[1.31.19}

Fix: Events callback, fix word length information for words with multibyte characters.
Fix: Re-translating a word in a different language after the first langauge has started speaking individual letters, gave silence.
Announce punctuation.  If character name is not defined, use English.
Announce punctuation.  Fix pitch of the voice which announces punctuation characters.
[[Phonemes]] text input.  Allow the language-switch phoneme eg. [[_^_EN hEloU _^_FR]] in the input.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@152 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2008-02-28 20:54:03 +00:00
parent 16fba5a1c1
commit 417395b033
36 changed files with 630 additions and 347 deletions
+28 -9
View File
@@ -434,11 +434,18 @@ char *EncodePhonemes(char *p, char *outptr, unsigned char *bad_phoneme)
while(!isspace(c = *p++) && (c != 0))
*outptr++ = tolower(c);
*outptr = 0;
if(strcmp(p_lang,"en")==0)
if(c == 0)
{
*p_lang = 0; // don't need "en", it's assumed by default
if(strcmp(p_lang,"en")==0)
{
*p_lang = 0; // don't need "en", it's assumed by default
return(p);
}
}
else
{
*outptr++ = '|'; // more phonemes follow, terminate language string with separator
}
return(p);
}
break;
}
@@ -2302,10 +2309,10 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
while(((c = *p) != ' ') && (c != 0))
{
if(IsAlpha(wc))
any_alpha++;
wc_prev = wc;
wc_bytes = utf8_in(&wc,p,0);
if(IsAlpha(wc))
any_alpha++;
n = groups2_count[c];
if(IsDigit(wc) && ((langopts.tone_numbers == 0) || !any_alpha))
@@ -2424,11 +2431,23 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
if(match1.points == 0)
{
static const char str_unknown[4] = {phonCAPITAL,phonCAPITAL,phonCAPITAL,0};
if(((any_alpha > 0) || (p[wc_bytes-1] > ' ')) && !iswpunct(wc))
if(iswalpha(wc))
{
// an unrecognised character in a word, indicate with clicks
match1.phonemes = str_unknown;
match1.points = 1;
if((any_alpha > 1) || (p[wc_bytes-1] > ' '))
{
// an unrecognised character in a word, indicate with clicks
match1.phonemes = str_unknown;
match1.points = 1;
}
}
else
{
LookupLetter(wc, -1, ph_buf);
if(ph_buf[0])
{
match1.phonemes = ph_buf;
match1.points = 1;
}
}
p += (wc_bytes-1);
}
+37 -10
View File
@@ -45,6 +45,31 @@ void Translator::LookupLetter(unsigned int letter, int next_byte, char *ph_buf1)
char ph_stress[2];
char ph_buf3[30];
ph_buf1[0] = 0;
len = utf8_out(letter,&single_letter[2]);
single_letter[len+2] = ' ';
if(next_byte == -1)
{
// speaking normal text, not individual characters
if(Lookup(&single_letter[2],ph_buf1) != 0)
return;
single_letter[1] = '_';
if(Lookup(&single_letter[1],ph_buf3) != 0)
return; // the character is specified as _* so ignore it when speaking normal text
// check whether this character is specified for English
SetTranslator2("en");
if(translator2->Lookup(&single_letter[2], ph_buf3) != 0)
{
// yes, switch to English and re-translate the word
sprintf(ph_buf1,"%c",phonSWITCH);
}
SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
return;
}
if((letter <= 32) || iswspace(letter))
{
// lookup space as _&32 etc.
@@ -53,10 +78,6 @@ void Translator::LookupLetter(unsigned int letter, int next_byte, char *ph_buf1)
return;
}
len = utf8_out(letter,&single_letter[2]);
single_letter[len+2] = ' ';
if(next_byte != ' ')
next_byte = RULE_SPELLING;
single_letter[3+len] = next_byte; // follow by space-space if the end of the word, or space-0x31
@@ -91,8 +112,8 @@ void Translator::LookupLetter(unsigned int letter, int next_byte, char *ph_buf1)
int Translator::TranslateLetter(char *word, char *phonemes, int control)
{//=====================================================================
int Translator::TranslateLetter(char *word, char *phonemes, int control, int word_length)
{//======================================================================================
// get pronunciation for an isolated letter
// return number of bytes used by the letter
// control 2=say-as glyphs, 3-say-as chars
@@ -134,11 +155,17 @@ int Translator::TranslateLetter(char *word, char *phonemes, int control)
return(0);
}
if(ph_buf[0] == 0)
if((ph_buf[0] == 0) && (word_length == 1) && (translator_name != L('e','n')))
{
// ?? speak as English ??
sprintf(phonemes,"%c",phonSWITCH);
return(0);
// speak as English, check whether there is a translation for this character
SetTranslator2("en");
translator2->LookupLetter(letter, word[n_bytes], ph_buf);
SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
if(ph_buf[0] != 0)
{
sprintf(phonemes,"%c",phonSWITCH);
return(0);
}
}
if(ph_buf[0] == 0)
+111 -37
View File
@@ -63,11 +63,11 @@ static const char *punct_stop = ".:!?"; // pitch fall if followed by space
static const char *punct_close = ")]}>;'\""; // always pitch fall unless followed by alnum
// alter tone for announce punctuation or capitals
static const char *tone_punct_on = "\001+50R\001+10T"; // add reverberation, reduce low frequencies
static const char *tone_punct_off = "\001R\001T";
static const char *tone_punct_on = "\0016T"; // add reverberation, lower pitch
static const char *tone_punct_off = "\001T";
// punctuations symbols that can end a clause
static const unsigned short punct_chars[] = {',','.','?','!',':',';',
const unsigned short punct_chars[] = {',','.','?','!',':',';',
0x2013, // en-dash
0x2014, // em-dash
0x2026, // elipsis
@@ -477,22 +477,38 @@ static void UngetC(int c)
}
const char *WordToString2(unsigned int word)
{//========================================
// Convert a language mnemonic word into a string
int ix;
static char buf[5];
char *p;
const char *Translator::LookupSpecial(const char *string)
{//======================================================
p = buf;
for(ix=3; ix>=0; ix--)
{
if((*p = word >> (ix*8)) != 0)
p++;
}
*p = 0;
return(buf);
}
const char *Translator::LookupSpecial(const char *string, char* text_out)
{//======================================================================
unsigned int flags[2];
char phonemes[55];
char phonemes2[55];
static char buf[60];
char *string1 = (char *)string;
if(LookupDictList(&string1,phonemes,flags,0,NULL))
{
SetWordStress(phonemes,flags[0],-1,0);
DecodePhonemes(phonemes,phonemes2);
sprintf(buf,"[[%s]] ",phonemes2);
sprintf(text_out,"[[%s]]",phonemes2);
option_phoneme_input = 1;
return(buf);
return(text_out);
}
return(NULL);
}
@@ -503,26 +519,78 @@ const char *Translator::LookupCharName(int c)
// Find the phoneme string (in ascii) to speak the name of character c
int ix;
const char *p;
static char buf[24];
unsigned int flags[2];
char single_letter[24];
char phonemes[60];
char phonemes2[60];
char *lang_name = NULL;
char *string;
static char buf[60];
buf[0] = '_';
ix = utf8_out(c,&buf[1]);
buf[1+ix]=0;
buf[0] = 0;
flags[0] = 0;
flags[1] = 0;
single_letter[0] = 0;
single_letter[1] = '_';
ix = utf8_out(c,&single_letter[2]);
single_letter[2+ix]=0;
if((p = LookupSpecial(buf)) == NULL)
string = &single_letter[1];
if(LookupDictList(&string, phonemes, flags, 0, NULL) == 0)
{
p = LookupSpecial(&buf[1]);
// try _* then *
string = &single_letter[2];
if(LookupDictList(&string, phonemes, flags, 0, NULL) == 0)
{
// now try the rules
single_letter[1] = ' ';
TranslateRules(&single_letter[2], phonemes, sizeof(phonemes), NULL,0,0);
}
}
if(p != NULL)
return(p);
if((p = LookupSpecial("_??")) == NULL)
if((phonemes[0] == 0) && (translator_name != L('e','n')))
{
p = "symbol";
// not found, try English
SetTranslator2("en");
string = &single_letter[1];
single_letter[1] = '_';
if(translator2->LookupDictList(&string, phonemes, flags, 0, NULL) == 0)
{
string = &single_letter[2];
translator2->LookupDictList(&string, phonemes, flags, 0, NULL);
}
if(phonemes[0])
{
lang_name = "en";
}
else
{
SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
}
}
strcpy(buf,p);
// sprintf(buf,"%s%d ",p,c);
if(phonemes[0])
{
if(lang_name)
{
translator2->SetWordStress(phonemes,flags[0],-1,0);
DecodePhonemes(phonemes,phonemes2);
sprintf(buf,"[[_^_%s %s _^_%s]]","en",phonemes2,WordToString2(translator_name));
SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
}
else
{
SetWordStress(phonemes,flags[0],-1,0);
DecodePhonemes(phonemes,phonemes2);
sprintf(buf,"[[%s]] ",phonemes2);
}
}
else
{
strcpy(buf,"[[(X1)(X1)(X1)]]");
}
option_phoneme_input = 1;
return(buf);
}
@@ -714,7 +782,9 @@ int Translator::AnnouncePunctuation(int c1, int c2, char *buf, int bufix)
p = &buf[bufix];
if(punct_count==1)
{
sprintf(p,"%s %s %s",tone_punct_on,punctname,tone_punct_off);
}
else
if(punct_count < 4)
{
@@ -1769,8 +1839,8 @@ int Translator::ReadClause(FILE *f_in, char *buf, unsigned short *charix, int n_
const char *p;
wchar_t xml_buf[N_XML_BUF+1];
#define N_XML_BUF2 12
char buf2[N_XML_BUF2+2];
#define N_XML_BUF2 20
char xml_buf2[N_XML_BUF2+2]; // for &<name> and &<number> sequences
static char ungot_string[N_XML_BUF2+4];
static int ungot_string_ix = -1;
@@ -1859,26 +1929,26 @@ f_input = f_in; // for GetC etc
c1 = c2;
while(!Eof() && (iswalnum(c1) || (c1=='#')) && (n_xml_buf < N_XML_BUF2))
{
buf2[n_xml_buf++] = c1;
xml_buf2[n_xml_buf++] = c1;
c1 = GetC();
}
buf2[n_xml_buf] = 0;
xml_buf2[n_xml_buf] = 0;
c2 = GetC();
sprintf(ungot_string,"%s%c%c",&buf2[0],c1,c2);
sprintf(ungot_string,"%s%c%c",&xml_buf2[0],c1,c2);
if(c1 == ';')
{
if(buf2[0] == '#')
if(xml_buf2[0] == '#')
{
// character code number
if(buf2[1] == 'x')
found = sscanf(&buf2[2],"%x",(unsigned int *)(&c1));
if(xml_buf2[1] == 'x')
found = sscanf(&xml_buf2[2],"%x",(unsigned int *)(&c1));
else
found = sscanf(&buf2[1],"%d",&c1);
found = sscanf(&xml_buf2[1],"%d",&c1);
}
else
{
if((found = LookupMnem(xml_char_mnemonics,buf2)) != -1)
if((found = LookupMnem(xml_char_mnemonics,xml_buf2)) != -1)
{
c1 = found;
if(c2 == 0)
@@ -2050,14 +2120,15 @@ f_input = f_in; // for GetC etc
clause_upper_count++;
if((option_capitals == 2) && !iswupper(cprev))
{
p = LookupSpecial("_cap");
if(p != NULL)
char text_buf[40];
char text_buf2[30];
if(LookupSpecial("_cap",text_buf2) != NULL)
{
sprintf(buf2,"%s%s%s",tone_punct_on,p,tone_punct_off);
j = strlen(buf2);
sprintf(text_buf,"%s%s%s",tone_punct_on,text_buf2,tone_punct_off);
j = strlen(text_buf);
if((ix + j) < n_buf)
{
strcpy(&buf[ix],buf2);
strcpy(&buf[ix],text_buf);
ix += j;
}
}
@@ -2186,11 +2257,14 @@ if(option_ssml) parag=1;
if(speech_parameters[espeakSILENCE]==1)
continue;
j = ix+1;
ix += utf8_out(c1,&buf[ix]); // buf[ix++] = c1;
if(!iswspace(c1) && !IsBracket(c1))
{
charix[ix] = count_characters - clause_start_char;
while(j < ix)
charix[j++] = 0xffff; // subsequent bytes of a multibyte character
}
ix += utf8_out(c1,&buf[ix]); // buf[ix++] = c1;
if(((ix > (n_buf-20)) && !IsAlpha(c1) && !iswdigit(c1)) || (ix >= (n_buf-2)))
{
+1 -1
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.31.18 25.Feb.08";
const char *version_string = "1.31.19 28.Feb.08";
const int version_phdata = 0x013105;
int option_device_number = -1;
+2 -1
View File
@@ -51,7 +51,7 @@
#define EMBED_A 3 // amplitude/volume
#define EMBED_R 4 // pitch range/expression
#define EMBED_H 5 // echo/reverberation
#define EMBED_T 6 // different tone
#define EMBED_T 6 // different tone for announcing punctuation
#define EMBED_I 7 // sound icon
#define EMBED_S2 8 // speed (used in synthesize)
#define EMBED_Y 9 // say-as commands
@@ -274,5 +274,6 @@ int DoSample(PHONEME_TAB *ph1, PHONEME_TAB *ph2, int which, int length_mod, int
int DoSpect(PHONEME_TAB *this_ph, PHONEME_TAB *prev_ph, PHONEME_TAB *next_ph,
int which, PHONEME_LIST *plist, int modulation);
int PauseLength(int pause);
int LookupPhonemeTable(const char *name);
void InitBreath(void);
+1 -1
View File
@@ -111,7 +111,7 @@ int Translator_English::Unpronouncable(char *word)
if(c == '\'')
apostrophe = 1;
else
if((c < 'a') || (c > 0x241))
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)))
+67 -10
View File
@@ -752,7 +752,7 @@ if((wmark > 0) && (wmark < 8))
while(*wordx != ' ')
{
wordx += TranslateLetter(wordx, phonemes,spell_word);
wordx += TranslateLetter(wordx, phonemes,spell_word, word_length);
posn++;
if(phonemes[0] == phonSWITCH)
{
@@ -779,7 +779,7 @@ if((wmark > 0) && (wmark < 8))
// This word looks "unpronouncable", so speak letters individually until we
// find a remainder that we can pronounce.
emphasize_allcaps = 0;
wordx += TranslateLetter(wordx,phonemes,0);
wordx += TranslateLetter(wordx,phonemes,0, word_length);
posn++;
if(phonemes[0] == phonSWITCH)
{
@@ -825,12 +825,12 @@ if((wmark > 0) && (wmark < 8))
// characters not recognised, speak them individually
utf8_in(&wc, wordx, 0);
if(!iswpunct(wc))
if((word_length == 1) && IsAlpha(wc))
{
posn = 0;
while(*wordx != ' ')
{
wordx += TranslateLetter(wordx, phonemes, 4);
wordx += TranslateLetter(wordx, phonemes, 4, word_length);
posn++;
if(phonemes[0] == phonSWITCH)
{
@@ -1278,9 +1278,12 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
int first_phoneme = 1;
int source_ix;
int len;
int ix;
int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
const char *new_language;
unsigned char bad_phoneme[4];
int word_copy_len;
char word_copy[N_WORD_BYTES];
len = wtab->length;
if(len > 31) len = 31;
@@ -1355,11 +1358,42 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
if(word_flags & FLAG_PHONEMES)
{
// The input is in phoneme mnemonics, not language text
EncodePhonemes(word,word_phonemes,bad_phoneme);
int c1;
char lang_name[12];
if(memcmp(word,"_^_",3)==0)
{
// switch languages
word+=3;
for(ix=0;;)
{
c1 = *word++;
if((c1==' ') || (c1==0))
break;
lang_name[ix++] = tolower(c1);
}
lang_name[ix] = 0;
if((ix = LookupPhonemeTable(lang_name)) > 0)
{
SelectPhonemeTable(ix);
word_phonemes[0] = phonSWITCH;
word_phonemes[1] = ix;
word_phonemes[2] = 0;
}
}
else
{
EncodePhonemes(word,word_phonemes,bad_phoneme);
}
flags = FLAG_FOUND;
}
else
{
ix = 0;
while((word_copy[ix] = word[ix]) != ' ') ix++;
word_copy_len = ix;
flags = translator->TranslateWord(word, next_pause, wtab);
if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
@@ -1420,6 +1454,8 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
if(p[0] == phonSWITCH)
{
// this word uses a different language
memcpy(word, word_copy, word_copy_len);
new_language = (char *)(&p[1]);
if(new_language[0]==0)
new_language = "en";
@@ -1523,6 +1559,15 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
// Add the phonemes to the first stage phoneme list (ph_list2)
ph = phoneme_tab[ph_code];
if(ph_code == phonSWITCH)
{
ph_list2[n_ph_list2].phcode = ph_code;
ph_list2[n_ph_list2].sourceix = 0;
ph_list2[n_ph_list2].synthflags = embedded_flag;
ph_list2[n_ph_list2++].tone_number = *p++;
}
else
if(ph->type == phSTRESS)
{
// don't add stress phonemes codes to the list, but give their stress
@@ -1924,8 +1969,14 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
for(j=0; charix[j]==0; j++);
words[0].sourceix = charix[j];
for(k=j; charix[k]!=0; k++);
words[0].length = k-j;
k = 0;
while(charix[j] != 0)
{
// count the number of characters (excluding multibyte continuation bytes)
if(charix[j++] != 0xffff)
k++;
}
words[0].length = k;
while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
{
@@ -2327,10 +2378,16 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
words[word_count].start = ix;
words[word_count].flags = 0;
for(j=source_index; charix[j] == 0; j++);
for(j=source_index; charix[j] == 0; j++); // skip blanks
words[word_count].sourceix = charix[j];
for(k=j; charix[k]!=0; k++);
words[word_count].length = k-j;
k = 0;
while(charix[j] != 0)
{
// count the number of characters (excluding multibyte continuation bytes)
if(charix[j++] != 0xffff)
k++;
}
words[word_count].length = k;
word_flags = next_word_flags;
next_word_flags = 0;
+3 -2
View File
@@ -417,7 +417,7 @@ public:
private:
int TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int next_pause);
int TranslateLetter(char *letter, char *phonemes, int control);
int TranslateLetter(char *letter, char *phonemes, int control, int word_length);
void SetSpellingStress(char *phonemes, int control, int n_chars);
void WriteMnemonic(int *ix, int mnem);
void MakePhonemeList(int post_pause, int new_sentence);
@@ -427,7 +427,7 @@ private:
int AnnouncePunctuation(int c1, int c2, char *buf, int ix);
const char *LookupDict2(const char *word, const char *word2, char *phonetic, unsigned int *flags, int end_flags, WORD_TAB *wtab);
const char *LookupSpecial(const char *string);
const char *LookupSpecial(const char *string, char *text_out);
const char *LookupCharName(int c);
void LookupLetter(unsigned int letter, int next_byte, char *ph_buf);
int LookupNum2(int value, int control, char *ph_out);
@@ -539,6 +539,7 @@ extern char skip_marker[N_MARKER_LENGTH];
#define N_PUNCTLIST 60
extern wchar_t option_punctlist[N_PUNCTLIST]; // which punctuation characters to announce
extern unsigned char punctuation_to_tone[INTONATION_TYPES][PUNCT_INTONATIONS];
extern const unsigned short punct_chars[]; // punctuation chars fo end-of-clause
extern int speech_parameters[];
+11 -3
View File
@@ -144,7 +144,7 @@ int wcmdq_head=0;
int wcmdq_tail=0;
// pitch,speed,
int embedded_default[N_EMBEDDED_VALUES] = {0,50,170,100,50, 0,50, 0,170,0,0,0,0,0};
int embedded_default[N_EMBEDDED_VALUES] = {0,50,170,100,50, 0,0, 0,170,0,0,0,0,0};
static int embedded_max[N_EMBEDDED_VALUES] = {0,0x7fff,360,300,99,99,99, 0,360,0,0,0,0,4};
#define N_CALLBACK_IX N_WAV_BUF-2 // adjust this delay to match display with the currently spoken word
@@ -813,6 +813,12 @@ static void WavegenSetEcho(void)
amp = embedded_value[EMBED_H];
delay = 130;
}
if(embedded_value[EMBED_T] > 0)
{
// announcing punctuation
amp = embedded_value[EMBED_T] * 10;
delay = 130;
}
if(delay == 0)
amp = 0;
@@ -1517,8 +1523,9 @@ void SetEmbedded(int control, int value)
switch(command)
{
case EMBED_P:
case EMBED_T:
WavegenSetEcho(); // and drop through to case P
case EMBED_P:
// adjust formants to give better results for a different voice pitch
if((pitch_value = embedded_value[EMBED_P]) > MAX_PITCH_VALUE)
pitch_value = MAX_PITCH_VALUE;
@@ -1528,7 +1535,7 @@ void SetEmbedded(int control, int value)
{
wvoice->freq[ix] = (wvoice->freq2[ix] * factor)/256;
}
factor = (embedded_value[EMBED_T] - 50)*2;
factor = embedded_value[EMBED_T]*3;
wvoice->height[0] = (wvoice->height2[0] * (256 - factor*2))/256;
wvoice->height[1] = (wvoice->height2[1] * (256 - factor))/256;
break;
@@ -1623,6 +1630,7 @@ if(option_log_frames)
if((pitch_value = embedded_value[EMBED_P]) > MAX_PITCH_VALUE)
pitch_value = MAX_PITCH_VALUE;
pitch_value -= embedded_value[EMBED_T]; // adjust tone for announcing punctuation
if(pitch_value < 0)
pitch_value = 0;