} | } | ||||
c = ' '; | c = ' '; | ||||
} else if (rb == RULE_ENDING) { | } else if (rb == RULE_ENDING) { | ||||
static const char *flag_chars = "eipvdfq tba "; | |||||
static const char flag_chars[] = "eipvdfq tba "; | |||||
flags = ((rule[0] & 0x7f)<< 8) + (rule[1] & 0x7f); | flags = ((rule[0] & 0x7f)<< 8) + (rule[1] & 0x7f); | ||||
suffix_char = 'S'; | suffix_char = 'S'; | ||||
if (flags & (SUFX_P >> 8)) | if (flags & (SUFX_P >> 8)) |
#include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme... | #include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme... | ||||
#include "translate.h" // for Translator, utf8_in, LANGU... | #include "translate.h" // for Translator, utf8_in, LANGU... | ||||
static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out); | |||||
static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, unsigned int *flags, int command, int *failed, int *add_points); | |||||
static int LookupFlags(Translator *tr, const char *word, unsigned int flags_out[2]); | |||||
static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, int command, int *failed, int *add_points); | |||||
typedef struct { | typedef struct { | ||||
int points; | int points; | ||||
// convert characters to an approximate 7 bit ascii equivalent | // convert characters to an approximate 7 bit ascii equivalent | ||||
// used for checking for vowels (up to 0x259=schwa) | // used for checking for vowels (up to 0x259=schwa) | ||||
#define N_REMOVE_ACCENT 0x25e | #define N_REMOVE_ACCENT 0x25e | ||||
static unsigned char remove_accent[N_REMOVE_ACCENT] = { | |||||
static const unsigned char remove_accent[N_REMOVE_ACCENT] = { | |||||
'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0c0 | 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0c0 | ||||
'd', 'n', 'o', 'o', 'o', 'o', 'o', 0, 'o', 'u', 'u', 'u', 'u', 'y', 't', 's', // 0d0 | 'd', 'n', 'o', 'o', 'o', 'o', 'o', 0, 'o', 'u', 'u', 'u', 'u', 'y', 't', 's', // 0d0 | ||||
'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0e0 | 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0e0 | ||||
unsigned char c; | unsigned char c; | ||||
unsigned int mnem; | unsigned int mnem; | ||||
PHONEME_TAB *ph; | PHONEME_TAB *ph; | ||||
static const char *stress_chars = "==,,'* "; | |||||
static const char stress_chars[] = "==,,'* "; | |||||
sprintf(outptr, "* "); | sprintf(outptr, "* "); | ||||
while ((phcode = *inptr++) > 0) { | while ((phcode = *inptr++) > 0) { | ||||
char phon_buf2[30]; | char phon_buf2[30]; | ||||
PHONEME_LIST *plist; | PHONEME_LIST *plist; | ||||
static const char *stress_chars = "==,,''"; | |||||
static const char stress_chars[] = "==,,''"; | |||||
if (phon_out_buf == NULL) { | if (phon_out_buf == NULL) { | ||||
phon_out_size = N_PHON_OUT; | phon_out_size = N_PHON_OUT; | ||||
int n_bytes; | int n_bytes; | ||||
int add_points; | int add_points; | ||||
int command; | int command; | ||||
unsigned int *flags = NULL; | |||||
MatchRecord match; | MatchRecord match; | ||||
static MatchRecord best; | |||||
MatchRecord best; | |||||
int total_consumed; // letters consumed for best match | int total_consumed; // letters consumed for best match | ||||
else | else | ||||
failed = 1; | failed = 1; | ||||
} else if (((command & 0xf0) == 0x20) || (command == DOLLAR_LIST)) { | } else if (((command & 0xf0) == 0x20) || (command == DOLLAR_LIST)) { | ||||
DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); | |||||
DollarRule(word, word_start, consumed, group_length, word_buf, tr, command, &failed, &add_points); | |||||
} | } | ||||
break; | break; | ||||
pre_ptr++; | pre_ptr++; | ||||
command = *rule++; | command = *rule++; | ||||
if ((command == DOLLAR_LIST) || ((command & 0xf0) == 0x20)) { | if ((command == DOLLAR_LIST) || ((command & 0xf0) == 0x20)) { | ||||
DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); | |||||
DollarRule(word, word_start, consumed, group_length, word_buf, tr, command, &failed, &add_points); | |||||
} | } | ||||
break; | break; | ||||
case RULE_SYLLABLE: | case RULE_SYLLABLE: | ||||
return flags0; | return flags0; | ||||
} | } | ||||
static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out) | |||||
static int LookupFlags(Translator *tr, const char *word, unsigned int flags_out[2]) | |||||
{ | { | ||||
char buf[100]; | char buf[100]; | ||||
static unsigned int flags[2]; | static unsigned int flags[2]; | ||||
flags[0] = flags[1] = 0; | flags[0] = flags[1] = 0; | ||||
LookupDictList(tr, &word1, buf, flags, 0, NULL); | LookupDictList(tr, &word1, buf, flags, 0, NULL); | ||||
*flags_out = flags; | |||||
flags_out[0] = flags[0]; | |||||
flags_out[1] = flags[1]; | |||||
return flags[0]; | return flags[0]; | ||||
} | } | ||||
return end_flags; | return end_flags; | ||||
} | } | ||||
static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, unsigned int *flags, int command, int *failed, int *add_points) { | |||||
static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, int command, int *failed, int *add_points) { | |||||
// $list or $p_alt | // $list or $p_alt | ||||
// make a copy of the word up to the post-match characters | // make a copy of the word up to the post-match characters | ||||
int ix = *word - word_start + consumed + group_length + 1; | int ix = *word - word_start + consumed + group_length + 1; | ||||
memcpy(word_buf, word_start-1, ix); | memcpy(word_buf, word_start-1, ix); | ||||
word_buf[ix] = ' '; | word_buf[ix] = ' '; | ||||
word_buf[ix+1] = 0; | word_buf[ix+1] = 0; | ||||
LookupFlags(tr, &word_buf[1], &flags); | |||||
unsigned int flags[2]; | |||||
LookupFlags(tr, &word_buf[1], flags); | |||||
if ((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) | if ((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) | ||||
*add_points = 23; | *add_points = 23; |
#define NUMBER_OF_SAMPLES 100 | #define NUMBER_OF_SAMPLES 100 | ||||
static int scale_wav_tab[] = { 45, 38, 45, 45, 55, 45 }; // scale output from different voicing sources | |||||
static const int scale_wav_tab[] = { 45, 38, 45, 45, 55, 45 }; // scale output from different voicing sources | |||||
// For testing, this can be overwritten in KlattInit() | // For testing, this can be overwritten in KlattInit() | ||||
static const short natural_samples2[256] = { | static const short natural_samples2[256] = { |
static int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key); | static int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key); | ||||
static int LookupTune(const char *name); | static int LookupTune(const char *name); | ||||
extern const MNEM_TAB langopts_tab[]; | |||||
void LoadLanguageOptions(Translator *translator, int key, char *keyValue ) { | void LoadLanguageOptions(Translator *translator, int key, char *keyValue ) { | ||||
if (CheckTranslator(translator, langopts_tab, key) != 0) { | if (CheckTranslator(translator, langopts_tab, key) != 0) { | ||||
return; | return; |
// this list must be in ascending order | // this list must be in ascending order | ||||
static unsigned short derived_letters[] = { | |||||
static const unsigned short derived_letters[] = { | |||||
0x00aa, 'a'+L_SUP, | 0x00aa, 'a'+L_SUP, | ||||
0x00b2, '2'+L_SUP, | 0x00b2, '2'+L_SUP, | ||||
0x00b3, '3'+L_SUP, | 0x00b3, '3'+L_SUP, | ||||
char ph_roman[30]; | char ph_roman[30]; | ||||
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 const 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; |
// convert from words-per-minute to internal speed factor | // convert from words-per-minute to internal speed factor | ||||
// Use this to calibrate speed for wpm 80-450 (espeakRATE_MINIMUM - espeakRATE_MAXIMUM) | // Use this to calibrate speed for wpm 80-450 (espeakRATE_MINIMUM - espeakRATE_MAXIMUM) | ||||
static unsigned char speed_lookup[] = { | |||||
static const unsigned char speed_lookup[] = { | |||||
255, 255, 255, 255, 255, // 80 | 255, 255, 255, 255, 255, // 80 | ||||
253, 249, 245, 242, 238, // 85 | 253, 249, 245, 242, 238, // 85 | ||||
235, 232, 228, 225, 222, // 90 | 235, 232, 228, 225, 222, // 90 | ||||
}; | }; | ||||
// speed_factor1 adjustments for speeds 350 to 374: pauses | // speed_factor1 adjustments for speeds 350 to 374: pauses | ||||
static unsigned char pause_factor_350[] = { | |||||
static const unsigned char pause_factor_350[] = { | |||||
22, 22, 22, 22, 22, 22, 22, 21, 21, 21, // 350 | 22, 22, 22, 22, 22, 22, 22, 21, 21, 21, // 350 | ||||
21, 20, 20, 19, 19, 18, 17, 16, 15, 15, // 360 | 21, 20, 20, 19, 19, 18, 17, 16, 15, 15, // 360 | ||||
15, 15, 15, 15, 15 // 370 | 15, 15, 15, 15, 15 // 370 | ||||
// wav_factor adjustments for speeds 350 to 450 | // wav_factor adjustments for speeds 350 to 450 | ||||
// Use this to calibrate speed for wpm 350-450 | // Use this to calibrate speed for wpm 350-450 | ||||
static unsigned char wav_factor_350[] = { | |||||
static const unsigned char wav_factor_350[] = { | |||||
120, 121, 120, 119, 119, // 350 | 120, 121, 120, 119, 119, // 350 | ||||
118, 118, 117, 116, 116, // 355 | 118, 118, 117, 116, 116, // 355 | ||||
115, 114, 113, 112, 112, // 360 | 115, 114, 113, 112, 112, // 360 |
static int frame_width; | static int frame_width; | ||||
static int default_freq[N_PEAKS] = | |||||
static const int default_freq[N_PEAKS] = | |||||
{ 200, 500, 1200, 3000, 3500, 4000, 6900, 7800, 9000 }; | { 200, 500, 1200, 3000, 3500, 4000, 6900, 7800, 9000 }; | ||||
static int default_width[N_PEAKS] = | |||||
static const int default_width[N_PEAKS] = | |||||
{ 750, 500, 550, 550, 600, 700, 700, 700, 700 }; | { 750, 500, 550, 550, 600, 700, 700, 700, 700 }; | ||||
static int default_klt_bw[N_PEAKS] = | |||||
static const int default_klt_bw[N_PEAKS] = | |||||
{ 89, 90, 140, 260, 260, 260, 500, 500, 500 }; | { 89, 90, 140, 260, 260, 260, 500, 500, 500 }; | ||||
static double read_double(FILE *stream) | static double read_double(FILE *stream) |
static espeak_ng_OUTPUT_MODE my_mode = ENOUTPUT_MODE_SYNCHRONOUS; | static espeak_ng_OUTPUT_MODE my_mode = ENOUTPUT_MODE_SYNCHRONOUS; | ||||
static int out_samplerate = 0; | static int out_samplerate = 0; | ||||
static int voice_samplerate = 22050; | static int voice_samplerate = 22050; | ||||
static int min_buffer_length = 60; // minimum buffer length in ms | |||||
static const int min_buffer_length = 60; // minimum buffer length in ms | |||||
static espeak_ng_STATUS err = ENS_OK; | static espeak_ng_STATUS err = ENS_OK; | ||||
static t_espeak_callback *synth_callback = NULL; | static t_espeak_callback *synth_callback = NULL; | ||||
{ | { | ||||
(void)size; // unused in non-async modes | (void)size; // unused in non-async modes | ||||
static unsigned int temp_identifier; | |||||
unsigned int temp_identifier; | |||||
if (unique_identifier == NULL) | if (unique_identifier == NULL) | ||||
unique_identifier = &temp_identifier; | unique_identifier = &temp_identifier; | ||||
{ | { | ||||
(void)size; // unused in non-async modes | (void)size; // unused in non-async modes | ||||
static unsigned int temp_identifier; | |||||
unsigned int temp_identifier; | |||||
if (unique_identifier == NULL) | if (unique_identifier == NULL) | ||||
unique_identifier = &temp_identifier; | unique_identifier = &temp_identifier; |
case L('s', 'k'): // Slovak | case L('s', 'k'): // Slovak | ||||
case L('c', 's'): // Czech | case L('c', 's'): // Czech | ||||
{ | { | ||||
static const char *sk_voiced = "bdgjlmnrvwzaeiouy"; | |||||
static const char sk_voiced[] = "bdgjlmnrvwzaeiouy"; | |||||
SetupTranslator(tr, stress_lengths_sk, stress_amps_sk); | SetupTranslator(tr, stress_lengths_sk, stress_amps_sk); | ||||
tr->encoding = ESPEAKNG_ENCODING_ISO_8859_2; | tr->encoding = ESPEAKNG_ENCODING_ISO_8859_2; |
int tone_points[12] = { 600, 170, 1200, 135, 2000, 110, 3000, 110, -1, 0 }; | int tone_points[12] = { 600, 170, 1200, 135, 2000, 110, 3000, 110, -1, 0 }; | ||||
// limit the rate of change for each formant number | // limit the rate of change for each formant number | ||||
static int formant_rate_22050[9] = { 240, 170, 170, 170, 170, 170, 170, 170, 170 }; // values for 22kHz sample rate | |||||
static const int formant_rate_22050[9] = { 240, 170, 170, 170, 170, 170, 170, 170, 170 }; // values for 22kHz sample rate | |||||
int formant_rate[9]; // values adjusted for actual sample rate | int formant_rate[9]; // values adjusted for actual sample rate | ||||
#define DEFAULT_LANGUAGE_PRIORITY 5 | #define DEFAULT_LANGUAGE_PRIORITY 5 |
// pitch,speed, | // pitch,speed, | ||||
const int embedded_default[N_EMBEDDED_VALUES] = { 0, 50, espeakRATE_NORMAL, 100, 50, 0, 0, 0, espeakRATE_NORMAL, 0, 0, 0, 0, 0, 0 }; | const int embedded_default[N_EMBEDDED_VALUES] = { 0, 50, espeakRATE_NORMAL, 100, 50, 0, 0, 0, espeakRATE_NORMAL, 0, 0, 0, 0, 0, 0 }; | ||||
static int embedded_max[N_EMBEDDED_VALUES] = { 0, 0x7fff, 750, 300, 99, 99, 99, 0, 750, 0, 0, 0, 0, 4, 0 }; | |||||
static const int embedded_max[N_EMBEDDED_VALUES] = { 0, 0x7fff, 750, 300, 99, 99, 99, 0, 750, 0, 0, 0, 0, 4, 0 }; | |||||
#if USE_LIBSONIC | #if USE_LIBSONIC | ||||
static sonicStream sonicSpeedupStream = NULL; | static sonicStream sonicSpeedupStream = NULL; | ||||
// 2nd index=modulation_type | // 2nd index=modulation_type | ||||
// value: bits 0-3 amplitude (16ths), bits 4-7 every n cycles | // value: bits 0-3 amplitude (16ths), bits 4-7 every n cycles | ||||
#define N_ROUGHNESS 8 | #define N_ROUGHNESS 8 | ||||
static unsigned char modulation_tab[N_ROUGHNESS][8] = { | |||||
static const unsigned char modulation_tab[N_ROUGHNESS][8] = { | |||||
{ 0, 0x00, 0x00, 0x00, 0, 0x46, 0xf2, 0x29 }, | { 0, 0x00, 0x00, 0x00, 0, 0x46, 0xf2, 0x29 }, | ||||
{ 0, 0x2f, 0x00, 0x2f, 0, 0x45, 0xf2, 0x29 }, | { 0, 0x2f, 0x00, 0x2f, 0, 0x45, 0xf2, 0x29 }, | ||||
{ 0, 0x2f, 0x00, 0x2e, 0, 0x45, 0xf2, 0x28 }, | { 0, 0x2f, 0x00, 0x2e, 0, 0x45, 0xf2, 0x28 }, |