[1.43.63]

Phoneme definitions.  Add "equivalents" table to translate phonemes from a foreign language (eg. English) into the equivalant phonemes of this language. This is used when *_rules and *_list files indicate that a word uses pronunciation rules from a different language.

Unpronouncable words can be recognised by rules in *_rule files.  This feature is now used for en, de, es.

Lang=ta, hi.  Letter-names for combining vowel characters are distinguished from stand-alone vowel characters by a preceding beep.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@251 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2010-08-02 09:09:25 +00:00
parent ebf0535e6d
commit 4423576af2
58 changed files with 1641 additions and 728 deletions
+171 -27
View File
@@ -149,6 +149,7 @@ enum {
kPROCEDURE,
kENDPHONEME,
kENDPROCEDURE,
kEQUIVALENTS,
kPHONEMENUMBER,
kPHONEMETABLE,
kINCLUDE,
@@ -243,6 +244,7 @@ static keywtab_t keywords[] = {
{"procedure", tSTATEMENT, kPROCEDURE},
{"endphoneme", tSTATEMENT, kENDPHONEME},
{"endprocedure", tSTATEMENT, kENDPROCEDURE},
{"equivalents", tSTATEMENT, kEQUIVALENTS},
{"import_phoneme", tSTATEMENT, kIMPORT_PH},
{"stress_type",tSTATEMENT, kSTRESSTYPE},
{"starttype", tSTATEMENT, kSTARTTYPE},
@@ -363,6 +365,10 @@ static PHONEME_TAB *phoneme_tab2;
static int phoneme_flags;
static int place_articulation;
static char *p_equivalence;
static char equivalence_buf[20000];
#define N_PROCS 50
int n_procs;
int proc_addr[N_PROCS];
@@ -2479,6 +2485,23 @@ static int CompileSwitch(int type)
static PHONEME_TAB_LIST *FindPhonemeTable(const char *string)
{//==========================================================
int ix;
for(ix=0; ix<n_phoneme_tabs; ix++)
{
if(strcmp(phoneme_tab_list2[ix].name, string) == 0)
{
return(&phoneme_tab_list2[ix]);
}
}
error("Unknown phoneme table: '%s'",string);
return(NULL);
} // end of FindPhonemeTable
static PHONEME_TAB *FindPhoneme(const char *string)
{//================================================
PHONEME_TAB_LIST *phtab = NULL;
@@ -2487,7 +2510,7 @@ static PHONEME_TAB *FindPhoneme(const char *string)
char *phname;
char buf[200];
// is this the name of a phoneme which is ijn scope
// is this the name of a phoneme which is in scope
if((strlen(string) <= 4) && ((ix = LookupPhoneme(string,0)) != -1))
{
return(&phoneme_tab2[ix]);
@@ -2500,17 +2523,9 @@ static PHONEME_TAB *FindPhoneme(const char *string)
*phname++ = 0;
}
for(ix=0; ix<n_phoneme_tabs; ix++)
{
if(strcmp(phoneme_tab_list2[ix].name,buf) == 0)
{
phtab = &phoneme_tab_list2[ix];
break;
}
}
phtab = FindPhonemeTable(buf);
if(phtab == NULL)
{
error("Unknown phoneme table: '%s'",buf);
return(NULL); // phoneme table not found
}
@@ -3025,6 +3040,7 @@ static void WritePhonemeTables()
fputc(phoneme_tab_list2[ix].includes,f_phtab);
fputc(0,f_phtab);
fputc(0,f_phtab);
Write4Bytes(f_phtab, phoneme_tab_list2[ix].equivalence_tables); // byte index into phondata for equivalence tables
fwrite(phoneme_tab_list2[ix].name,1,N_PHONEME_TAB_NAME,f_phtab);
@@ -3047,6 +3063,8 @@ static void WritePhonemeTables()
static void EndPhonemeTable()
{//==========================
int ix;
int *pw;
int length;
if(n_phoneme_tabs == 0)
return;
@@ -3061,10 +3079,24 @@ static void EndPhonemeTable()
fprintf(f_errors,"%3d: Phoneme [%s] not declared, referenced at line %d\n",linenum,
WordToString(phoneme_tab2[ix].mnemonic),int(phoneme_tab2[ix].program));
error_count++;
phoneme_tab2[ix].type = 0; // prevent the error message repeating
}
}
n_phcodes_list[n_phoneme_tabs-1] = n_phcodes;
if((length = p_equivalence - equivalence_buf) > 0)
{
// terminate the list of phoneme equivalence tables
pw = (int *)p_equivalence;
pw[0] = 0;
// write the equivalence data into phondata, and remember it's address
ix = ftell(f_phdata);
fprintf(f_phcontents,"Q 0x%.5x %s\n", ix, phoneme_tab_list2[n_phoneme_tabs-1].name);
phoneme_tab_list2[n_phoneme_tabs-1].equivalence_tables = ix;
fwrite(equivalence_buf, length+4, 1, f_phdata);
}
}
@@ -3092,11 +3124,12 @@ static void StartPhonemeTable(const char *name)
if(gui_flag)
progress->Update(n_phoneme_tabs);
memset(&phoneme_tab_list2[n_phoneme_tabs], 0, sizeof(PHONEME_TAB_LIST));
phoneme_tab_list2[n_phoneme_tabs].phoneme_tab_ptr = phoneme_tab2 = p;
memset(phoneme_tab_list2[n_phoneme_tabs].name, 0, N_PHONEME_TAB_NAME);
strncpy0(phoneme_tab_list2[n_phoneme_tabs].name, name, N_PHONEME_TAB_NAME);
n_phcodes = 1;
phoneme_tab_list2[n_phoneme_tabs].includes = 0;
p_equivalence = equivalence_buf;
if(n_phoneme_tabs > 0)
{
@@ -3131,6 +3164,111 @@ static void StartPhonemeTable(const char *name)
} // end of StartPhonemeTable
static void CompileEquivalents()
{//=============================
// a list of phonemes in another language and the equivalent phoneme strings in this language
int ix;
int n_names;
int n_bytes;
int foreign_phoneme;
int foreign_error = 0;
int remove_stress = 0;
char *p_start;
char *p;
int foreign_table;
char foreign_table_name[40];
char line_buf[80];
char names[6][80];
char phcode[7];
char save_voice_name[80];
NextItem(tSTRING);
strcpy(foreign_table_name, item_string);
strcpy(save_voice_name,voice_name2);
if((foreign_table = SelectPhonemeTableName(foreign_table_name)) < 0)
{
error("Unknown phoneme table '%s'", foreign_table_name);
foreign_error = 1;
foreign_phoneme = 0;
}
p_start = p_equivalence;
p_equivalence += 8;
p_start[0] = foreign_table;
linenum--;
while(!feof(f_in))
{
linenum++;
if(fgets(line_buf, sizeof(line_buf), f_in) == NULL)
break;
if((p = strstr(line_buf,"//")) != NULL)
*p = 0;
for(ix=0; ix<6; ix++)
names[ix][0] = 0;
n_names = sscanf(line_buf,"%s %s %s %s %s %s",names[0],names[1],names[2],names[3],names[4],names[5]);
if(n_names < 1)
continue;
if(strcmp(names[0],"endphoneme") == 0)
break;
if(strcmp(names[0],"remove_stress") == 0)
{
remove_stress = 1;
continue;
}
if(p_equivalence > &equivalence_buf[sizeof(equivalence_buf) - 16])
{
error("'equivalents' tables are too large",NULL);
break;
}
if(foreign_error == 0)
{
phcode[0] = foreign_phoneme = LookupPhonemeString(names[0]);
if(foreign_phoneme == 0)
{
sprintf(line_buf,"%s/%s", foreign_table_name, names[0]);
error("Unknown phoneme '%s'", line_buf);
}
}
for(ix=1; ix<n_names; ix++)
{
phcode[ix] = LookupPhoneme(names[ix], 1);
}
// only write a translation if it has an effect
if((n_names > 2) || (phcode[0] != phcode[1]))
{
// write: foreign phoneme number, then a string of local phoneme numbers
memcpy(p_equivalence, phcode, n_names);
p_equivalence += n_names;
*p_equivalence++ = 0;
}
}
*p_equivalence++ = 0;
p_equivalence = (char *)((int)(p_equivalence + 3) & ~0x3); // align to word boundary
n_bytes = p_equivalence - p_start;
p_start[1] = remove_stress;
n_bytes = n_bytes / 4;
p_start[2] = n_bytes >> 8; // index of next table
p_start[3] = n_bytes;
LoadVoice(voice_name2,0); // reset the original phoneme table
LoadVoiceVariant(save_voice_name,0);
} // end of CompileEquivalents
static void CompilePhonemeFiles()
{//==============================
int item;
@@ -3161,8 +3299,9 @@ static void CompilePhonemeFiles()
item = NextItem(tKEYWORD);
if(item == kINCLUDE)
switch(item)
{
case kINCLUDE:
NextItem(tSTRING);
sprintf(buf,"%s%s",path_source,item_string);
if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL)
@@ -3176,32 +3315,36 @@ static void CompilePhonemeFiles()
strncpy0(current_fname,item_string,sizeof(current_fname));
linenum = 1;
}
}
else
if(item == kPHONEMETABLE)
{
break;
case kPHONEMETABLE:
EndPhonemeTable();
NextItem(tSTRING); // name of the new phoneme table
StartPhonemeTable(item_string);
}
else
if(item == kPHONEMESTART)
{
break;
case kPHONEMESTART:
if(n_phoneme_tabs == 0)
{
Error("phonemetable is missing");
return;
}
CompilePhoneme(1);
}
else
if(item == kPROCEDURE)
{
break;
case kPROCEDURE:
CompilePhoneme(0);
break;
case kEQUIVALENTS:
CompileEquivalents();
break;
default:
if(!feof(f_in))
Error("Keyword 'phoneme' expected");
break;
}
else
if(!feof(f_in))
Error("Keyword 'phoneme' expected");
}
phoneme_tab2[n_phcodes+1].mnemonic = 0; // terminator
} // end of CompilePhonemeFiles
@@ -3275,6 +3418,7 @@ memset(markers_used,0,sizeof(markers_used));
"# S - A SPECT_SEQ structure\n"
"# W - A wavefile segment\n"
"# E - An envelope\n"
"# Q - Phoneme equivalence tables\n"
"#\n"
"# Address is the displacement within phondata of this item\n"
"#\n"
+12 -7
View File
@@ -53,6 +53,7 @@ static char *hash_chains[N_HASH_DICT];
static char letterGroupsDefined[N_LETTER_GROUPS];
MNEM_TAB mnem_rules[] = {
{"unpr", 0x01},
{"w_alt2", 0x12},
{"w_alt3", 0x13},
{"w_alt", 0x11}, // note: put longer names before their sub-strings
@@ -192,8 +193,8 @@ char *print_dictionary_flags(unsigned int *flags)
char *DecodeRule(const char *group_chars, int group_length, char *rule)
{//====================================================================
char *DecodeRule(const char *group_chars, int group_length, char *rule, int control)
{//=================================================================================
/* Convert compiled match template to ascii */
unsigned char rb;
@@ -268,16 +269,20 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule)
if(rb == RULE_DOLLAR)
{
p[0] = '$';
name = LookupMnemName(mnem_rules, *rule++);
strcpy(&p[1],name);
p += (strlen(name)+1);
value = *rule++ & 0xff;
if((value != 0x01) || (control & FLAG_UNPRON_TEST))
{
p[0] = '$';
name = LookupMnemName(mnem_rules, value);
strcpy(&p[1],name);
p += (strlen(name)+1);
}
c = ' ';
}
else
if(rb == RULE_ENDING)
{
static const char *flag_chars = "ei vtfq t";
static const char *flag_chars = "eipvdfq tba ";
flags = ((rule[0] & 0x7f)<< 8) + (rule[1] & 0x7f);
suffix_char = 'S';
if(flags & (SUFX_P >> 8))
+76 -127
View File
@@ -38,15 +38,16 @@ int dictionary_skipwords;
char dictionary_name[40];
extern char *print_dictionary_flags(unsigned int *flags);
extern char *DecodeRule(const char *group_chars, int group_length, char *rule);
extern char *DecodeRule(const char *group_chars, int group_length, char *rule, int control);
// accented characters which indicate (in some languages) the start of a separate syllable
//static const unsigned short diereses_list[7] = {L'ä',L'ë',L'ï',L'ö',L'ü',L'ÿ',0};
static const unsigned short diereses_list[7] = {0xe4,0xeb,0xef,0xf6,0xfc,0xff,0};
// convert characters to an approximate 7 bit ascii equivalent
// used for checking for vowels
static unsigned char remove_accent[] = {
// used for checking for vowels (up to 0x259=schwa)
#define N_REMOVE_ACCENT 0x25e
static unsigned char remove_accent[N_REMOVE_ACCENT] = {
'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
'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i', // 0e0
@@ -73,7 +74,9 @@ static unsigned char remove_accent[] = {
'r','r','r','r','u','u','u','u','s','s','t','t','y','y','h','h', // 210
'n','d','o','o','z','z','a','a','e','e','o','o','o','o','o','o', // 220
'o','o','y','y','l','n','t','j','d','q','a','c','c','l','t','s', // 230
'z', 0 };
'z', 0, 0, 'b','u','v','e','e','j','j','q','q','r','r','y','y', // 240
'a','a','a','b','o','c','d','d','e','e','e','e','e','e' };
@@ -86,8 +89,8 @@ void strncpy0(char *to,const char *from, int size)
}
static int reverse_word_bytes(int word)
{//=============================
int Reverse4Bytes(int word)
{//========================
// reverse the order of bytes from little-endian to big-endian
#ifdef ARCH_BIG
int ix;
@@ -170,9 +173,9 @@ static void InitGroups(Translator *tr)
pw = (unsigned int *)(tr->langopts.replace_chars);
while(*pw != 0)
{
*pw = reverse_word_bytes(*pw);
*pw = Reverse4Bytes(*pw);
pw++;
*pw = reverse_word_bytes(*pw);
*pw = Reverse4Bytes(*pw);
pw++;
}
#endif
@@ -275,7 +278,7 @@ int LoadDictionary(Translator *tr, const char *name, int no_error)
pw = (int *)(tr->data_dictlist);
length = reverse_word_bytes(pw[1]);
length = Reverse4Bytes(pw[1]);
if(size <= (N_HASH_DICT + sizeof(int)*2))
{
@@ -283,10 +286,10 @@ int LoadDictionary(Translator *tr, const char *name, int no_error)
return(2);
}
if((reverse_word_bytes(pw[0]) != N_HASH_DICT) ||
if((Reverse4Bytes(pw[0]) != N_HASH_DICT) ||
(length <= 0) || (length > 0x8000000))
{
fprintf(stderr,"Bad data: '%s' (%x length=%x)\n",fname,reverse_word_bytes(pw[0]),length);
fprintf(stderr,"Bad data: '%s' (%x length=%x)\n",fname,Reverse4Bytes(pw[0]),length);
return(2);
}
tr->data_dictrules = &(tr->data_dictlist[length]);
@@ -742,7 +745,7 @@ static int IsLetter(Translator *tr, int letter, int group)
}
else
{
if((letter >= 0xc0) && (letter <= 0x241))
if((letter >= 0xc0) && (letter < N_REMOVE_ACCENT))
return(tr->letter_bits[remove_accent[letter-0xc0]] & (1L << group));
}
@@ -753,107 +756,31 @@ static int IsLetter(Translator *tr, int letter, int group)
}
static int IsVowel(Translator *tr, int letter)
{//===========================================
return(IsLetter(tr, letter, 0));
int IsVowel(Translator *tr, int letter)
{//====================================
return(IsLetter(tr, letter, LETTERGP_VOWEL2));
}
static int Unpronouncable_en(Translator *tr, char *word)
{//=====================================================
/* Determines whether a word in 'unpronouncable', i.e. whether it should
be spoken as individual letters.
This function is language specific.
*/
static int Unpronouncable2(Translator *tr, char *word)
{//===================================================
int c;
int vowel_posn=9;
int index;
int count;
int ix;
int apostrophe=0;
int end_flags;
char ph_buf[N_WORD_PHONEMES];
static unsigned char initials_bitmap[86] = {
0x00, 0x00, 0x00, 0x00, 0x22, 0x08, 0x00, 0x88, // 0
0x20, 0x24, 0x20, 0x80, 0x10, 0x00, 0x00, 0x00,
0x00, 0x28, 0x08, 0x00, 0x88, 0x22, 0x04, 0x00, // 16
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x88, 0x22, 0x04, 0x00, 0x02, 0x00, 0x04, // 32
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x28, 0x8a, 0x03, 0x00, 0x00, 0x40, 0x00, // 48
0x02, 0x00, 0x41, 0xca, 0xbb, 0x06, 0x20, 0x80,
0x91, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, // 64
0x08, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x22, 0x00, 0x01, 0x00, };
// words which we pass through to the dictionary, even though they look unpronouncable
static const char *exceptions[] = {
"'s ", "st ","nd ","rd ","th ",NULL };
if((*word == ' ') || (*word == 0))
return(0);
for(ix=0; exceptions[ix] != NULL; ix++)
{
// Seemingly uncpronouncable words, but to be looked in the dictionary rules instead
if(memcmp(word,exceptions[ix],3)==0)
return(0);
}
index=0;
count=0;
for(;;)
{
index += utf8_in(&c,&word[index]);
count++;
if((c==0) || (c==' ') || (c == '\''))
break;
if(IsVowel(tr, c) || (c == 'y'))
{
vowel_posn = count;
break;
}
if(c == '\'')
apostrophe = 1;
else
if(!IsAlpha(c))
return(0); // letter (not vowel) outside Latin character range or apostrophe, abort test
}
if((vowel_posn > 5) || ((word[0]!='s') && (vowel_posn > 4)))
return(1); // no vowel, or no vowel in first four letters
/* there is at least one vowel, is the initial letter combination valid ? */
if(vowel_posn < 3)
return(0); /* vowel in first two letters, OK */
if(apostrophe)
return(0); // first two letters not a-z, abort test
index = (word[0]-'a') * 26 + (word[1]-'a');
if(initials_bitmap[index >> 3] & (1L << (index & 7)))
return(0);
else
return(1); /****/
} /* end of Unpronounceable */
static int Unpronouncable_de(Translator *tr, char *word)
{//=====================================================
if(memcmp(word,"tsch",4)==0)
return(0);
return(2);
ph_buf[0] = 0;
c = word[-1];
word[-1] = ' '; // ensure there is a space before the "word"
end_flags = TranslateRules(tr, word, ph_buf, sizeof(ph_buf), NULL, FLAG_UNPRON_TEST, NULL);
word[-1] = c;
if((end_flags == 0) || (end_flags & SUFX_UNPRON))
return(1);
return(0);
}
int Unpronouncable(Translator *tr, char *word)
{//===========================================
/* Determines whether a word in 'unpronouncable', i.e. whether it should
@@ -868,18 +795,6 @@ int Unpronouncable(Translator *tr, char *word)
int index;
int count;
int apostrophe=0;
int result=2; // unknown
if(tr->translator_name == L('e','n'))
{
return(Unpronouncable_en(tr,word));
}
if(tr->translator_name == L('d','e'))
{
result = Unpronouncable_de(tr,word);
}
if(result < 2)
return(result);
utf8_in(&c,word);
if((tr->letter_bits_offset > 0) && (c < 0x241))
@@ -899,9 +814,12 @@ int Unpronouncable(Translator *tr, char *word)
for(;;)
{
index += utf8_in(&c,&word[index]);
if((c==0) || (c==' ') || (c == '\''))
if((c==0) || (c==' '))
break;
if((c=='\'') && (count > 1))
break; // "tv'" but not "l'"
if(count==0)
c1 = c;
count++;
@@ -916,11 +834,14 @@ int Unpronouncable(Translator *tr, char *word)
apostrophe = 1;
else
if(!iswalpha(c))
return(0); // letter (not vowel) outside a-z range or apostrophe, abort test
return(0);
}
if((vowel_posn < 9) && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 2))
return(0); // option means allow any word with a vowel
if((vowel_posn > 2) && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 2))
{
// Lookup unpronounable rules in *_rules
return(Unpronouncable2(tr, word));
}
if(c1 == tr->langopts.param[LOPT_UNPRONOUNCABLE])
vowel_posn--; // disregard this as the initial letter when counting
@@ -1813,6 +1734,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
int match_type; /* left, right, or consume */
int failed;
int unpron_ignore;
int consumed; /* number of letters consumed from input */
int count; /* count through rules in the group */
int syllable_count;
@@ -1858,6 +1780,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
/* search through dictionary rules */
while(rule[0] != RULE_GROUP_END)
{
unpron_ignore = word_flags & FLAG_UNPRON_TEST;
match_type=0;
consumed = 0;
letter = 0;
@@ -1874,6 +1797,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
/* work through next rule until end, or until no-match proved */
rule_start = rule;
failed = 0;
while(!failed)
{
@@ -1904,6 +1828,14 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
break;
case RULE_PRE:
match_type = RULE_PRE;
if(word_flags & FLAG_UNPRON_TEST)
{
// checking the start of the word for unpronouncable character sequences, only
// consider rules which explicitly match the start of a word
if(rule[0] != ' ')
failed = 1;
unpron_ignore = 0;
}
break;
case RULE_POST:
match_type = RULE_POST;
@@ -2046,8 +1978,14 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
case RULE_DOLLAR:
command = *rule++;
if(command == 0x01)
{
match.end_type = SUFX_UNPRON; // $unpron
}
else
if((command & 0xf0) == 0x10)
{
// $w_alt
if(dict_flags & (1 << (BITNUM_FLAG_ALT + (command & 0xf))))
add_points = 23;
else
@@ -2056,6 +1994,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
else
if((command & 0xf0) == 0x20)
{
// $p_alt
// make a copy of the word up to the post-match characters
ix = *word - word_start + consumed + group_length + 1;
memcpy(word_buf, word_start-1, ix);
@@ -2151,8 +2090,8 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
break;
case RULE_DEL_FWD:
// find the next 'e' in the word and replace by ''
for(p = *word + group_length; *p != ' '; p++)
// find the next 'e' in the word and replace by 'E'
for(p = *word + group_length; p < post_ptr; p++)
{
if(*p == 'e')
{
@@ -2366,9 +2305,11 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
match.points += add_points;
}
if(failed == 2)
if((failed == 2) && (unpron_ignore == 0))
{
/* matched OK, is this better than the last best match ? */
if(match.points >= best.points)
{
memcpy(&best,&match,sizeof(match));
@@ -2386,7 +2327,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_
if(group_length > 1)
pts += 35; // to account for an extra letter matching
DecodePhonemes(match.phonemes,decoded_phonemes);
fprintf(f_trans,"%3d\t%s [%s]\n",pts,DecodeRule(group_chars, group_length, rule_start),decoded_phonemes);
fprintf(f_trans,"%3d\t%s [%s]\n",pts,DecodeRule(group_chars, group_length, rule_start, word_flags), decoded_phonemes);
}
}
@@ -2469,7 +2410,10 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
wordbuf[ix] = c;
}
wordbuf[ix] = 0;
fprintf(f_trans,"Translate '%s'\n",wordbuf);
if(word_flags & FLAG_UNPRON_TEST)
fprintf(f_trans,"Unpronouncable? '%s'\n",wordbuf);
else
fprintf(f_trans,"Translate '%s'\n",wordbuf);
}
p = p_start;
@@ -2597,7 +2541,7 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
}
// no match, try removing the accent and re-translating the word
if((letter >= 0xc0) && (letter <= 0x241) && ((ix = remove_accent[letter-0xc0]) != 0))
if((letter >= 0xc0) && (letter < N_REMOVE_ACCENT) && ((ix = remove_accent[letter-0xc0]) != 0))
{
// within range of the remove_accent table
if((p[-2] != ' ') || (p[n] != ' '))
@@ -2682,7 +2626,11 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
strcpy(phonemes,match1.phonemes);
return(0);
}
if(word_flags & FLAG_UNPRON_TEST)
return(match1.end_type | 1);
match1.end_type &= ~SUFX_UNPRON;
if((match1.end_type != 0) && (end_phonemes != NULL))
{
/* a standard ending has been found, re-translate the word without it */
@@ -3524,7 +3472,8 @@ int RemoveEnding(Translator *tr, char *word, int end_type, char *word_copy)
if((strcmp(ending,"s")==0) || (strcmp(ending,"es")==0))
end_flags |= FLAG_SUFX_S;
if(strcmp(ending,"'s")==0)
// if(strcmp(ending,"'s")==0)
if(ending[0] == '\'')
end_flags &= ~FLAG_SUFX; // don't consider 's as an added suffix
return(end_flags);
+2
View File
@@ -233,6 +233,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
EVT_MENU(MENU_LEXICON_DE, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_IT, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_IT2, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_TEST, MyFrame::OnTools)
EVT_MENU(MENU_TO_UTF8, MyFrame::OnTools)
EVT_MENU(MENU_COUNT_WORDS, MyFrame::OnTools)
EVT_MENU(MENU_TEST, MyFrame::OnTools)
@@ -608,6 +609,7 @@ void MyFrame::OnTools(wxCommandEvent& event)
case MENU_LEXICON_DE:
case MENU_LEXICON_IT:
case MENU_LEXICON_IT2:
case MENU_LEXICON_TEST:
CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
break;
+72
View File
@@ -763,6 +763,75 @@ void Lexicon_De()
}
extern int IsVowel(Translator *tr, int letter);
void Lexicon_Test()
{//================
int c1, c2, c3;
char *p;
int prev_c1=0;
int prev_c2=0;
int prev_c3 = 0;
FILE *f_in;
FILE *f_out;
char buf[200];
wxString s_fname = wxFileSelector(_T("List of UTF-8 words with Combining Grave Accent U+300 to indicate stress"),path_dir1,
_T(""),_T(""),_T("*"),wxOPEN);
if(s_fname.IsEmpty())
return;
strcpy(buf,s_fname.mb_str(wxConvLocal));
path_dir1 = wxFileName(s_fname).GetPath();
if((f_in = fopen(buf,"r")) == NULL)
{
wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
return;
}
strcat(buf,"_1");
if((f_out = fopen(buf,"w")) == NULL)
{
wxLogError(_T("Can't write file: ") + wxString(buf,wxConvLocal));
fclose(f_in);
return;
}
while(!feof(f_in))
{
if((p = fgets(buf,sizeof(buf),f_in)) == NULL)
break;
if(buf[0] == 0)
continue;
p += utf8_in(&c1, p);
p += utf8_in(&c2, p);
p += utf8_in(&c3, p);
c1 = towlower(c1);
c2 = towlower(c2);
c3 = towlower(c3);
if(IsVowel(translator, c1))
continue;
if(IsVowel(translator, c2))
continue;
if((prev_c1 != c1) || (prev_c2 != c2) || ((prev_c3 != c3) && !IsVowel(translator,c3)))
fputc('\n',f_out);
prev_c1 = c1;
prev_c2 = c2;
prev_c3 = c3;
fprintf(f_out,"%s",buf);
}
fclose(f_in);
fclose(f_out);
} // end of Lexicon_Test
void Lexicon_Bg()
{//==============
// Bulgarian: compare stress markup in a list of words with lookup using bg_rules
@@ -1275,6 +1344,9 @@ void CompareLexicon(int id)
case MENU_LEXICON_IT2:
Lexicon_It(2);
break;
case MENU_LEXICON_TEST:
Lexicon_Test();
break;
}
} // end of CompareLexicon
+1
View File
@@ -161,6 +161,7 @@ enum {
MENU_LEXICON_DE,
MENU_LEXICON_IT,
MENU_LEXICON_IT2,
MENU_LEXICON_TEST,
MENU_TO_UTF8,
MENU_COUNT_WORDS,
MENU_TEST,
+1
View File
@@ -128,6 +128,7 @@ wxMenuBar *MakeMenu(int type, const char *dict_name)
lexicon_menu->Append(MENU_LEXICON_DE, _("German"));
lexicon_menu->Append(MENU_LEXICON_IT, _("Italian"));
lexicon_menu->Append(MENU_LEXICON_IT2, _("Italian, pass 2"));
// lexicon_menu->Append(MENU_LEXICON_TEST, _("Test"));
tools_menu = new wxMenu;
tools_menu->Append(MENU_VOWELCHART, _("Make &Vowels Chart"), vowelchart_menu);
+16 -3
View File
@@ -766,7 +766,7 @@ static int CheckDotOrdinal(Translator *tr, char *word, char *word_end, WORD_TAB
if(word_end[0] == '.')
utf8_in(&c2, &word_end[2]);
else
utf8_in(&c2, &word_end[1]);
utf8_in(&c2, &word_end[0]);
if((word_end[1] != 0) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || IsAlpha(c2)))
{
@@ -850,8 +850,8 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
flags[0] = 0;
flags[1] = 0;
if((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER))
return(0);
if(((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER)) || isdigit(word[-2]))
return(0); // not '2xx'
word_start = word;
while((c = *word++) != ' ')
@@ -889,6 +889,10 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
prev = value;
n_digits++;
}
if(isdigit(word[0]))
return(0); // eg. 'xx2'
acc += prev;
if(acc < tr->langopts.min_roman)
return(0);
@@ -896,6 +900,7 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
if(acc > tr->langopts.max_roman)
return(0);
Lookup(tr, "_roman",ph_roman); // precede by "roman" if _rom is defined in *_list
p = &ph_out[0];
@@ -931,6 +936,10 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
return(0);
}
}
else
{
wtab[0].flags |= FLAG_ORDINAL;
}
}
tr->prev_dict_flags = 0;
@@ -1071,6 +1080,10 @@ static int LookupThousands(Translator *tr, int value, int thousandplex, int thou
}
}
sprintf(ph_out,"%s%s",ph_of,ph_thousands);
if((value == 1) && (thousandplex == 1) && (tr->langopts.numbers & NUM_OMIT_1_THOUSAND))
return(1);
return(found_value);
}
+2 -1
View File
@@ -130,7 +130,8 @@ typedef struct {
char name[N_PHONEME_TAB_NAME];
PHONEME_TAB *phoneme_tab_ptr;
int n_phonemes;
int includes; // also include the phonemes from this other phoneme table
int includes; // also include the phonemes from this other phoneme table
int equivalence_tables; // lists of equivalent phonemes to match other languages, byte index into phondata
} PHONEME_TAB_LIST;
+1 -1
View File
@@ -613,7 +613,7 @@ void MyFrame::OnProsody(wxCommandEvent& WXUNUSED(event))
prosodyframe->CreateStatusBar();
int width, height;
wxMDIClientWindow *clientwin = this->GetClientWindow();
wxMDIClientWindow *clientwin = (wxMDIClientWindow *)this->GetClientWindow();
clientwin->GetClientSize(&width, &height);
#ifdef deleted
+5 -9
View File
@@ -1995,8 +1995,8 @@ static MNEM_TAB xml_char_mnemonics[] = {
{NULL,-1}};
int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type)
{//=============================================================================================================
int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type, char *voice_change)
{//=================================================================================================================================
/* Find the end of the current clause.
Write the clause into buf
@@ -2051,6 +2051,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix
tr->clause_lower_count = 0;
end_of_input = 0;
*tone_type = 0;
*voice_change = 0;
f_input = f_in; // for GetC etc
@@ -2218,16 +2219,11 @@ f_input = f_in; // for GetC etc
if(terminator & CLAUSE_BIT_VOICE)
{
// a change in voice, write the new voice name to the end of the buf
p = current_voice_id;
while((*p != 0) && (ix < (n_buf-1)))
{
buf[ix++] = *p++;
}
buf[ix++] = 0;
strcpy(voice_change, current_voice_id);
}
return(terminator);
}
c1 = ' ';
c2 = GetC();
continue;
}
+1 -1
View File
@@ -73,7 +73,7 @@ BOOL load_MBR()
if(hinstDllMBR != NULL)
return TRUE; // already loaded
if (!(hinstDllMBR=LoadLibraryA("mbrola.dll")))
if ((hinstDllMBR=LoadLibraryA("mbrola.dll")) == 0)
return FALSE;
init_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"init_MBR");
write_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"write_MBR");
+14 -11
View File
@@ -35,8 +35,8 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.43.57 18.Jul.10";
const int version_phdata = 0x014354;
const char *version_string = "1.43.63 02.Aug.10";
const int version_phdata = 0x014361;
int option_device_number = -1;
FILE *f_logespeak = NULL;
@@ -49,7 +49,7 @@ PHONEME_TAB *phoneme_tab[N_PHONEME_TAB];
unsigned char phoneme_tab_flags[N_PHONEME_TAB]; // bit 0: not inherited
USHORT *phoneme_index=NULL;
char *spects_data=NULL;
char *phondata_ptr=NULL;
unsigned char *wavefile_data=NULL;
static unsigned char *phoneme_tab_data = NULL;
@@ -116,16 +116,17 @@ int LoadPhData()
int result = 1;
int length;
unsigned char *p;
int *pw;
if((phoneme_tab_data = (unsigned char *)ReadPhFile((void *)(phoneme_tab_data),"phontab",NULL)) == NULL)
return(-1);
if((phoneme_index = (USHORT *)ReadPhFile((void *)(phoneme_index),"phonindex",NULL)) == NULL)
return(-1);
if((spects_data = ReadPhFile((void *)(spects_data),"phondata",NULL)) == NULL)
if((phondata_ptr = ReadPhFile((void *)(phondata_ptr),"phondata",NULL)) == NULL)
return(-1);
if((tunes = (TUNE *)ReadPhFile((void *)(tunes),"intonations",&length)) == NULL)
return(-1);
wavefile_data = (unsigned char *)spects_data;
wavefile_data = (unsigned char *)phondata_ptr;
n_tunes = length / sizeof(TUNE);
// read the version number from the first 4 bytes of phondata
@@ -150,7 +151,9 @@ int LoadPhData()
n_phonemes = p[0];
phoneme_tab_list[ix].n_phonemes = p[0];
phoneme_tab_list[ix].includes = p[1];
p += 4;
pw = (int *)p;
phoneme_tab_list[ix].equivalence_tables = Reverse4Bytes(pw[1]);
p += 8;
memcpy(phoneme_tab_list[ix].name,p,N_PHONEME_TAB_NAME);
p += N_PHONEME_TAB_NAME;
phoneme_tab_list[ix].phoneme_tab_ptr = (PHONEME_TAB *)p;
@@ -168,10 +171,10 @@ void FreePhData(void)
{//==================
Free(phoneme_tab_data);
Free(phoneme_index);
Free(spects_data);
Free(phondata_ptr);
phoneme_tab_data=NULL;
phoneme_index=NULL;
spects_data=NULL;
phondata_ptr=NULL;
}
@@ -226,7 +229,7 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params,
frame_t *frame;
static frameref_t frames_buf[N_SEQ_FRAMES];
seq = (SPECT_SEQ *)(&spects_data[fmt_params->fmt_addr]);
seq = (SPECT_SEQ *)(&phondata_ptr[fmt_params->fmt_addr]);
seqk = (SPECT_SEQK *)seq;
nf = seq->n_frames;
@@ -279,7 +282,7 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params,
{
// a secondary reference has been returned, which is not a wavefile
// add these spectra to the main sequence
seq2 = (SPECT_SEQ *)(&spects_data[fmt_params->fmt2_addr]);
seq2 = (SPECT_SEQ *)(&phondata_ptr[fmt_params->fmt2_addr]);
seqk2 = (SPECT_SEQK *)seq2;
// first frame of the addition just sets the length of the last frame of the main seq
@@ -371,7 +374,7 @@ unsigned char *GetEnvelope(int index)
fprintf(stderr,"espeak: No envelope\n");
return(envelope_data[0]); // not found, use a default envelope
}
return((unsigned char *)&spects_data[index]);
return((unsigned char *)&phondata_ptr[index]);
}
+5 -1
View File
@@ -254,6 +254,9 @@ static int DoSample2(int index, int which, int std_length, int control, int leng
wav_length = (p[1] * 256);
wav_length += p[0]; // length in bytes
if(wav_length == 0)
return(0);
min_length = speed.min_sample_len;
if(wav_scale==0)
@@ -1656,7 +1659,8 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
{
InterpretPhoneme2(p->tone_ph, &phdata_tone);
pitch_env = GetEnvelope(phdata_tone.pitch_env);
amp_env = GetEnvelope(phdata_tone.amp_env);
if(phdata_tone.amp_env > 0)
amp_env = GetEnvelope(phdata_tone.amp_env);
}
StartSyllable();
+1
View File
@@ -533,6 +533,7 @@ int SelectPhonemeTableName(const char *name);
void Write4Bytes(FILE *f, int value);
int Read4Bytes(FILE *f);
int Reverse4Bytes(int word);
int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *err_name,int flags);
+17 -10
View File
@@ -130,7 +130,7 @@ static Translator* NewTranslator(void)
memset(tr->letter_bits,0,sizeof(tr->letter_bits));
memset(tr->letter_groups,0,sizeof(tr->letter_groups));
// 0-5 sets of characters matched by A B C E F G in pronunciation rules
// 0-5 sets of characters matched by A B C H F G Y in pronunciation rules
// these may be set differently for different languages
SetLetterBits(tr,0,"aeiou"); // A vowels, except y
SetLetterBits(tr,1,"bcdfgjklmnpqstvxz"); // B hard consonants, excluding h,r,w
@@ -424,7 +424,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.stress_rule = STRESSPOSN_1L;
SetLetterVowel(tr,'y');
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_HUNDRED_AND | NUM_OMIT_1_HUNDRED | NUM_ORDINAL_DOT | NUM_1900;
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_HUNDRED_AND | NUM_OMIT_1_HUNDRED | NUM_ORDINAL_DOT | NUM_1900 | NUM_ROMAN | NUM_ROMAN_CAPITALS | NUM_ROMAN_ORDINAL;
}
break;
@@ -440,8 +440,9 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_LONG_VOWEL_THRESHOLD] = 175/2;
memcpy(tr->stress_lengths,stress_lengths_de,sizeof(tr->stress_lengths));
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_OMIT_1_HUNDRED | NUM_ALLOW_SPACE | NUM_ORDINAL_DOT | NUM_ROMAN;
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND | NUM_ALLOW_SPACE | NUM_ORDINAL_DOT | NUM_ROMAN;
SetLetterVowel(tr,'y');
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 2; // use de_rules for unpronouncable rules
}
break;
@@ -458,6 +459,8 @@ Translator *SelectTranslator(const char *name)
tr->langopts.numbers = NUM_HUNDRED_AND | NUM_ROMAN | NUM_1900;
tr->langopts.param[LOPT_COMBINE_WORDS] = 2; // allow "mc" to cmbine with the following word
tr->langopts.suffix_add_e = 'e';
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 2; // use en_rules for unpronouncable rules
SetLetterBits(tr,6,"aeiouy"); // Group Y: vowels, including y
}
break;
@@ -547,7 +550,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.unstressed_wd2 = 2;
tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_ROMAN | NUM_ROMAN_AFTER;
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND | NUM_ROMAN | NUM_ROMAN_AFTER;
if(name2 == L('c','a'))
{
@@ -559,6 +562,10 @@ Translator *SelectTranslator(const char *name)
{
tr->langopts.stress_flags = 0x100 | 0x6 | 0x30; // stress last syllable unless word ends with a vowel
}
else
{
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 2; // use es_rules for unpronouncable rules
}
}
break;
@@ -702,7 +709,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_IT_DOUBLING] = 1;
tr->langopts.param[LOPT_ANNOUNCE_PUNCT] = 2; // don't break clause before announcing . ? !
tr->langopts.numbers = NUM_DFRACTION_5 | NUM_ALLOW_SPACE | NUM_ROMAN | NUM_ROMAN_ORDINAL | NUM_ROMAN_CAPITALS | NUM_ORDINAL_DOT | NUM_OMIT_1_HUNDRED;
tr->langopts.numbers = NUM_DFRACTION_5 | NUM_ALLOW_SPACE | NUM_ROMAN | NUM_ROMAN_ORDINAL | NUM_ROMAN_CAPITALS | NUM_ORDINAL_DOT | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND;
tr->langopts.thousands_sep = ' '; // don't allow dot as thousands separator
tr->langopts.decimal_sep = ',';
tr->langopts.max_roman = 899;
@@ -879,7 +886,7 @@ SetLengthMods(tr,3); // all equal
tr->letter_groups[0] = vowels_cyrillic;
tr->langopts.stress_rule = STRESSPOSN_3R; // antipenultimate
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_DFRACTION_2;
tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND | NUM_DFRACTION_2;
tr->langopts.numbers2 = 0x8a; // variant numbers before thousands,milliards
}
break;
@@ -1098,7 +1105,7 @@ SetLengthMods(tr,3); // all equal
if(name2 == L('t','a'))
{
tr->letter_bits_offset = OFFSET_TAMIL;
tr->langopts.numbers = 0x1;
tr->langopts.numbers = NUM_OMIT_1_THOUSAND ;
}
if(name2 == L('m','r'))
{
@@ -1140,8 +1147,8 @@ SetLengthMods(tr,3); // all equal
case L('t','r'): // Turkish
{
static const unsigned char stress_amps_tr[8] = {18,16, 20,20, 20,21, 21,20 };
static const short stress_lengths_tr[8] = {190,180, 200,200, 0,0, 240,250};
static const unsigned char stress_amps_tr[8] = {18,16, 20,21, 20,21, 21,20 };
static const short stress_lengths_tr[8] = {190,180, 200,230, 0,0, 240,250};
SetupTranslator(tr,stress_lengths_tr,stress_amps_tr);
tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
@@ -1149,7 +1156,7 @@ SetLengthMods(tr,3); // all equal
tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
tr->langopts.stress_flags = 0x20; //no automatic secondary stress
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_OMIT_1_HUNDRED | NUM_DFRACTION_2;
tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_OMIT_1_HUNDRED | NUM_OMIT_1_THOUSAND | NUM_DFRACTION_2;
tr->langopts.max_initial_consonants = 2;
}
break;
+114 -2
View File
@@ -667,6 +667,98 @@ static int CheckDottedAbbrev(char *word1, WORD_TAB *wtab)
} // end of CheckDottedAbbrev
extern char *phondata_ptr;
int ChangeEquivalentPhonemes(Translator *tr, int lang2, char *phonemes)
{//====================================================================
// tr: the original language
// lang2: phoneme table number for the temporary language
// phonemes: the phonemes to be replaced
int ix;
int len;
char phon;
char *p;
unsigned char *pb;
char *eqlist;
char *p_out;
char *p_in;
int remove_stress = 0;
char phonbuf[N_WORD_PHONEMES];
// has a phoneme equivalence table been specified for thus language pair?
if((ix = phoneme_tab_list[tr->phoneme_tab_ix].equivalence_tables) == 0)
return(0);
pb = (unsigned char *)&phondata_ptr[ix];
for(;;)
{
if(pb[0] == 0)
return(0); // table not found
if(pb[0] == lang2)
break;
len = (pb[2] << 8) + pb[3]; // size of this table in words
pb += (len * 4);
}
remove_stress = pb[1];
if(option_phonemes == 2)
{
DecodePhonemes(phonemes, phonbuf);
fprintf(f_trans,"(%s) %s -> (%s) ", phoneme_tab_list[lang2].name, phonbuf, phoneme_tab_list[tr->phoneme_tab_ix].name);
}
p_in = phonemes;
eqlist = (char *)&pb[8];
p_out = phonbuf;
while((phon = *p_in++) != 0)
{
if(remove_stress && ((phon & 0xff) < phonSTRESS_PREV))
continue; // remove stress marks
// is there a translation for this phoneme code?
p = eqlist;
while(*p != 0)
{
len = strlen(&p[1]);
if(*p == phon)
{
strcpy(p_out, &p[1]);
p_out += len;
break;
}
p += (len + 2);
}
if(*p == 0)
{
// no translation found
*p_out++ = phon;
}
}
*p_out = 0;
if(remove_stress)
{
SetWordStress(tr, phonbuf, NULL, -1, 0);
}
strcpy(phonemes, phonbuf);
if(option_phonemes == 2)
{
SelectPhonemeTable(tr->phoneme_tab_ix);
DecodePhonemes(phonemes, phonbuf);
fprintf(f_trans,"%s\n\n", phonbuf);
}
return(1);
} // end of ChangeEquivalentPhonemes
int TranslateWord(Translator *tr, char *word1, int next_pause, WORD_TAB *wtab)
{//===========================================================================
@@ -1148,6 +1240,12 @@ strcpy(phonemes2,phonemes);
strcpy(word_phonemes,phonemes);
return(0);
}
if(dictionary_flags2[0] & FLAG_ABBREV)
{
// Removing the suffix leaves a word which should be spoken as individual letters
// Not yet implemented
}
if(dictionary_flags[0]==0)
{
dictionary_flags[0] = dictionary_flags2[0];
@@ -1697,6 +1795,19 @@ static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pa
p[1] = phonSCHWA;
p[2] = 0;
}
// ?? Option to convert from language2 phonemes to the equivalent language1 phonemes
// ?? Option to set the word-stress according to language1 rules eg. lang=fr)
if(ChangeEquivalentPhonemes(tr, switch_phonemes, (char *)p))
{
switch_phonemes = -1;
}
if(switch_phonemes == -1)
{
strcpy(dictionary_name, old_dictionary_name);
SelectPhonemeTable(voice->phoneme_tab_ix);
}
}
if(!(word_flags & FLAG_HYPHEN))
@@ -2196,6 +2307,7 @@ void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *t
short charix[N_TR_SOURCE+4];
WORD_TAB words[N_CLAUSE_WORDS];
static char voice_change_name[40];
int word_count=0; // index into words
char sbuf[N_TR_SOURCE];
@@ -2218,7 +2330,7 @@ void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *t
for(ix=0; ix<N_TR_SOURCE; ix++)
charix[ix] = 0;
terminator = ReadClause(tr, f_text, source, charix, &charix_top, N_TR_SOURCE, &tone2);
terminator = ReadClause(tr, f_text, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name);
if((f_logespeak != NULL) && (logging_type & 4))
{
@@ -3038,7 +3150,7 @@ if((c == '/') && (tr->langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(pre
{
// return new voice name if an embedded voice change command terminated the clause
if(terminator & CLAUSE_BIT_VOICE)
*voice_change = &source[source_index];
*voice_change = voice_change_name;
else
*voice_change = NULL;
}
+11 -4
View File
@@ -112,6 +112,8 @@
#define FLAG_SUFFIX_VOWEL 0x08000000 // remember an initial vowel from the suffix
#define FLAG_NO_TRACE 0x10000000 // passed to TranslateRules() to suppress dictionary lookup printout
#define FLAG_NO_PREFIX 0x20000000
#define FLAG_UNPRON_TEST 0x80000000 // do unpronounability test on the beginning of the word
// prefix/suffix flags (bits 8 to 14, bits 16 to 22) don't use 0x8000, 0x800000
#define SUFX_E 0x0100 // e may have been added
@@ -125,6 +127,8 @@
#define SUFX_B 0x20000 // break, this character breaks the word into stem and suffix (used with SUFX_P)
#define SUFX_A 0x40000 // remember that the suffix starts with a vowel
#define SUFX_UNPRON 0x8000 // used to return $unpron flag from *_rules
#define FLAG_ALLOW_TEXTMODE 0x02 // allow dictionary to translate to text rather than phonemes
#define FLAG_SUFX 0x04
@@ -221,9 +225,9 @@
typedef const char * constcharptr;
typedef struct {
int points;
int points;
const char *phonemes;
int end_type;
int end_type;
char *del_fwd;
} MatchRecord;
@@ -388,6 +392,7 @@ typedef struct {
#define NUM_AND_HUNDRED 0x40000
#define NUM_THOUSAND_AND 0x80000
#define NUM_VIGESIMAL 0x100000
#define NUM_OMIT_1_THOUSAND 0x200000
#define NUM_ROMAN 0x1000000
#define NUM_ROMAN_CAPITALS 0x2000000
@@ -413,6 +418,7 @@ typedef struct {
// bit18= 'and' before hundreds
// bit19= 'and' after thousands if there are no hundreds
// bit20= vigesimal number, if tens are not found
// bit21= omit "one" before "thousand"
// bit24= recognize roman numbers
// bit25= Roman numbers only if upper case
@@ -484,7 +490,8 @@ typedef struct
char phon_out[300];
char phonemes_repeat[20];
int phonemes_repeat_count;
int phonemes_repeat_count;
int phoneme_tab_ix;
unsigned char stress_amps[8];
unsigned char stress_amps_r[8];
@@ -650,7 +657,7 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags,
int TranslateRules(Translator *tr, char *p, char *phonemes, int size, char *end_phonemes, int end_flags, unsigned int *dict_flags);
int TranslateWord(Translator *tr, char *word1, int next_pause, WORD_TAB *wtab);
void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *tone, char **voice_change);
int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type);
int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type, char *voice_change);
void SetVoiceStack(espeak_VOICE *v);
void InterpretPhoneme(Translator *tr, int control, PHONEME_LIST *plist, PHONEME_DATA *phdata);
+1
View File
@@ -978,6 +978,7 @@ voice_t *LoadVoice(const char *vname, int control)
fprintf(stderr,"Unknown phoneme table: '%s'\n",phonemes_name);
}
voice->phoneme_tab_ix = ix;
new_translator->phoneme_tab_ix = ix;
error = LoadDictionary(new_translator, new_dictionary, control & 4);
if(dictionary_name[0]==0)
return(NULL); // no dictionary loaded
+2 -2
View File
@@ -41,7 +41,7 @@
*/
extern wxString path_phsource;
extern char *spects_data;
extern char *phondata_ptr;
extern USHORT *phoneme_index;
extern int n_phoneme_tables;
@@ -664,7 +664,7 @@ void MakeVowelLists(void)
{
ix = vowelfmt_addr[vowelfmt_ix];
seq = (SPECT_SEQ *)(&spects_data[ix]);
seq = (SPECT_SEQ *)(&phondata_ptr[ix]);
seqk = (SPECT_SEQK *)seq;
if(seq->frame[0].frflags & FRFLAG_KLATT)