Browse Source

move attr_prosody_value()

master
Juho Hiltunen 7 years ago
parent
commit
16a5b5d15c
3 changed files with 50 additions and 49 deletions
  1. 0
    49
      src/libespeak-ng/readclause.c
  2. 49
    0
      src/libespeak-ng/ssml.c
  3. 1
    0
      src/libespeak-ng/ssml.h

+ 0
- 49
src/libespeak-ng/readclause.c View File

return NULL; return NULL;
} }


static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out)
{
int sign = 0;
wchar_t *tail;
double value;

while (iswspace(*pw)) pw++;
if (*pw == '+') {
pw++;
sign = 1;
}
if (*pw == '-') {
pw++;
sign = -1;
}
value = (double)wcstod(pw, &tail);
if (tail == pw) {
// failed to find a number, return 100%
*value_out = 100;
return 2;
}

if (*tail == '%') {
if (sign != 0)
value = 100 + (sign * value);
*value_out = (int)value;
return 2; // percentage
}

if ((tail[0] == 's') && (tail[1] == 't')) {
double x;
// convert from semitones to a frequency percentage
x = pow((double)2.0, (double)((value*sign)/12)) * 100;
*value_out = (int)x;
return 2; // percentage
}

if (param_type == espeakRATE) {
if (sign == 0)
*value_out = (int)(value * 100);
else
*value_out = 100 + (int)(sign * value * 100);
return 2; // percentage
}

*value_out = (int)value;
return sign; // -1, 0, or 1
}

static int AddNameData(const char *name, int wide) static int AddNameData(const char *name, int wide)
{ {
// Add the name to the namedata and return its position // Add the name to the namedata and return its position

+ 49
- 0
src/libespeak-ng/ssml.c View File

return ix; return ix;
} }


int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out)
{
int sign = 0;
wchar_t *tail;
double value;

while (iswspace(*pw)) pw++;
if (*pw == '+') {
pw++;
sign = 1;
}
if (*pw == '-') {
pw++;
sign = -1;
}
value = (double)wcstod(pw, &tail);
if (tail == pw) {
// failed to find a number, return 100%
*value_out = 100;
return 2;
}

if (*tail == '%') {
if (sign != 0)
value = 100 + (sign * value);
*value_out = (int)value;
return 2; // percentage
}

if ((tail[0] == 's') && (tail[1] == 't')) {
double x;
// convert from semitones to a frequency percentage
x = pow((double)2.0, (double)((value*sign)/12)) * 100;
*value_out = (int)x;
return 2; // percentage
}

if (param_type == espeakRATE) {
if (sign == 0)
*value_out = (int)(value * 100);
else
*value_out = 100 + (int)(sign * value * 100);
return 2; // percentage
}

*value_out = (int)value;
return sign; // -1, 0, or 1
}

int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[]) int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[])
{ {
// Determines whether voice attribute are specified in this tag, and if so, whether this means // Determines whether voice attribute are specified in this tag, and if so, whether this means

+ 1
- 0
src/libespeak-ng/ssml.h View File

int attrcmp(const wchar_t *string1, const char *string2); int attrcmp(const wchar_t *string1, const char *string2);
int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab); int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab);
int attrnumber(const wchar_t *pw, int default_value, int type); int attrnumber(const wchar_t *pw, int default_value, int type);
int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out);
int attrcopy_utf8(char *buf, const wchar_t *pw, int len); int attrcopy_utf8(char *buf, const wchar_t *pw, int len);
int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[]); int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[]);



Loading…
Cancel
Save