[1.39.26]

Added languages: ca (Catalan) lv (Latvian)
Numbers: allow for languages which have numbers for 100,000 and (or not) 10,000,000 (eg. hi, sw)
Phoneme [ts] new files in phsource/ustop
*_rules: fix crash for lettergroups numbers greater than 10, and better error reporting.
Languages: eo, jbo: adjust syllable lengths.
Language: en, fix "1st, 2nd, 3rd, 5th".  But a full ordinal number feature is still needed.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@202 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2008-11-16 09:18:53 +00:00
parent 084cd2c17d
commit a7501374b2
46 changed files with 700 additions and 196 deletions
+2 -1
View File
@@ -264,6 +264,7 @@ static keywtab_t keywords[] = {
{"long", 0x2000000+phLONG},
{"brkafter", 0x2000000+phBRKAFTER},
{"nonsyllabic",0x2000000+phNONSYLLABIC},
{"lengthenstop",0x2000000+phLENGTHENSTOP},
// voiced / unvoiced
{"vcd", 0x2000000+phVOICED},
@@ -602,7 +603,7 @@ int Compile::LoadSpect(const char *path, int control)
float total;
float pkheight;
int marker1_set=0;
int frame_vowelbreak=NULL;
int frame_vowelbreak=0;
SpectFrame *fr;
wxString path_sep = _T("/");
+25 -9
View File
@@ -50,6 +50,7 @@ static int debug_flag = 0;
int hash_counts[N_HASH_DICT];
char *hash_chains[N_HASH_DICT];
char letterGroupsDefined[N_LETTER_GROUPS];
MNEM_TAB mnem_flags[] = {
// these in the first group put a value in bits0-3 of dictionary_flags
@@ -199,6 +200,10 @@ static char nullstring[] = {0};
text_not_phonemes = 0;
phonetic = word = nullstring;
if(memcmp(linebuf,"_-",2)==0)
{
step=1; // TEST
}
p = linebuf;
// while(isspace2(*p)) p++;
@@ -313,7 +318,7 @@ static char nullstring[] = {0};
break;
case 1:
if(c == '-')
if((c == '-') && (word[0] != '_'))
{
flag_codes[n_flag_codes++] = BITNUM_FLAG_HYPHENATED;
c = ' ';
@@ -798,10 +803,16 @@ void copy_rule_string(char *string, int &state)
c = *p++ - '0';
value = *p++ - '0';
c = c * 10 + value;
if((value < 0) || (value > 9) || (c <= 0) || (c >= N_LETTER_GROUPS))
if((value < 0) || (value > 9))
{
c = 0;
fprintf(f_log,"%5d: Expected 2 digits after 'L'",linenum);
fprintf(f_log,"%5d: Expected 2 digits after 'L'\n",linenum);
error_count++;
}
else
if((c <= 0) || (c >= N_LETTER_GROUPS) || (letterGroupsDefined[(int)c] == 0))
{
fprintf(f_log,"%5d: Letter group L%.2d not defined\n",linenum,c);
error_count++;
}
c += 'A';
@@ -1249,18 +1260,25 @@ static int compile_lettergroup(char *input, FILE *f_out)
p = input;
if(!isdigit(p[0]) || !isdigit(p[1]))
{
fprintf(f_log,"%5d: Expected 2 digits after '.L'\n",linenum);
error_count++;
return(1);
}
group = atoi(&p[1]);
group = atoi(&p[0]);
if(group >= N_LETTER_GROUPS)
{
fprintf(f_log,"%5d: lettergroup out of range (01-%.2d)\n",linenum,N_LETTER_GROUPS);
error_count++;
return(1);
}
while(!isspace2(*p)) p++;
fputc(RULE_GROUP_START,f_out);
fputc(RULE_LETTERGP2,f_out);
fputc(group + 'A', f_out);
letterGroupsDefined[group] = 1;
for(;;)
{
@@ -1346,11 +1364,7 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
if(memcmp(buf,".L",2)==0)
{
if(compile_lettergroup(&buf[2], f_out) != 0)
{
fprintf(f_log,"%5d: Bad lettergroup\n",linenum);
error_count++;
}
compile_lettergroup(&buf[2], f_out);
continue;
}
@@ -1509,6 +1523,8 @@ int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, cha
char path[sizeof(path_home)+40]; // path_dsource+20
error_count = 0;
memset(letterGroupsDefined,0,sizeof(letterGroupsDefined));
debug_flag = flags & 1;
if(dsource == NULL)
+13 -1
View File
@@ -686,6 +686,8 @@ int Translator::IsLetterGroup(char *word, int group, int pre)
char *w;
p = letterGroups[group];
if(p == NULL)
return(0);
while(*p != RULE_GROUP_END)
{
@@ -1012,7 +1014,9 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
int unstressed_word = 0;
char *max_output;
int final_ph;
int final_ph2;
int mnem;
int mnem2;
int post_tonic;
int opt_length;
int done;
@@ -1043,6 +1047,7 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
}
if(ix == 0) return;
final_ph = phonetic[ix-1];
final_ph2 = phonetic[ix-2];
max_output = output + (N_WORD_PHONEMES-3); /* check for overrun */
@@ -1131,7 +1136,14 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
else
{
mnem = phoneme_tab[final_ph]->mnemonic;
if((mnem != 'n') && (mnem != 's'))
mnem2 = phoneme_tab[final_ph2]->mnemonic;
if((mnem == 's') && (mnem2 == 'n'))
{
// -ns stress remains on penultimate syllable
}
else
if(((mnem != 'n') && (mnem != 's')) || (phoneme_tab[final_ph2]->type != phVOWEL))
{
stressed_syllable = vowel_count - 1;
}
+12 -20
View File
@@ -756,6 +756,7 @@ int Translator::TranslateRoman(char *word, char *ph_out)
int subtract;
int repeat = 0;
unsigned int flags;
char ph_roman[30];
char number_chars[N_WORD_BYTES];
static const char *roman_numbers = "ixcmvld";
@@ -806,11 +807,20 @@ int Translator::TranslateRoman(char *word, char *ph_out)
if(acc > langopts.max_roman)
return(0);
Lookup("_roman",ph_out); // precede by "roman" if _rom is defined in *_list
p = &ph_out[strlen(ph_out)];
Lookup("_roman",ph_roman); // precede by "roman" if _rom is defined in *_list
p = &ph_out[0];
if((langopts.numbers & NUM_ROMAN_AFTER) == 0)
{
strcpy(ph_out,ph_roman);
p = &ph_out[strlen(ph_out)];
}
sprintf(number_chars," %d ",acc);
TranslateNumber(&number_chars[1],p,&flags,0);
if(langopts.numbers & NUM_ROMAN_AFTER)
strcat(ph_out,ph_roman);
return(1);
} // end of TranslateRoman
@@ -1236,24 +1246,6 @@ int Translator::TranslateNumber_1(char *word, char *ph_out, unsigned int *flags,
{
if((thousandplex > 0) && (value < 1000))
{
if(langopts.numbers2 & 0x100)
{
if((thousandplex == 1) && (value >= 100))
{
// special word for 100,000's
char ph_buf3[20];
sprintf(string,"_%dL",value / 100);
if(Lookup(string,ph_buf2) == 0)
{
LookupNum2(value/100,0,ph_buf2);
Lookup("_0L",ph_buf3);
strcat(ph_buf2,ph_buf3);
}
value %= 100;
if(value == 0)
suppress_null = 1;
}
}
if((suppress_null == 0) && (LookupThousands(value,thousandplex,ph_append)))
{
// found an exact match for N thousand
+3 -2
View File
@@ -56,8 +56,9 @@
#define phBEFORENOTVOWEL2 0x1000
#define phSWITCHVOICING 0x0800
#define phNONSYLLABIC 0x100000 // don't count this vowel as a syllable when finding the stress position
#define phLONG 0x200000
#define phNONSYLLABIC 0x100000 // don't count this vowel as a syllable when finding the stress position
#define phLONG 0x200000
#define phLENGTHENSTOP 0x400000 // make the pre-pause slightly longer
// fixed phoneme code numbers, these can be used from the program code
#define phonCONTROL 1
+5 -1
View File
@@ -557,7 +557,11 @@ void Translator::MakePhonemeList(int post_pause, int start_sentence)
{
if((x = (langopts.word_gap & 0x7)) != 0)
{
insert_ph = pause_phonemes[x];
if((x > 1) || ((insert_ph != phonPAUSE_SHORT) && (insert_ph != phonPAUSE_NOLINK)))
{
// don't reduce the pause
insert_ph = pause_phonemes[x];
}
}
if(option_wordgap > 0)
{
+5 -2
View File
@@ -320,6 +320,9 @@ void Translator::CalcLengths()
if((langopts.word_gap & 0x10) && (p->newword))
p->prepause = 60;
if(p->ph->phflags & phLENGTHENSTOP)
p->prepause += 30;
if(p->synthflags & SFLAG_LENGTHEN)
p->prepause += langopts.long_stop;
break;
@@ -487,9 +490,9 @@ void Translator::CalcLengths()
}
// calc length modifier
if(next->ph->code == phonPAUSE_VSHORT)
if((next->ph->code == phonPAUSE_VSHORT) && (next2->type == phPAUSE))
{
// ignore very short pause
// if PAUSE_VSHORT is followed by a pause, then use that
next = next2;
next2 = next3;
next3 = &phoneme_list[ix+4];
+1 -1
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.39.22 10.Nov.08";
const char *version_string = "1.39.26 15.Nov.08";
const int version_phdata = 0x013900;
int option_device_number = -1;
+35 -8
View File
@@ -275,7 +275,7 @@ Translator *SelectTranslator(const char *name)
case L('e','o'):
{
static const short stress_lengths_eo[8] = {145, 145, 200, 170, 0, 0, 320, 340};
static const short stress_lengths_eo[8] = {145, 145, 230, 170, 0, 0, 360, 370};
static const unsigned char stress_amps_eo[] = {16,14, 20,20, 20,24, 24,22 };
static const wchar_t eo_char_apostrophe[2] = {'l',0};
@@ -286,6 +286,7 @@ Translator *SelectTranslator(const char *name)
tr->char_plus_apostrophe = eo_char_apostrophe;
tr->langopts.word_gap = 1;
tr->langopts.vowel_pause = 2;
tr->langopts.stress_rule = 2;
tr->langopts.stress_flags = 0x6 | 0x10;
tr->langopts.unstressed_wd1 = 3;
@@ -296,9 +297,12 @@ Translator *SelectTranslator(const char *name)
break;
case L('e','s'): // Spanish
case L('c','a'): // Catalan
{
static const short stress_lengths_es[8] = {170, 200, 180, 180, 0, 0, 220, 250};
static const short stress_lengths_es[8] = {180, 210, 190, 190, 0, 0, 230, 260};
// static const short stress_lengths_es[8] = {170, 200, 180, 180, 0, 0, 220, 250};
static const unsigned char stress_amps_es[8] = {16,12, 18,18, 20,20, 20,20 }; // 'diminished' is used to mark a quieter, final unstressed syllable
static const wchar_t ca_punct_within_word[] = {'\'',0xb7,0}; // ca: allow middle-dot within word
tr = new Translator();
SetupTranslator(tr,stress_lengths_es,stress_amps_es);
@@ -313,7 +317,13 @@ 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 = 0x529 + NUM_ROMAN;
tr->langopts.numbers = 0x529 + NUM_ROMAN + NUM_ROMAN_AFTER;
if(name2 == L('c','a'))
{
tr->punct_within_word = ca_punct_within_word;
tr->langopts.stress_flags = 0x200 | 0x6 | 0x30; // stress last syllable unless word ends with a vowel
}
}
break;
@@ -369,7 +379,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.stress_rule = 6; // stress on last heaviest syllable, excluding final syllable
tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
tr->langopts.numbers = 0x011;
tr->langopts.numbers2 = 0x100;
tr->langopts.numbers2 = NUM2_100000;
tr->letter_bits_offset = OFFSET_DEVANAGARI;
SetIndicLetters(tr);
}
@@ -515,12 +525,13 @@ SetLengthMods(tr,3); // all equal
case L_jbo: // Lojban
{
static const short stress_lengths_jbo[8] = {185,170, 200,200, 0,0, 290,300};
static const short stress_lengths_jbo[8] = {145,145, 170,160, 0,0, 330,350};
static const wchar_t jbo_punct_within_word[] = {'.',',','\'',0x2c8,0}; // allow period and comma within a word, also stress marker (from LOPT_SYLLABLE_CAPS)
tr = new Translator();
SetupTranslator(tr,stress_lengths_jbo,NULL);
tr->langopts.stress_rule = 2;
tr->langopts.vowel_pause = 0x20c; // pause before a word which starts with a vowel, or after a word which ends in a consonant
// tr->langopts.word_gap = 1;
tr->punct_within_word = jbo_punct_within_word;
tr->langopts.param[LOPT_SYLLABLE_CAPS] = 1; // capitals indicate stressed syllables
SetLetterVowel(tr,'y');
@@ -577,8 +588,10 @@ SetLengthMods(tr,3); // all equal
case L('l','v'): // latvian
{
static const unsigned char stress_amps_lv[8] = {17,14, 20,20, 20,22, 22,22 };
static const short stress_lengths_lv[8] = {180,140, 210,210, 0,0, 210,210};
tr = new Translator();
SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
SetupTranslator(tr,stress_lengths_lv,stress_amps_lv);
tr->langopts.stress_rule = 0;
tr->langopts.spelling_stress = 1;
@@ -636,6 +649,17 @@ SetLengthMods(tr,3); // all equal
}
break;
case L('o','m'):
{
static const unsigned char stress_amps_om[] = {16,16, 20,20, 20,24, 24,22 };
static const short stress_lengths_om[8] = {200,200, 200,200, 0,0, 200,200};
tr = new Translator();
SetupTranslator(tr,stress_lengths_om,stress_amps_om);
tr->langopts.stress_rule = 3;
}
break;
case L('p','l'): // Polish
{
static const short stress_lengths_pl[8] = {160, 190, 175, 175, 0, 0, 200, 210};
@@ -780,7 +804,7 @@ SetLengthMods(tr,3); // all equal
tr->langopts.stress_flags = 0x6 | 0x10;
tr->langopts.numbers = 0x4e1;
tr->langopts.numbers2 = 0x100;
tr->langopts.numbers2 = NUM2_100000a;
}
break;
@@ -807,13 +831,15 @@ SetLengthMods(tr,3); // all equal
if(name2 == L('k','n'))
{
tr->letter_bits_offset = OFFSET_KANNADA;
tr->langopts.numbers = 0x1;
tr->langopts.numbers2 = NUM2_100000;
}
tr->langopts.param[LOPT_WORD_MERGE] = 1; // don't break vowels betwen words
SetIndicLetters(tr); // call this after setting OFFSET_
}
break;
#ifdef deleted
case L('t','h'): // Thai
{
static const short stress_lengths_th[8] = {230,150, 230,230, 230,0, 230,250};
@@ -830,6 +856,7 @@ SetLengthMods(tr,3); // all equal
tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
}
break;
#endif
case L('t','r'): // Turkish
{
+62 -6
View File
@@ -2597,10 +2597,14 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
for(ix=0; ix<word_count; ix++)
{
int j;
int nx;
int c_temp;
char *pn;
char *pw;
static unsigned int break_numbers1 = 0x49249248;
static unsigned int break_numbers2 = 0x492492a8; // for languages which have numbers for 100,000 and 100,00,000
static unsigned int break_numbers3 = 0x49249268; // for languages which have numbers for 100,000 and 1,000,000
unsigned int break_numbers;
char number_buf[80];
// start speaking at a specified word position in the text?
@@ -2617,24 +2621,76 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
// digits should have been converted to Latin alphabet ('0' to '9')
word = pw = &sbuf[words[ix].start];
if(iswdigit(word[0]) && (langopts.numbers2 & NUM2_100000))
{
// Languages with 100000 numbers. Remove thousands separators so that we can insert them again later
pn = number_buf;
while(pn < &number_buf[sizeof(number_buf)-3])
{
if(iswdigit(*pw))
{
*pn++ = *pw++;
}
else
if((*pw == langopts.thousands_sep) && (pw[1] == ' ') && iswdigit(pw[2]))
{
pw += 2;
ix++; // skip "word"
}
else
{
nx = pw - word;
memset(word,' ',nx);
nx = pn - number_buf;
memcpy(word,number_buf,nx);
break;
}
}
pw = word;
}
for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
if((n_digits > 4) && (word[0] != '0'))
{
// word is entirely digits, insert commas and break into 3 digit "words"
number_buf[0] = ' ';
pn = &number_buf[1];
j = n_digits;
nx = n_digits;
if(langopts.numbers2 & NUM2_100000a)
break_numbers = break_numbers3;
else
if(langopts.numbers2 & NUM2_100000)
break_numbers = break_numbers2;
else
break_numbers = break_numbers1;
while(pn < &number_buf[sizeof(number_buf)-3])
{
if(!isdigit(c = *pw++) && (c != langopts.decimal_sep))
break;
*pn++ = c;
if((--j > 0) && (j % 3)==0)
if((--nx > 0) && (break_numbers & (1 << nx)))
{
if(langopts.thousands_sep != ' ')
{
*pn++ = langopts.thousands_sep;
}
*pn++ = ' ';
if(break_numbers & (1 << (nx-1)))
{
// the next group only has 1 digits (i.e. NUM2_10000), make it three
*pn++ = '0';
*pn++ = '0';
}
if(break_numbers & (1 << (nx-2)))
{
// the next group only has 2 digits (i.e. NUM2_10000), make it three
*pn++ = '0';
}
}
}
pn[0] = ' ';
@@ -2659,10 +2715,10 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
for(pw = word; *pw != ' ';)
{
memset(number_buf,' ',9);
j = utf8_in(&c_temp, pw, 0);
memcpy(&number_buf[2],pw,j);
nx = utf8_in(&c_temp, pw, 0);
memcpy(&number_buf[2],pw,nx);
TranslateWord2(&number_buf[2], &words[ix], 0, 0 );
pw += j;
pw += nx;
}
}
+10 -5
View File
@@ -29,7 +29,7 @@
#define N_RULE_GROUP2 120 // max num of two-letter rule chains
#define N_HASH_DICT 1024
#define N_CHARSETS 20
#define N_LETTER_GROUPS 20
#define N_LETTER_GROUPS 25
/* dictionary flags, word 1 */
@@ -322,9 +322,10 @@ typedef struct {
unsigned char *length_mods;
unsigned char *length_mods0;
#define NUM_ROMAN 0x20000
#define NUM_ROMAN_UC 0x40000
#define NUM_NOPAUSE 0x80000
#define NUM_ROMAN 0x20000
#define NUM_ROMAN_UC 0x40000
#define NUM_NOPAUSE 0x80000
#define NUM_ROMAN_AFTER 0x200000
// bits0-1=which numbers routine to use.
// bit2= thousands separator must be space
@@ -344,13 +345,17 @@ typedef struct {
// bit18=Roman numbers only if upper case
// bit19=don't add pause after a number
// bit20='and' before hundreds
// bit21= say "roman" after the number, not before
int numbers;
#define NUM2_100000 0x100 // numbers for 100,000 and 10,000,000
#define NUM2_100000a 0x500 // numbers for 100,000 and 1,000,000
// bits 1-4 use variant form of numbers before thousands,millions,etc.
// bit6=(LANG=pl) two forms of plural, M or MA
// bit7=(LANG-ru) use MB for 1 thousand, million, etc
// bit8=(LANG=sw) special word for 100,000s
// bit8=(LANG=hi) special word for 100,000 and 10,000,000
// bit9=(LANG=rw) say "thousand" and "million" before its number, not after
// bit10=(LANG=sw) special word for 100,000 and 1,000,000
int numbers2;
int max_roman;