[1.27.06] Roman number translation added (for some languages).

espeak_Char(32) can speak "space" by adding an entry for _#32 in *_list file. Similarly for Tab.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@61 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2007-07-07 15:37:48 +00:00
parent efbed31f77
commit f3a4623535
24 changed files with 1614 additions and 583 deletions
+78 -3
View File
@@ -51,13 +51,18 @@ int Translator::TranslateLetter(char *word, char *phonemes, int control)
char capital[20];
char ph_buf[30];
char ph_buf2[50];
static char single_letter[8] = {0};
static char single_letter[10] = {0,0};
ph_buf[0] = 0;
capital[0] = 0;
n_bytes = utf8_in(&letter,word,0);
if((letter & 0xfff00) == 0x0e000)
{
letter &= 0xff; // uncode private usage area
}
if(control > 2)
{
// include CAPITAL information
@@ -68,8 +73,17 @@ int Translator::TranslateLetter(char *word, char *phonemes, int control)
}
letter = towlower(letter);
if((letter <= 32) || iswspace(letter))
{
// lookup space as _&32 etc.
sprintf(&single_letter[1],"_#%d ",letter);
Lookup(&single_letter[1],ph_buf);
strcat(phonemes,ph_buf);
return(n_bytes);
}
len = utf8_out(letter,&single_letter[2]);
single_letter[2+len] = ' ';
single_letter[len+2] = ' ';
next = RULE_SPELLING;
if(word[n_bytes] == ' ')
@@ -186,6 +200,67 @@ void Translator::SetSpellingStress(char *phonemes, int control)
int Translator::TranslateRoman(char *word, char *ph_out)
{//=====================================================
int c;
char *p;
int acc;
int prev;
int value;
int subtract;
unsigned int flags;
char number_chars[N_WORD_BYTES];
static char *roman_numbers = "ixcmvld";
static int roman_values[] = {1,10,100,1000,5,50,500};
if((langopts.numbers & NUM_ROMAN) == 0)
return(0);
acc = 0;
prev = 0;
subtract = 0x7fff;
while((c = *word++) != ' ')
{
if((p = strchr(roman_numbers,c)) == NULL)
return(0);
value = roman_values[p - roman_numbers];
if((prev==5) || (prev==50) || (prev==500))
{
if(value >= prev)
return(0);
}
if((prev != 0) && (prev < value))
{
if(((acc % 10) != 0) || ((prev*10) < value))
return(0);
subtract = prev;
value -= subtract;
}
else
if(value >= subtract)
return(0);
else
acc += prev;
prev = value;
}
acc += prev;
if(acc < 2)
return(0);
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)];
sprintf(number_chars," %d ",acc);
TranslateNumber(&number_chars[1],p,&flags,0);
return(1);
} // end of TranslateRoman
int Translator::LookupNum2(int value, int control, char *ph_out)
@@ -589,7 +664,7 @@ int Translator::TranslateNumber_1(char *word, char *ph_out, unsigned int *flags,
{
if((thousandplex > 0) && (value < 1000))
{
if(langopts.numbers & 0x40000)
if(langopts.numbers2 & 0x100)
{
if((thousandplex == 1) && (value >= 100))
{
+4
View File
@@ -1546,6 +1546,10 @@ f_input = f_in; // for GetC etc
c1 = j;
}
}
if((sayas_mode == 0x14) && (c1 <= 0x20))
{
c1 += 0xe000; // move into unicode private usage area
}
}
else
if(c1 == '<')
+1 -1
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.27.05 05.Jul.07";
const char *version_string = "1.27.06 07.Jul.07";
const int version_phdata = 0x012701;
int option_device_number = -1;
+1 -2
View File
@@ -44,8 +44,7 @@ Translator_English::Translator_English() : Translator()
langopts.stress_rule = 0;
langopts.word_gap = 0;
langopts.numbers = 0x41;
langopts.numbers = 0x41 + NUM_ROMAN;
}
+14 -10
View File
@@ -122,7 +122,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_PREFIXES] = 1;
memcpy(tr->stress_lengths,stress_lengths_de,sizeof(tr->stress_lengths));
tr->langopts.numbers = 0x11c19;
tr->langopts.numbers = 0x11c19 + NUM_ROMAN;
SetLetterVowel(tr,'y');
}
break;
@@ -213,7 +213,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 = 0x529;
tr->langopts.numbers = 0x529 + NUM_ROMAN;
}
break;
@@ -271,7 +271,8 @@ Translator *SelectTranslator(const char *name)
tr->langopts.stress_rule = 6; // stress on last heaviest syllable
tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
tr->langopts.numbers = 0x811 + 0x40000;
tr->langopts.numbers = 0x811;
tr->langopts.numbers2 = 0x100;
tr->letter_bits_offset = OFFSET_DEVANAGARI;
tr->langopts.replace_chars = replace_chars_hi;
tr->langopts.replacement_chars = replacement_chars_hi;
@@ -302,7 +303,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.max_initial_consonants = 5;
tr->langopts.spelling_stress = 1;
tr->langopts.numbers = 0x1c0d + 0x4000;
tr->langopts.numbers = 0x1c0d + 0x4000 + NUM_ROMAN;
tr->langopts.numbers2 = 0x4a; // variant numbers before thousands,milliards
tr->langopts.replace_chars = replace_cyrillic;
tr->langopts.replacement_chars = replace_cyrillic_latin;
@@ -336,7 +337,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_COMBINE_WORDS] = 99; // combine some prepositions with the following word
tr->langopts.long_stop = 130;
tr->langopts.numbers = 0x1809;
tr->langopts.numbers = 0x1809 + NUM_ROMAN;
SetLetterVowel(tr,'y');
tr->langopts.spelling_stress = 1;
//SetLengthMods(tr,3); // all equal
@@ -384,7 +385,7 @@ Translator *SelectTranslator(const char *name)
tr->langopts.param[LOPT_IT_DOUBLING] = 2; // double the first consonant if the previous word ends in a stressed vowel
tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
tr->langopts.param[LOPT_REDUCE] = 1; // reduce vowels even if phonemes are specified in it_list
tr->langopts.numbers = 0x2709 + 0x800;
tr->langopts.numbers = 0x2709 + 0x800 + NUM_ROMAN;
}
break;
@@ -397,6 +398,8 @@ Translator *SelectTranslator(const char *name)
tr->langopts.unstressed_wd1 = 0;
tr->langopts.unstressed_wd2 = 2;
tr->langopts.param[LOPT_DIERESES] = 1;
tr->langopts.numbers = 0x1 + NUM_ROMAN;
tr->langopts.max_roman = 5000;
}
break;
@@ -483,7 +486,7 @@ Translator *SelectTranslator(const char *name)
// tr->langopts.vowel_pause = 1;
tr->langopts.stress_rule = 3; // stress on final syllable
tr->langopts.stress_flags = 0x6 | 0x10 | 0x20000;
tr->langopts.numbers = 0xa69 + 0x2000;
tr->langopts.numbers = 0xa69 + 0x2000 + NUM_ROMAN;
tr->punct_to_tone[0][3] = 2; // use exclamation intonation
SetLetterVowel(tr,'y');
}
@@ -505,7 +508,7 @@ Translator *SelectTranslator(const char *name)
tr->charset_a0 = charsets[2]; // ISO-8859-2
tr->langopts.replace_chars = replace_chars_ro;
tr->langopts.replacement_chars = replacement_chars_ro;
tr->langopts.numbers = 0x1829+0x6000;
tr->langopts.numbers = 0x1829+0x6000 + NUM_ROMAN;
tr->langopts.numbers2 = 0x1e; // variant numbers before all thousandplex
}
break;
@@ -576,7 +579,8 @@ Translator *SelectTranslator(const char *name)
tr->langopts.stress_rule = 2;
tr->langopts.stress_flags = 0x6 | 0x10;
tr->langopts.numbers = 0x408e1;
tr->langopts.numbers = 0x8e1;
tr->langopts.numbers2 = 0x100;
}
break;
@@ -942,7 +946,7 @@ Translator_Afrikaans::Translator_Afrikaans() : Translator()
langopts.param[LOPT_PREFIXES] = 1;
SetLetterVowel(this,'y'); // add 'y' to vowels
langopts.numbers = 0x0d1;
langopts.numbers = 0x0d1 + NUM_ROMAN;
memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
}
+14 -3
View File
@@ -438,6 +438,7 @@ Translator::Translator()
langopts.length_mods0 = length_mods_en0;
langopts.long_stop = 100;
langopts.max_roman = 49;
langopts.thousands_sep = ',';
langopts.decimal_sep = '.';
@@ -667,7 +668,13 @@ if((wmark > 0) && (wmark < 8))
found = TranslateNumber(word,phonemes,&dictionary_flags,wflags);
}
if((wflags & FLAG_ALL_UPPER) && (clause_upper_count <= clause_lower_count) &&
if(!found & ((word_flags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
{
// either all upper or all lower case
found = TranslateRoman(word,phonemes);
}
if(!found && (wflags & FLAG_ALL_UPPER) && (clause_upper_count <= clause_lower_count) &&
!(dictionary_flags & (FLAG_ABBREV | FLAG_SKIPWORDS)) && (word_length>1) && (word_length<4) && iswalpha(first_char))
{
// An upper case word in a lower case clause. This could be an abbreviation.
@@ -1635,6 +1642,7 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
int phoneme_mode = 0;
int dict_flags; // returned from dictionary lookup
int word_flags; // set here
int next_word_flags;
int embedded_count = 0;
int letter_count = 0;
char *word;
@@ -1715,6 +1723,7 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
word_count = 0;
single_quoted = 0;
word_flags = 0;
next_word_flags = 0;
expect_verb=0;
expect_past=0;
expect_verb_s=0;
@@ -1827,7 +1836,7 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
}
}
else
if((option_sayas2 & 0xf0) != 1)
if((option_sayas2 & 0xf0) != 0x10)
{
if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out))
{
@@ -1937,6 +1946,7 @@ if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out)
c = ' '; // change from upper to lower case, start new word at the last uppercase
prev_in2 = c;
source_index = prev_source_index; // unget
next_word_flags |= FLAG_NOSPACE;
}
//#endif
}
@@ -2116,7 +2126,8 @@ if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out)
for(k=j; charix[k]!=0; k++);
words[word_count].length = k-j;
word_flags = 0;
word_flags = next_word_flags;
next_word_flags = 0;
pre_pause = 0;
word_mark = 0;
all_upper_case = FLAG_ALL_UPPER;
+7 -2
View File
@@ -69,12 +69,14 @@
// wordflags, flags in source word
#define FLAG_ALL_UPPER 0x1 /* no lower case letters in the word */
#define FLAG_FIRST_UPPER 0x2 /* first letter is upper case */
#define FLAG_UPPERS 0x3 // FLAG_ALL_UPPER | FLAG_FIRST_UPPER
#define FLAG_HAS_PLURAL 0x4 /* upper-case word with s or 's lower-case ending */
#define FLAG_PHONEMES 0x8 /* word is phonemes */
#define FLAG_LAST_WORD 0x10 /* last word in clause */
#define FLAG_STRESSED_WORD 0x20 /* this word has explicit stress */
#define FLAG_EMBEDDED 0x40 /* word is preceded by embedded commands */
#define FLAG_HYPHEN 0x80
#define FLAG_NOSPACE 0x100 // word is not seperated from previous word by a space
#define FLAG_DONT_SWITCH_TRANSLATOR 0x1000
#define FLAG_SUFFIX_REMOVED 0x2000
#define FLAG_HYPHEN_AFTER 0x4000
@@ -275,6 +277,7 @@ typedef struct {
unsigned char *length_mods;
unsigned char *length_mods0;
#define NUM_ROMAN 0x20000
// bits0-1=which numbers routine to use.
// bit2= thousands separator must be space
// bit3= , decimal separator, not .
@@ -289,15 +292,16 @@ typedef struct {
// bit12=allow space as thousands separator (in addition to langopts.thousands_sep)
// bits13-15 post-decimal-digits 0=single digits, 1=(LANG=it) 2=(LANG=pl) 3=(LANG=ro)
// bit16=dot after number indicates ordinal
// bit18=special word for 100,000s LANG=sw
// bit17=recognize roman numbers
int numbers;
// 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
int numbers2;
int max_roman;
int thousands_sep;
int decimal_sep;
int intonation; // 1=tone language
@@ -388,6 +392,7 @@ private:
int LookupNum3(int value, char *ph_out, int suppress_null, int thousandplex, int prev_thousands);
int LookupThousands(int value, int thousandplex, char *ph_out);
int TranslateNumber_1(char *word1, char *ph_out, unsigned int *flags, int wflags);
int TranslateRoman(char *word, char *ph_out);
void InitGroups(void);
void AppendPhonemes(char *string, int size, const char *ph);