So we know they are just tables, get protected from overflows, and get shared between processesmaster
const espeak_VOICE **voices; | const espeak_VOICE **voices; | ||||
espeak_VOICE voice_select; | espeak_VOICE voice_select; | ||||
static char genders[4] = { '-', 'M', 'F', '-' }; | |||||
static const char genders[4] = { '-', 'M', 'F', '-' }; | |||||
if ((language != NULL) && (language[0] != 0)) { | if ((language != NULL) && (language[0] != 0)) { | ||||
// display only voices for the specified language, in order of priority | // display only voices for the specified language, in order of priority | ||||
static int OpenWavFile(char *path, int rate) | static int OpenWavFile(char *path, int rate) | ||||
{ | { | ||||
static unsigned char wave_hdr[44] = { | |||||
static const unsigned char wave_hdr[44] = { | |||||
'R', 'I', 'F', 'F', 0x24, 0xf0, 0xff, 0x7f, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', | 'R', 'I', 'F', 'F', 0x24, 0xf0, 0xff, 0x7f, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', | ||||
0x10, 0, 0, 0, 1, 0, 1, 0, 9, 0x3d, 0, 0, 0x12, 0x7a, 0, 0, | 0x10, 0, 0, 0, 1, 0, 1, 0, 9, 0x3d, 0, 0, 0x12, 0x7a, 0, 0, | ||||
2, 0, 0x10, 0, 'd', 'a', 't', 'a', 0x00, 0xf0, 0xff, 0x7f | 2, 0, 0x10, 0, 'd', 'a', 't', 'a', 0x00, 0xf0, 0xff, 0x7f | ||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
static struct option long_options[] = { | |||||
static const struct option long_options[] = { | |||||
{ "help", no_argument, 0, 'h' }, | { "help", no_argument, 0, 'h' }, | ||||
{ "stdin", no_argument, 0, 0x100 }, | { "stdin", no_argument, 0, 0x100 }, | ||||
{ "compile-debug", optional_argument, 0, 0x101 }, | { "compile-debug", optional_argument, 0, 0x101 }, |
int addr = 0; | int addr = 0; | ||||
int value = 0; | int value = 0; | ||||
char path[N_ITEM_STRING]; | char path[N_ITEM_STRING]; | ||||
static int sound_instns[] = { i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD }; | |||||
static const int sound_instns[] = { i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD }; | |||||
NextItemBrackets(tSTRING, 2); | NextItemBrackets(tSTRING, 2); | ||||
strcpy(path, item_string); | strcpy(path, item_string); |
char suffix[20]; | char suffix[20]; | ||||
static char output[80]; | static char output[80]; | ||||
static char symbols[] = { | |||||
static const char symbols[] = { | |||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', | ||||
'&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!', | '&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!', | ||||
' ', '@', '?', 'J', 'N', 'K', 'V', '?', 'T', 'X', | ' ', '@', '?', 'J', 'N', 'K', 'V', '?', 'T', 'X', | ||||
'?', 'W' | '?', 'W' | ||||
}; | }; | ||||
static char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' }; | |||||
static const char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' }; | |||||
match_type = 0; | match_type = 0; | ||||
buf_pre[0] = 0; | buf_pre[0] = 0; | ||||
static void copy_rule_string(char *string, int *state_out) | static void copy_rule_string(char *string, int *state_out) | ||||
{ | { | ||||
// state 0: conditional, 1=pre, 2=match, 3=post, 4=phonemes | // state 0: conditional, 1=pre, 2=match, 3=post, 4=phonemes | ||||
static char *outbuf[5] = { rule_cond, rule_pre, rule_match, rule_post, rule_phonemes }; | |||||
static int next_state[5] = { 2, 2, 4, 4, 4 }; | |||||
static char *const outbuf[5] = { rule_cond, rule_pre, rule_match, rule_post, rule_phonemes }; | |||||
static const int next_state[5] = { 2, 2, 4, 4, 4 }; | |||||
char *output; | char *output; | ||||
char *p; | char *p; | ||||
int ix; | int ix; |
char vowel_length[N_WORD_PHONEMES/2]; | char vowel_length[N_WORD_PHONEMES/2]; | ||||
unsigned char phonetic[N_WORD_PHONEMES]; | unsigned char phonetic[N_WORD_PHONEMES]; | ||||
static char consonant_types[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; | |||||
static const char consonant_types[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; | |||||
stressflags = tr->langopts.stress_flags; | stressflags = tr->langopts.stress_flags; | ||||
// LANG=Russian | // LANG=Russian | ||||
if (stressed_syllable == 0) { | if (stressed_syllable == 0) { | ||||
// no explicit stress - guess the stress from the number of syllables | // no explicit stress - guess the stress from the number of syllables | ||||
static char guess_ru[16] = { 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11 }; | |||||
static char guess_ru_v[16] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10 }; // for final phoneme is a vowel | |||||
static char guess_ru_t[16] = { 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 10 }; // for final phoneme is an unvoiced stop | |||||
static const char guess_ru[16] = { 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11 }; | |||||
static const char guess_ru_v[16] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10 }; // for final phoneme is a vowel | |||||
static const char guess_ru_t[16] = { 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 10 }; // for final phoneme is an unvoiced stop | |||||
stressed_syllable = vowel_count - 3; | stressed_syllable = vowel_count - 3; | ||||
if (vowel_count < 16) { | if (vowel_count < 16) { |
int pitch_range; | int pitch_range; | ||||
int pitch_range_abs; | int pitch_range_abs; | ||||
int *drops; | int *drops; | ||||
signed char *overflow_tab; | |||||
const signed char *overflow_tab; | |||||
SYLLABLE *syl; | SYLLABLE *syl; | ||||
static signed char continue_tab[5] = { -26, 32, 20, 8, 0 }; | |||||
static const signed char continue_tab[5] = { -26, 32, 20, 8, 0 }; | |||||
drops = th->body_drops; | drops = th->body_drops; | ||||
pitch_range = (th->body_end - th->body_start) * 256; | pitch_range = (th->body_end - th->body_start) * 256; |
static void frame_init(klatt_frame_ptr frame) | static void frame_init(klatt_frame_ptr frame) | ||||
{ | { | ||||
double amp_par[7]; | double amp_par[7]; | ||||
static double amp_par_factor[7] = { 0.6, 0.4, 0.15, 0.06, 0.04, 0.022, 0.03 }; | |||||
static const double amp_par_factor[7] = { 0.6, 0.4, 0.15, 0.06, 0.04, 0.022, 0.03 }; | |||||
long Gain0_tmp; | long Gain0_tmp; | ||||
int ix; | int ix; | ||||
static double impulsive_source() | static double impulsive_source() | ||||
{ | { | ||||
static double doublet[] = { 0.0, 13000000.0, -13000000.0 }; | |||||
static const double doublet[] = { 0.0, 13000000.0, -13000000.0 }; | |||||
static double vwave; | static double vwave; | ||||
if (kt_globals.nper < 3) | if (kt_globals.nper < 3) | ||||
long temp; | long temp; | ||||
double temp1; | double temp1; | ||||
static long skew; | static long skew; | ||||
static short B0[224] = { | |||||
static const short B0[224] = { | |||||
1200, 1142, 1088, 1038, 991, 948, 907, 869, 833, 799, 768, 738, 710, 683, 658, | 1200, 1142, 1088, 1038, 991, 948, 907, 869, 833, 799, 768, 738, 710, 683, 658, | ||||
634, 612, 590, 570, 551, 533, 515, 499, 483, 468, 454, 440, 427, 415, 403, | 634, 612, 590, 570, 551, 533, 515, 499, 483, 468, 454, 440, 427, 415, 403, | ||||
391, 380, 370, 360, 350, 341, 332, 323, 315, 307, 300, 292, 285, 278, 272, | 391, 380, 370, 360, 350, 341, 332, 323, 315, 307, 300, 292, 285, 278, 272, | ||||
static double DBtoLIN(long dB) | static double DBtoLIN(long dB) | ||||
{ | { | ||||
static short amptable[88] = { | |||||
static const short amptable[88] = { | |||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, | ||||
8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 28, 32, | 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 28, 32, | ||||
35, 40, 45, 51, 57, 64, 71, 80, 90, 101, 114, 128, | 35, 40, 45, 51, 57, 64, 71, 80, 90, 101, 114, 128, | ||||
void KlattInit() | void KlattInit() | ||||
{ | { | ||||
static short formant_hz[10] = { 280, 688, 1064, 2806, 3260, 3700, 6500, 7000, 8000, 280 }; | |||||
static short bandwidth[10] = { 89, 160, 70, 160, 200, 200, 500, 500, 500, 89 }; | |||||
static short parallel_amp[10] = { 0, 59, 59, 59, 59, 59, 59, 0, 0, 0 }; | |||||
static short parallel_bw[10] = { 59, 59, 89, 149, 200, 200, 500, 0, 0, 0 }; | |||||
static const short formant_hz[10] = { 280, 688, 1064, 2806, 3260, 3700, 6500, 7000, 8000, 280 }; | |||||
static const short bandwidth[10] = { 89, 160, 70, 160, 200, 200, 500, 500, 500, 89 }; | |||||
static const short parallel_amp[10] = { 0, 59, 59, 59, 59, 59, 59, 0, 0, 0 }; | |||||
static const short parallel_bw[10] = { 59, 59, 89, 149, 200, 200, 500, 0, 0, 0 }; | |||||
int ix; | int ix; | ||||
char ph_buf2[80]; | char ph_buf2[80]; | ||||
char ph_alphabet[80]; | char ph_alphabet[80]; | ||||
char hexbuf[12]; | char hexbuf[12]; | ||||
static char pause_string[] = { phonPAUSE, 0 }; | |||||
static const char pause_string[] = { phonPAUSE, 0 }; | |||||
ph_buf[0] = 0; | ph_buf[0] = 0; | ||||
ph_alphabet[0] = 0; | ph_alphabet[0] = 0; | ||||
char number_chars[N_WORD_BYTES]; | char number_chars[N_WORD_BYTES]; | ||||
static const char *roman_numbers = "ixcmvld"; | static const char *roman_numbers = "ixcmvld"; | ||||
static int roman_values[] = { 1, 10, 100, 1000, 5, 50, 500 }; | |||||
static const int roman_values[] = { 1, 10, 100, 1000, 5, 50, 500 }; | |||||
acc = 0; | acc = 0; | ||||
prev = 0; | prev = 0; |
} | } | ||||
if ((plist3+1)->synthflags & SFLAG_LENGTHEN) { | if ((plist3+1)->synthflags & SFLAG_LENGTHEN) { | ||||
static char types_double[] = { phFRICATIVE, phVFRICATIVE, phNASAL, phLIQUID, 0 }; | |||||
static const char types_double[] = { phFRICATIVE, phVFRICATIVE, phNASAL, phLIQUID, 0 }; | |||||
if ((j > 0) && (strchr(types_double, next->type))) { | if ((j > 0) && (strchr(types_double, next->type))) { | ||||
// lengthen this consonant by doubling it | // lengthen this consonant by doubling it | ||||
// BUT, can't insert a phoneme at position plist3[0] because it crashes PrevPh() | // BUT, can't insert a phoneme at position plist3[0] because it crashes PrevPh() |
} | } | ||||
static wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name) | |||||
static const wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name) | |||||
{ | { | ||||
// Gets the value string for an attribute. | // Gets the value string for an attribute. | ||||
// Returns NULL if the attribute is not present | // Returns NULL if the attribute is not present | ||||
int ix; | int ix; | ||||
static wchar_t empty[1] = { 0 }; | |||||
static const wchar_t empty[1] = { 0 }; | |||||
while (*pw != 0) { | while (*pw != 0) { | ||||
if (iswspace(pw[-1])) { | if (iswspace(pw[-1])) { | ||||
// a voice change. | // a voice change. | ||||
// Returns CLAUSE_TYPE_VOICE_CHANGE if there is a voice change | // Returns CLAUSE_TYPE_VOICE_CHANGE if there is a voice change | ||||
wchar_t *lang; | |||||
wchar_t *gender; | |||||
wchar_t *name; | |||||
wchar_t *age; | |||||
wchar_t *variant; | |||||
const wchar_t *lang; | |||||
const wchar_t *gender; | |||||
const wchar_t *name; | |||||
const wchar_t *age; | |||||
const wchar_t *variant; | |||||
int value; | int value; | ||||
const char *new_voice_id; | const char *new_voice_id; | ||||
int value; | int value; | ||||
char buf[20]; | char buf[20]; | ||||
int new_parameters[N_SPEECH_PARAM]; | int new_parameters[N_SPEECH_PARAM]; | ||||
static char cmd_letter[N_SPEECH_PARAM] = { 0, 'S', 'A', 'P', 'R', 0, 'C', 0, 0, 0, 0, 0, 'F' }; // embedded command letters | |||||
static const char cmd_letter[N_SPEECH_PARAM] = { 0, 'S', 'A', 'P', 'R', 0, 'C', 0, 0, 0, 0, 0, 'F' }; // embedded command letters | |||||
for (param = 0; param < N_SPEECH_PARAM; param++) | for (param = 0; param < N_SPEECH_PARAM; param++) | ||||
new_parameters[param] = -1; | new_parameters[param] = -1; | ||||
return 0; | return 0; | ||||
} | } | ||||
static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp, PARAM_STACK *param_stack, int *speech_parameters) | |||||
static void SetProsodyParameter(int param_type, const wchar_t *attr1, PARAM_STACK *sp, PARAM_STACK *param_stack, int *speech_parameters) | |||||
{ | { | ||||
int value; | int value; | ||||
int sign; | int sign; | ||||
int value3; | int value3; | ||||
int voice_change_flag; | int voice_change_flag; | ||||
wchar_t *px; | wchar_t *px; | ||||
wchar_t *attr1; | |||||
wchar_t *attr2; | |||||
wchar_t *attr3; | |||||
const wchar_t *attr1; | |||||
const wchar_t *attr2; | |||||
const wchar_t *attr3; | |||||
int terminator; | int terminator; | ||||
char *uri; | char *uri; | ||||
int param_type; | int param_type; | ||||
} | } | ||||
// these tags have no effect if they are self-closing, eg. <voice /> | // these tags have no effect if they are self-closing, eg. <voice /> | ||||
static char ignore_if_self_closing[] = { 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 }; | |||||
static const char ignore_if_self_closing[] = { 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 }; | |||||
bool self_closing = false; | bool self_closing = false; | ||||
int len; | int len; | ||||
value = attrlookup(attr1, mnem_emphasis); | value = attrlookup(attr1, mnem_emphasis); | ||||
if (translator->langopts.tone_language == 1) { | if (translator->langopts.tone_language == 1) { | ||||
static unsigned char emphasis_to_pitch_range[] = { 50, 50, 40, 70, 90, 100 }; | |||||
static unsigned char emphasis_to_volume[] = { 100, 100, 70, 110, 135, 150 }; | |||||
static const unsigned char emphasis_to_pitch_range[] = { 50, 50, 40, 70, 90, 100 }; | |||||
static const unsigned char emphasis_to_volume[] = { 100, 100, 70, 110, 135, 150 }; | |||||
// tone language (eg.Chinese) do emphasis by increasing the pitch range. | // tone language (eg.Chinese) do emphasis by increasing the pitch range. | ||||
sp->parameter[espeakRANGE] = emphasis_to_pitch_range[value]; | sp->parameter[espeakRANGE] = emphasis_to_pitch_range[value]; | ||||
sp->parameter[espeakVOLUME] = emphasis_to_volume[value]; | sp->parameter[espeakVOLUME] = emphasis_to_volume[value]; | ||||
} else { | } else { | ||||
static unsigned char emphasis_to_volume2[] = { 100, 100, 75, 100, 120, 150 }; | |||||
static const unsigned char emphasis_to_volume2[] = { 100, 100, 75, 100, 120, 150 }; | |||||
sp->parameter[espeakVOLUME] = emphasis_to_volume2[value]; | sp->parameter[espeakVOLUME] = emphasis_to_volume2[value]; | ||||
sp->parameter[espeakEMPHASIS] = value; | sp->parameter[espeakEMPHASIS] = value; | ||||
} | } | ||||
terminator = CLAUSE_NONE; | terminator = CLAUSE_NONE; | ||||
if ((attr1 = GetSsmlAttribute(px, "strength")) != NULL) { | if ((attr1 = GetSsmlAttribute(px, "strength")) != NULL) { | ||||
static int break_value[6] = { 0, 7, 14, 21, 40, 80 }; // *10mS | |||||
static const int break_value[6] = { 0, 7, 14, 21, 40, 80 }; // *10mS | |||||
value = attrlookup(attr1, mnem_break); | value = attrlookup(attr1, mnem_break); | ||||
if (value < 3) { | if (value < 3) { | ||||
// adjust prepause on the following word | // adjust prepause on the following word |
{ | { | ||||
int stress_level; | int stress_level; | ||||
PHONEME_LIST *pl; | PHONEME_LIST *pl; | ||||
static int condition_level[4] = { 1, 2, 4, 15 }; | |||||
static const int condition_level[4] = { 1, 2, 4, 15 }; | |||||
if (phoneme_tab[plist[0].phcode]->type == phVOWEL) | if (phoneme_tab[plist[0].phcode]->type == phVOWEL) | ||||
pl = plist; | pl = plist; |
#define N_VCOLOUR 2 | #define N_VCOLOUR 2 | ||||
// percentage change for each formant in 256ths | // percentage change for each formant in 256ths | ||||
static short vcolouring[N_VCOLOUR][5] = { | |||||
static const short vcolouring[N_VCOLOUR][5] = { | |||||
{ 243, 272, 256, 256, 256 }, // palatal consonant follows | { 243, 272, 256, 256, 256 }, // palatal consonant follows | ||||
{ 256, 256, 240, 240, 240 }, // retroflex | { 256, 256, 240, 240, 240 }, // retroflex | ||||
}; | }; |
break; | break; | ||||
case L('m', 'k'): // Macedonian | case L('m', 'k'): // Macedonian | ||||
{ | { | ||||
static wchar_t vowels_cyrillic[] = { | |||||
static const wchar_t vowels_cyrillic[] = { | |||||
// also include 'р' [R] | // also include 'р' [R] | ||||
0x440, 0x430, 0x435, 0x438, 0x439, 0x43e, 0x443, 0x44b, 0x44d, | 0x440, 0x430, 0x435, 0x438, 0x439, 0x43e, 0x443, 0x44b, 0x44d, | ||||
0x44e, 0x44f, 0x450, 0x451, 0x456, 0x457, 0x45d, 0x45e, 0 | 0x44e, 0x44f, 0x450, 0x451, 0x456, 0x457, 0x45d, 0x45e, 0 | ||||
{ | { | ||||
static const short stress_lengths_vi[8] = { 150, 150, 180, 180, 210, 230, 230, 240 }; | static const short stress_lengths_vi[8] = { 150, 150, 180, 180, 210, 230, 230, 240 }; | ||||
static const unsigned char stress_amps_vi[] = { 16, 16, 16, 16, 22, 22, 22, 22 }; | static const unsigned char stress_amps_vi[] = { 16, 16, 16, 16, 22, 22, 22, 22 }; | ||||
static wchar_t vowels_vi[] = { | |||||
static const wchar_t vowels_vi[] = { | |||||
0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a | 0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a | ||||
0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă | 0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă | ||||
0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â | 0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â |
// Set voice to the default values | // Set voice to the default values | ||||
int pk; | int pk; | ||||
static unsigned char default_heights[N_PEAKS] = { 130, 128, 120, 116, 100, 100, 128, 128, 128 }; // changed for v.1.47 | |||||
static unsigned char default_widths[N_PEAKS] = { 140, 128, 128, 160, 171, 171, 128, 128, 128 }; | |||||
static const unsigned char default_heights[N_PEAKS] = { 130, 128, 120, 116, 100, 100, 128, 128, 128 }; // changed for v.1.47 | |||||
static const unsigned char default_widths[N_PEAKS] = { 140, 128, 128, 160, 171, 171, 128, 128, 128 }; | |||||
static int breath_widths[N_PEAKS] = { 0, 200, 200, 400, 400, 400, 600, 600, 600 }; | |||||
static const int breath_widths[N_PEAKS] = { 0, 200, 200, 400, 400, 400, 600, 600, 600 }; | |||||
// default is: pitch 80,118 | // default is: pitch 80,118 | ||||
voice->pitch_base = 0x47000; | voice->pitch_base = 0x47000; |
int length4; | int length4; | ||||
int qix; | int qix; | ||||
int cmd; | int cmd; | ||||
static int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256 | |||||
static int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256 | |||||
static const int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256 | |||||
static const int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256 | |||||
end_wave = 1; | end_wave = 1; | ||||