mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-26 21:14:27 +00:00
[1.32]
Fix: espeak --stdout, set a (large) data size. espeak --voices. Include mbrola voices only if a language is specified. git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@156 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
+18
-2
@@ -183,6 +183,7 @@ int compile_line(char *linebuf, char *dict_line, int *hash)
|
||||
int len_word;
|
||||
int len_phonetic;
|
||||
int text_not_phonemes; // this word specifies replacement text, not phonemes
|
||||
unsigned int wc;
|
||||
|
||||
char *mnemptr;
|
||||
char *comment;
|
||||
@@ -415,6 +416,13 @@ static char nullstring[] = {0};
|
||||
}
|
||||
}
|
||||
|
||||
if(sscanf(word,"U+%x",&wc) == 1)
|
||||
{
|
||||
// Character code
|
||||
ix = utf8_out(wc, word);
|
||||
word[ix] = 0;
|
||||
}
|
||||
else
|
||||
if((word[0] & 0x80)==0) // 7 bit ascii only
|
||||
{
|
||||
// If first letter is uppercase, convert to lower case. (Only if it's 7bit ascii)
|
||||
@@ -1515,8 +1523,16 @@ int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, cha
|
||||
|
||||
fprintf(f_log,"Using phonemetable: '%s'\n",PhonemeTabName());
|
||||
compile_dictlist_file(path,"roots");
|
||||
compile_dictlist_file(path,"list");
|
||||
compile_dictlist_file(path,"listx");
|
||||
if(translator->langopts.listx)
|
||||
{
|
||||
compile_dictlist_file(path,"list");
|
||||
compile_dictlist_file(path,"listx");
|
||||
}
|
||||
else
|
||||
{
|
||||
compile_dictlist_file(path,"listx");
|
||||
compile_dictlist_file(path,"list");
|
||||
}
|
||||
compile_dictlist_file(path,"extra");
|
||||
|
||||
compile_dictlist_end(f_out);
|
||||
|
||||
+57
-28
@@ -40,6 +40,7 @@ int dictionary_skipwords;
|
||||
char dictionary_name[40];
|
||||
|
||||
extern MNEM_TAB mnem_flags[];
|
||||
extern PHONEME_TAB_LIST phoneme_tab_list[N_PHONEME_TABS];
|
||||
|
||||
// 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};
|
||||
@@ -488,6 +489,13 @@ void DecodePhonemes(const char *inptr, char *outptr)
|
||||
*outptr++ = c;
|
||||
mnem = mnem >> 8;
|
||||
}
|
||||
if(phcode == phonSWITCH)
|
||||
{
|
||||
while(isalpha(*inptr))
|
||||
{
|
||||
*outptr++ = *inptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*outptr = 0; /* string terminator */
|
||||
@@ -519,6 +527,7 @@ void Translator::GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
|
||||
int ix;
|
||||
int phon_out_ix=0;
|
||||
int stress;
|
||||
char *p;
|
||||
PHONEME_LIST *plist;
|
||||
|
||||
static const char *stress_chars = "==,,''";
|
||||
@@ -550,6 +559,17 @@ void Translator::GetTranslatedPhonemeString(char *phon_out, int n_phon_out)
|
||||
// syllablic consonant
|
||||
WriteMnemonic(&phon_out_ix,phoneme_tab[phonSYLLABIC]->mnemonic);
|
||||
}
|
||||
if(plist->ph->code == phonSWITCH)
|
||||
{
|
||||
// the tone_ph field contains a phoneme table number
|
||||
p = phoneme_tab_list[plist->tone_ph].name;
|
||||
while(*p != 0)
|
||||
{
|
||||
phon_out[phon_out_ix++] = *p++;
|
||||
}
|
||||
phon_out[phon_out_ix++] = ' ';
|
||||
}
|
||||
else
|
||||
if(plist->tone_ph > 0)
|
||||
{
|
||||
WriteMnemonic(&phon_out_ix,phoneme_tab[plist->tone_ph]->mnemonic);
|
||||
@@ -2244,8 +2264,8 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
|
||||
|
||||
|
||||
int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char *end_phonemes, int word_flags, int dict_flags)
|
||||
{//===========================================================================================================================
|
||||
int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char *end_phonemes, int word_flags, unsigned int *dict_flags)
|
||||
{//=====================================================================================================================================
|
||||
/* Translate a word bounded by space characters
|
||||
Append the result to 'phonemes' and any standard prefix/suffix in 'end_phonemes' */
|
||||
|
||||
@@ -2262,8 +2282,9 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
int letter;
|
||||
int any_alpha=0;
|
||||
int ix;
|
||||
int digit_count=0;
|
||||
unsigned int digit_count=0;
|
||||
char *p;
|
||||
int dict_flags0=0;
|
||||
MatchRecord match1;
|
||||
MatchRecord match2;
|
||||
char ph_buf[40];
|
||||
@@ -2275,6 +2296,9 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
if(data_dictrules == NULL)
|
||||
return(0);
|
||||
|
||||
if(dict_flags != NULL)
|
||||
dict_flags0 = dict_flags[0];
|
||||
|
||||
for(ix=0; ix<(N_WORD_BYTES-1);)
|
||||
{
|
||||
c = p_start[ix];
|
||||
@@ -2359,13 +2383,13 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
group_name[1] = c2;
|
||||
group_name[2] = 0;
|
||||
p2 = p;
|
||||
MatchRule(&p2, group_name, groups2[g], &match2, word_flags, dict_flags);
|
||||
MatchRule(&p2, group_name, groups2[g], &match2, word_flags, dict_flags0);
|
||||
if(match2.points > 0)
|
||||
match2.points += 35; /* to acount for 2 letters matching */
|
||||
|
||||
/* now see whether single letter chain gives a better match ? */
|
||||
group_name[1] = 0;
|
||||
MatchRule(&p, group_name, groups1[c], &match1, word_flags, dict_flags);
|
||||
MatchRule(&p, group_name, groups1[c], &match1, word_flags, dict_flags0);
|
||||
|
||||
if(match2.points >= match1.points)
|
||||
{
|
||||
@@ -2384,11 +2408,11 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
group_name[1] = 0;
|
||||
|
||||
if(groups1[c] != NULL)
|
||||
MatchRule(&p, group_name, groups1[c], &match1, word_flags, dict_flags);
|
||||
MatchRule(&p, group_name, groups1[c], &match1, word_flags, dict_flags0);
|
||||
else
|
||||
{
|
||||
// no group for this letter, use default group
|
||||
MatchRule(&p, "", groups1[0], &match1, word_flags, dict_flags);
|
||||
MatchRule(&p, "", groups1[0], &match1, word_flags, dict_flags0);
|
||||
|
||||
if((match1.points == 0) && ((option_sayas & 0x10) == 0))
|
||||
{
|
||||
@@ -2397,23 +2421,27 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
if((letter >= 0xc0) && (letter <= 0x241) && ((ix = remove_accent[letter-0xc0]) != 0))
|
||||
{
|
||||
// within range of the remove_accent table
|
||||
p2 = p-1;
|
||||
p[-1] = ix;
|
||||
while((p[0] = p[n]) != ' ') p++;
|
||||
while(n-- > 0) *p++ = ' '; // replacement character must be no longer than original
|
||||
|
||||
if(langopts.param[LOPT_DIERESES] && (lookupwchar(diereses_list,letter) > 0))
|
||||
if((p[-2] != ' ') || (p[n] != ' '))
|
||||
{
|
||||
// vowel with dieresis, replace and continue from this point
|
||||
p = p2;
|
||||
continue;
|
||||
// not the only letter in the word
|
||||
p2 = p-1;
|
||||
p[-1] = ix;
|
||||
while((p[0] = p[n]) != ' ') p++;
|
||||
while(n-- > 0) *p++ = ' '; // replacement character must be no longer than original
|
||||
|
||||
if(langopts.param[LOPT_DIERESES] && (lookupwchar(diereses_list,letter) > 0))
|
||||
{
|
||||
// vowel with dieresis, replace and continue from this point
|
||||
p = p2;
|
||||
continue;
|
||||
}
|
||||
|
||||
phonemes[0] = 0; // delete any phonemes which have been produced so far
|
||||
p = p_start;
|
||||
word_vowel_count = 0;
|
||||
word_stressed_count = 0;
|
||||
continue; // start again at the beginning of the word
|
||||
}
|
||||
|
||||
phonemes[0] = 0; // delete any phonemes which have been produced so far
|
||||
p = p_start;
|
||||
word_vowel_count = 0;
|
||||
word_stressed_count = 0;
|
||||
continue; // start again at the beginning of the word
|
||||
}
|
||||
else
|
||||
if((letter >= 0x3200) && (letter < 0xa700) && (end_phonemes != NULL))
|
||||
@@ -2430,14 +2458,15 @@ 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(iswalpha(wc))
|
||||
if(IsAlpha(wc))
|
||||
{
|
||||
if((any_alpha > 1) || (p[wc_bytes-1] > ' '))
|
||||
{
|
||||
// an unrecognised character in a word, indicate with clicks
|
||||
match1.phonemes = str_unknown;
|
||||
match1.points = 1;
|
||||
// an unrecognised character in a word, abort and then spell the word
|
||||
phonemes[0] = 0;
|
||||
if(dict_flags != NULL)
|
||||
dict_flags[0] |= FLAG_SPELLWORD;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2492,7 +2521,7 @@ int Translator::TranslateRules(char *p_start, char *phonemes, int ph_size, char
|
||||
}
|
||||
|
||||
// any language specific changes ?
|
||||
ApplySpecialAttribute(phonemes,dict_flags);
|
||||
ApplySpecialAttribute(phonemes,dict_flags0);
|
||||
memcpy(p_start,word_copy,strlen(word_copy));
|
||||
return(0);
|
||||
} /* end of TranslateRules */
|
||||
|
||||
+5
-3
@@ -65,6 +65,8 @@ static const char *help_text =
|
||||
"--punct=\"<characters>\"\n"
|
||||
"\t Speak the names of punctuation characters during speaking. If\n"
|
||||
"\t =<characters> is omitted, all punctuation is spoken.\n"
|
||||
"--split=\"<minutes>\"\n"
|
||||
"\t Starts a new WAV file every <minutes>. Used with -w\n"
|
||||
"--voices=<langauge>\n"
|
||||
"\t List the available voices for the specified language.\n"
|
||||
"\t If <language> is omitted, then list all voices.\n"
|
||||
@@ -196,8 +198,8 @@ int OpenWavFile(char *path, int rate)
|
||||
{
|
||||
static unsigned char wave_hdr[44] = {
|
||||
'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',
|
||||
0x10,0,0,0,1,0,1,0, 0,0,0,0, 0,0,0,0,
|
||||
2,0,0x10,0,'d','a','t','a', 0,0,0,0 };
|
||||
0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0,
|
||||
2,0,0x10,0,'d','a','t','a', 0xff,0xff,0xff,0x7f};
|
||||
|
||||
if(path == NULL)
|
||||
return(2);
|
||||
@@ -215,7 +217,7 @@ int OpenWavFile(char *path, int rate)
|
||||
fwrite(wave_hdr,1,24,f_wavfile);
|
||||
Write4Bytes(f_wavfile,rate);
|
||||
Write4Bytes(f_wavfile,rate * 2);
|
||||
fwrite(&wave_hdr[32],1,8,f_wavfile);
|
||||
fwrite(&wave_hdr[32],1,12,f_wavfile);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
|
||||
+2
-2
@@ -216,8 +216,8 @@ static int drops_0[8] = {0x400,0x400,0x700,0x700,0x700,0xa00,0x1800,0x0e00};
|
||||
static short oflow[] = {0, 20, 12, 4, 0};
|
||||
static short oflow_emf[] = {5, 24, 15, 10, 5};
|
||||
static short oflow_less[] = {3, 19, 12, 7, 2};
|
||||
static short oflow_test2[] = {20, 0, 20, 0, 20};
|
||||
static short back_emf[] = {35, 32, 0};
|
||||
// static short oflow_test2[] = {20, 0, 20, 0, 20};
|
||||
// static short back_emf[] = {35, 32, 0};
|
||||
|
||||
|
||||
#define N_TONE_HEAD_TABLE 13
|
||||
|
||||
+218
-48
@@ -37,22 +37,33 @@
|
||||
|
||||
|
||||
#define M_NAME 0
|
||||
#define M_ACUTE 1
|
||||
#define M_BREVE 2
|
||||
#define M_CARON 3
|
||||
#define M_CEDILLA 4
|
||||
#define M_CIRCUMFLEX 5
|
||||
#define M_DIAERESIS 6
|
||||
#define M_DOUBLE_ACUTE 7
|
||||
#define M_DOT_ABOVE 8
|
||||
#define M_GRAVE 9
|
||||
#define M_MACRON 10
|
||||
#define M_OGONEK 11
|
||||
#define M_RING 12
|
||||
#define M_STROKE 13
|
||||
#define M_TILDE 14
|
||||
#define M_SMALLCAP 1
|
||||
#define M_TURNED 2
|
||||
#define M_REVERSED 3
|
||||
#define M_CURL 4
|
||||
|
||||
#define M_MIDDLE_DOT 8 // duplicate of M_DOT_ABOVE
|
||||
#define M_ACUTE 5
|
||||
#define M_BREVE 6
|
||||
#define M_CARON 7
|
||||
#define M_CEDILLA 8
|
||||
#define M_CIRCUMFLEX 9
|
||||
#define M_DIAERESIS 10
|
||||
#define M_DOUBLE_ACUTE 11
|
||||
#define M_DOT_ABOVE 12
|
||||
#define M_GRAVE 13
|
||||
#define M_MACRON 14
|
||||
#define M_OGONEK 15
|
||||
#define M_RING 16
|
||||
#define M_STROKE 17
|
||||
#define M_TILDE 18
|
||||
|
||||
#define M_BAR 19
|
||||
#define M_RETROFLEX 20
|
||||
#define M_HOOK 21
|
||||
|
||||
|
||||
#define M_MIDDLE_DOT M_DOT_ABOVE // duplicate of M_DOT_ABOVE
|
||||
#define M_IMPLOSIVE M_HOOK
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
@@ -62,6 +73,11 @@ int flags;
|
||||
// these are tokens to look up in the *_list file.
|
||||
ACCENTS accents_tab[] = {
|
||||
{"_lig", 1},
|
||||
{"_smc", 1}, // smallcap
|
||||
{"_tur", 1}, // turned
|
||||
{"_rev", 1}, // reversed
|
||||
{"_crl", 0}, // curl
|
||||
|
||||
{"_acu", 0}, // acute
|
||||
{"_brv", 0}, // breve
|
||||
{"_hac", 0}, // caron/hacek
|
||||
@@ -76,12 +92,38 @@ ACCENTS accents_tab[] = {
|
||||
{"_rng", 0}, // ring
|
||||
{"_stk", 0}, // stroke
|
||||
{"_tld", 0}, // tilde
|
||||
|
||||
{"_bar", 0}, // bar
|
||||
{"_rfx", 0}, // retroflex
|
||||
{"_hok", 0}, // hook
|
||||
};
|
||||
|
||||
|
||||
#define CAPITAL 0
|
||||
#define LETTER(ch,mod1,mod2) ch+(mod1 << 8)
|
||||
#define LIGATURE(ch1,ch2,mod1) ch1+(ch2 << 8)+0x8000
|
||||
#define LETTER(ch,mod1,mod2) (ch-59)+(mod1 << 6)+(mod2 << 11)
|
||||
#define LIGATURE(ch1,ch2,mod1) (ch1-59)+((ch2-59) << 6)+(mod1 << 12)+0x8000
|
||||
|
||||
|
||||
#define L_ALPHA 60 // U+3B1
|
||||
#define L_SCHWA 61 // U+259
|
||||
#define L_OPEN_E 62 // U+25B
|
||||
#define L_GAMMA 63 // U+3B3
|
||||
#define L_IOTA 64 // U+3B9
|
||||
#define L_OE 65 // U+153
|
||||
#define L_OMEGA 66 // U+3C9
|
||||
|
||||
#define L_PHI 67 // U+3C6
|
||||
#define L_ESH 68 // U+283
|
||||
#define L_UPSILON 69 // U+3C5
|
||||
#define L_EZH 70 // U+292
|
||||
#define L_GLOTTAL 71 // U+294
|
||||
#define L_RTAP 72 // U+27E
|
||||
|
||||
|
||||
static const short non_ascii_tab[] = {
|
||||
0, 0x3b1, 0x259, 0x25b, 0x3b3, 0x3b9, 0x153, 0x3c9,
|
||||
0x3c6, 0x283, 0x3c5, 0x292, 0x294, 0x27e };
|
||||
|
||||
|
||||
// characters U+00e0 to U+017f
|
||||
const short letter_accents_0e0[] = {
|
||||
@@ -179,11 +221,11 @@ LETTER('l',M_ACUTE,0),
|
||||
CAPITAL,
|
||||
LETTER('l',M_CEDILLA,0),
|
||||
CAPITAL,
|
||||
LETTER('1',M_CARON,0),
|
||||
LETTER('l',M_CARON,0),
|
||||
CAPITAL,
|
||||
LETTER('1',M_MIDDLE_DOT,0), // U+0140
|
||||
LETTER('l',M_MIDDLE_DOT,0), // U+0140
|
||||
CAPITAL,
|
||||
LETTER('1',M_STROKE,0),
|
||||
LETTER('l',M_STROKE,0),
|
||||
CAPITAL,
|
||||
LETTER('n',M_ACUTE,0),
|
||||
CAPITAL,
|
||||
@@ -248,6 +290,98 @@ LETTER('s',M_NAME,0), // long-s // U+17f
|
||||
};
|
||||
|
||||
|
||||
// characters U+0250 to U+029F
|
||||
const short letter_accents_250[] = {
|
||||
LETTER('a',M_TURNED,0), // U+250
|
||||
LETTER(L_ALPHA,0,0),
|
||||
LETTER(L_ALPHA,M_TURNED,0),
|
||||
LETTER('b',M_IMPLOSIVE,0),
|
||||
0, // open-o
|
||||
LETTER('c',M_CURL,0),
|
||||
LETTER('d',M_RETROFLEX,0),
|
||||
LETTER('d',M_IMPLOSIVE,0),
|
||||
LETTER('e',M_REVERSED,0), // U+258
|
||||
0, // schwa
|
||||
LETTER(L_SCHWA,M_HOOK,0),
|
||||
0, // open-e
|
||||
LETTER(L_OPEN_E,M_REVERSED,0),
|
||||
LETTER(L_OPEN_E,M_HOOK,M_REVERSED),
|
||||
0,//LETTER(L_OPEN_E,M_CLOSED,M_REVERSED),
|
||||
LETTER('j',M_BAR,0),
|
||||
LETTER('g',M_IMPLOSIVE,0), // U+260
|
||||
LETTER('g',0,0),
|
||||
LETTER('g',M_SMALLCAP,0),
|
||||
LETTER(L_GAMMA,0,0),
|
||||
0, // ramshorn
|
||||
LETTER('h',M_TURNED,0),
|
||||
LETTER('h',M_HOOK,0),
|
||||
0,//LETTER(L_HENG,M_HOOK,0),
|
||||
LETTER('i',M_BAR,0), // U+268
|
||||
LETTER(L_IOTA,0,0),
|
||||
LETTER('i',M_SMALLCAP,0),
|
||||
LETTER('l',M_TILDE,0),
|
||||
LETTER('l',M_BAR,0),
|
||||
LETTER('l',M_RETROFLEX,0),
|
||||
LIGATURE('l','z',0),
|
||||
LETTER('m',M_TURNED,0),
|
||||
0,//LETTER('m',M_TURNED,M_LEG), // U+270
|
||||
LETTER('m',M_HOOK,0),
|
||||
0,//LETTER('n',M_LEFTHOOK,0),
|
||||
LETTER('n',M_RETROFLEX,0),
|
||||
LETTER('n',M_SMALLCAP,0),
|
||||
LETTER('o',M_BAR,0),
|
||||
LIGATURE('o','e',M_SMALLCAP),
|
||||
0,//LETTER(L_OMEGA,M_CLOSED,0),
|
||||
LETTER(L_PHI,0,0), // U+278
|
||||
LETTER('r',M_TURNED,0),
|
||||
0,//LETTER('r',M_TURNED,M_LEG),
|
||||
LETTER('r',M_RETROFLEX,M_TURNED),
|
||||
0,//LETTER('r',M_LEG,0),
|
||||
LETTER('r',M_RETROFLEX,0),
|
||||
0, // r-tap
|
||||
LETTER(L_RTAP,M_REVERSED,0),
|
||||
LETTER('r',M_SMALLCAP,0), // U+280
|
||||
LETTER('r',M_TURNED,M_SMALLCAP),
|
||||
LETTER('s',M_RETROFLEX,0),
|
||||
0, // esh
|
||||
0,//LETTER('j',M_BAR,L_IMPLOSIVE),
|
||||
LETTER(L_ESH,M_REVERSED,0),
|
||||
LETTER(L_ESH,M_CURL,0),
|
||||
LETTER('t',M_TURNED,0),
|
||||
LETTER('t',M_RETROFLEX,0), // U+288
|
||||
LETTER('u',M_BAR,0),
|
||||
LETTER(L_UPSILON,0,0),
|
||||
LETTER('v',M_HOOK,0),
|
||||
LETTER('v',M_TURNED,0),
|
||||
LETTER('w',M_TURNED,0),
|
||||
LETTER('y',M_TURNED,0),
|
||||
LETTER('y',M_SMALLCAP,0),
|
||||
LETTER('z',M_RETROFLEX,0), // U+290
|
||||
LETTER('z',M_CURL,0),
|
||||
0, // ezh
|
||||
LETTER(L_EZH,M_CURL,0),
|
||||
0, // glottal stop
|
||||
LETTER(L_GLOTTAL,M_REVERSED,0),
|
||||
LETTER(L_GLOTTAL,M_TURNED,0),
|
||||
0,//LETTER('c',M_LONG,0),
|
||||
0, // bilabial click // U+298
|
||||
LETTER('b',M_SMALLCAP,0),
|
||||
0,//LETTER(L_OPEN_E,M_CLOSED,0),
|
||||
LETTER('g',M_IMPLOSIVE,M_SMALLCAP),
|
||||
LETTER('h',M_SMALLCAP,0),
|
||||
LETTER('j',M_CURL,0),
|
||||
LETTER('k',M_TURNED,0),
|
||||
LETTER('l',M_SMALLCAP,0),
|
||||
LETTER('q',M_HOOK,0), // U+2a0
|
||||
LETTER(L_GLOTTAL,M_STROKE,0),
|
||||
LETTER(L_GLOTTAL,M_STROKE,M_REVERSED),
|
||||
LIGATURE('d','z',0),
|
||||
0, // dezh
|
||||
LIGATURE('d','z',M_CURL),
|
||||
LIGATURE('t','s',0),
|
||||
0, // tesh
|
||||
LIGATURE('t','s',M_CURL),
|
||||
};
|
||||
|
||||
int Translator::LookupLetter2(unsigned int letter, char *ph_buf)
|
||||
{//=============================================================
|
||||
@@ -257,14 +391,15 @@ int Translator::LookupLetter2(unsigned int letter, char *ph_buf)
|
||||
single_letter[0] = 0;
|
||||
single_letter[1] = '_';
|
||||
len = utf8_out(letter, &single_letter[2]);
|
||||
single_letter[2+len] = 0;
|
||||
single_letter[len+2] = ' ';
|
||||
single_letter[len+3] = 0;
|
||||
|
||||
if(Lookup(&single_letter[1],ph_buf) == 0)
|
||||
{
|
||||
single_letter[1] = ' ';
|
||||
if(Lookup(&single_letter[2],ph_buf) == 0)
|
||||
{
|
||||
TranslateRules(&single_letter[2], ph_buf, 20, NULL,0,0);
|
||||
TranslateRules(&single_letter[2], ph_buf, 20, NULL,0,NULL);
|
||||
}
|
||||
}
|
||||
return(ph_buf[0]);
|
||||
@@ -274,45 +409,79 @@ int Translator::LookupLetter2(unsigned int letter, char *ph_buf)
|
||||
void Translator::LookupAccentedLetter(unsigned int letter, char *ph_buf)
|
||||
{//=====================================================================
|
||||
// lookup the character in the accents table
|
||||
int accent_data;
|
||||
int accent1;
|
||||
int accent_data = 0;
|
||||
int accent1 = 0;
|
||||
int accent2 = 0;
|
||||
int basic_letter;
|
||||
int letter2=0;
|
||||
char ph_letter1[30];
|
||||
char ph_letter2[30];
|
||||
char ph_accent1[30];
|
||||
char ph_accent2[30];
|
||||
|
||||
if((letter >= 0xe0) && (letter < 0x17f))
|
||||
{
|
||||
accent_data = letter_accents_0e0[letter - 0xe0];
|
||||
}
|
||||
else
|
||||
if((letter >= 0x250) && (letter <= 0x2a8))
|
||||
{
|
||||
accent_data = letter_accents_250[letter - 0x250];
|
||||
}
|
||||
|
||||
basic_letter = accent_data & 0x7f;
|
||||
if((accent1 = (accent_data >> 8) & 0x7f) != 0)
|
||||
if(accent_data != 0)
|
||||
{
|
||||
basic_letter = (accent_data & 0x3f) + 59;
|
||||
if(basic_letter < 'a')
|
||||
basic_letter = non_ascii_tab[basic_letter-59];
|
||||
|
||||
if(accent_data & 0x8000)
|
||||
{
|
||||
if(accent_data & 0x8000)
|
||||
{
|
||||
letter2 = accent1;
|
||||
accent1 = 0;
|
||||
}
|
||||
letter2 = (accent_data >> 6) & 0x3f;
|
||||
letter2 += 59;
|
||||
accent2 = (accent_data >> 12) & 0x7;
|
||||
}
|
||||
else
|
||||
{
|
||||
accent1 = (accent_data >> 6) & 0x1f;
|
||||
accent2 = (accent_data >> 11) & 0xf;
|
||||
}
|
||||
|
||||
if(Lookup(accents_tab[accent1].name, ph_accent1) != 0)
|
||||
{
|
||||
|
||||
if(LookupLetter2(basic_letter, ph_letter1) != 0)
|
||||
if(Lookup(accents_tab[accent1].name, ph_accent1) != 0)
|
||||
{
|
||||
|
||||
if(LookupLetter2(basic_letter, ph_letter1) != 0)
|
||||
{
|
||||
if(accent2 != 0)
|
||||
{
|
||||
if(Lookup(accents_tab[accent2].name, ph_accent2) == 0)
|
||||
{
|
||||
// break;
|
||||
}
|
||||
|
||||
if(accents_tab[accent2].flags & 1)
|
||||
{
|
||||
strcpy(ph_buf,ph_accent2);
|
||||
ph_buf += strlen(ph_buf);
|
||||
ph_accent2[0] = 0;
|
||||
}
|
||||
}
|
||||
if(letter2 != 0)
|
||||
{
|
||||
//ligature
|
||||
LookupLetter2(letter2, ph_letter2);
|
||||
sprintf(ph_buf,"%s%c%s%c%s%s",ph_accent1, phonPAUSE_VSHORT, ph_letter1, phonSTRESS_P, ph_letter2, ph_accent2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(accent1 == 0)
|
||||
{
|
||||
//ligature
|
||||
LookupLetter2(letter2, ph_letter2);
|
||||
sprintf(ph_buf,"%s%c%s%s",ph_accent1, phonPAUSE_VSHORT, ph_letter1, ph_letter2);
|
||||
}
|
||||
strcpy(ph_buf, ph_letter1);
|
||||
else
|
||||
{
|
||||
if(langopts.accents & 1)
|
||||
sprintf(ph_buf,"%s%c%s", ph_accent1, phonPAUSE_VSHORT, ph_letter1);
|
||||
else
|
||||
sprintf(ph_buf,"%s%c%s%c", ph_letter1, phonPAUSE_VSHORT, ph_accent1, phonPAUSE_VSHORT);
|
||||
}
|
||||
if((langopts.accents & 1) || (accents_tab[accent1].flags & 1))
|
||||
sprintf(ph_buf,"%s%c%c%s", ph_accent1, phonPAUSE_VSHORT, phonSTRESS_P, ph_letter1);
|
||||
else
|
||||
sprintf(ph_buf,"%s%c%s%c", ph_letter1, phonPAUSE_VSHORT, ph_accent1, phonPAUSE_VSHORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,7 +548,7 @@ void Translator::LookupLetter(unsigned int letter, int next_byte, char *ph_buf1)
|
||||
single_letter[1] = ' ';
|
||||
if(Lookup(&single_letter[2],ph_buf3) == 0)
|
||||
{
|
||||
TranslateRules(&single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,0,0);
|
||||
TranslateRules(&single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,0,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +620,8 @@ int Translator::TranslateLetter(char *word, char *phonemes, int control, int wor
|
||||
return(0);
|
||||
}
|
||||
|
||||
if((ph_buf[0] == 0) && (word_length == 1) && (translator_name != L('e','n')))
|
||||
if((ph_buf[0] == 0) && (translator_name != L('e','n')))
|
||||
// if((ph_buf[0] == 0) && (word_length == 1) && (translator_name != L('e','n')))
|
||||
{
|
||||
// speak as English, check whether there is a translation for this character
|
||||
SetTranslator2("en");
|
||||
@@ -473,7 +643,7 @@ int Translator::TranslateLetter(char *word, char *phonemes, int control, int wor
|
||||
if((ph_buf[0]==0) && !iswspace(letter))
|
||||
Lookup("_??",ph_buf);
|
||||
|
||||
if((control==4) && (ph_buf[0] != 0))
|
||||
if(ph_buf[0] != 0)
|
||||
{
|
||||
// speak the hexadecimal number of the character code
|
||||
sprintf(hexbuf,"%x",letter);
|
||||
|
||||
+1
-1
@@ -545,7 +545,7 @@ const char *Translator::LookupCharName(int c)
|
||||
{
|
||||
// now try the rules
|
||||
single_letter[1] = ' ';
|
||||
TranslateRules(&single_letter[2], phonemes, sizeof(phonemes), NULL,0,0);
|
||||
TranslateRules(&single_letter[2], phonemes, sizeof(phonemes), NULL,0,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,8 @@ static const char *help_text =
|
||||
"--punct=\"<characters>\"\n"
|
||||
"\t Speak the names of punctuation characters during speaking. If\n"
|
||||
"\t =<characters> is omitted, all punctuation is spoken.\n"
|
||||
"--split=\"<minutes>\"\n"
|
||||
"\t Starts a new WAV file every <minutes>. Used with -w\n"
|
||||
"--voices=<langauge>\n"
|
||||
"\t List the available voices for the specified language.\n"
|
||||
"\t If <language> is omitted, then list all voices.\n"
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@
|
||||
#include "translate.h"
|
||||
#include "wave.h"
|
||||
|
||||
const char *version_string = "1.31.20 01.Mar.08";
|
||||
const int version_phdata = 0x013105;
|
||||
const char *version_string = "1.32 04.Mar.08";
|
||||
const int version_phdata = 0x013200;
|
||||
|
||||
int option_device_number = -1;
|
||||
|
||||
|
||||
@@ -330,6 +330,7 @@ Translator *SelectTranslator(const char *name)
|
||||
tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
|
||||
tr->langopts.max_initial_consonants = 5;
|
||||
tr->langopts.spelling_stress = 1;
|
||||
tr->langopts.accents = 1;
|
||||
|
||||
tr->langopts.numbers = 0x140d + 0x4000 + NUM_ROMAN_UC;
|
||||
tr->langopts.numbers2 = 0x4a; // variant numbers before thousands,milliards
|
||||
@@ -442,8 +443,8 @@ SetLengthMods(tr,3); // all equal
|
||||
|
||||
case L('k','u'): // Kurdish
|
||||
{
|
||||
static const unsigned char stress_amps_ku[8] = {16,16, 20,20, 20,24, 24,22 };
|
||||
static const short stress_lengths_ku[8] = {170,170, 190,170, 0,0, 230,240};
|
||||
static const unsigned char stress_amps_ku[8] = {18,18, 20,20, 20,24, 24,22 };
|
||||
static const short stress_lengths_ku[8] = {180,180, 190,180, 0,0, 230,240};
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_ku,stress_amps_ku);
|
||||
@@ -451,7 +452,7 @@ SetLengthMods(tr,3); // all equal
|
||||
|
||||
tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
|
||||
|
||||
tr->langopts.numbers = 0x100469;
|
||||
tr->langopts.numbers = 0x100461;
|
||||
tr->langopts.max_initial_consonants = 2;
|
||||
}
|
||||
break;
|
||||
@@ -501,6 +502,7 @@ SetLengthMods(tr,3); // all equal
|
||||
SetLetterVowel(tr,'y');
|
||||
|
||||
tr->langopts.numbers = 0x11c19;
|
||||
tr->langopts.accents = 1;
|
||||
memcpy(tr->stress_lengths,stress_lengths_nl,sizeof(tr->stress_lengths));
|
||||
}
|
||||
break;
|
||||
@@ -630,6 +632,7 @@ SetLengthMods(tr,3); // all equal
|
||||
SetLetterVowel(tr,'y');
|
||||
// SetLetterBits(tr,6,"eiyäö"); // soft vowels NOTE accented letters don't work in SetLetterBits
|
||||
tr->langopts.numbers = 0x1909;
|
||||
tr->langopts.accents = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -762,6 +765,7 @@ SetLengthMods(tr,3); // all equal
|
||||
if(name2 == L('z','h'))
|
||||
{
|
||||
tr->langopts.textmode = 1;
|
||||
tr->langopts.listx = 1; // compile zh_listx after zh_list
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
+40
-14
@@ -758,6 +758,8 @@ if((wmark > 0) && (wmark < 8))
|
||||
{
|
||||
// change to another language in order to translate this word
|
||||
strcpy(word_phonemes,phonemes);
|
||||
if(word_length > 1)
|
||||
return(FLAG_SPELLWORD); // a mixture of languages, retranslate as individual letters, separated by spaces
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
@@ -785,7 +787,7 @@ if((wmark > 0) && (wmark < 8))
|
||||
{
|
||||
// change to another language in order to translate this word
|
||||
strcpy(word_phonemes,phonemes);
|
||||
return(0);
|
||||
return(FLAG_SPELLWORD);
|
||||
}
|
||||
|
||||
p = &wordx[word_length-3]; // this looks wrong. Doesn't consider multi-byte chars.
|
||||
@@ -810,7 +812,7 @@ if((wmark > 0) && (wmark < 8))
|
||||
{
|
||||
// Translate the stem
|
||||
unpron_length = strlen(phonemes);
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags[0]);
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
|
||||
|
||||
if(phonemes[0] == phonSWITCH)
|
||||
{
|
||||
@@ -859,11 +861,11 @@ if((wmark > 0) && (wmark < 8))
|
||||
|
||||
// remove any standard suffix and confirm that the prefix is still recognised
|
||||
phonemes2[0] = 0;
|
||||
end2 = TranslateRules(wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags[0]);
|
||||
end2 = TranslateRules(wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
|
||||
if(end2)
|
||||
{
|
||||
RemoveEnding(wordx,end2,word_copy);
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags[0]);
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
|
||||
memcpy(wordx,word_copy,strlen(word_copy));
|
||||
if((end_type & SUFX_P) == 0)
|
||||
{
|
||||
@@ -920,7 +922,7 @@ if((wmark > 0) && (wmark < 8))
|
||||
found = LookupDictList(&wordpf, phonemes, dictionary_flags, SUFX_P, wtab); // without prefix
|
||||
if(found == 0)
|
||||
{
|
||||
end_type = TranslateRules(wordpf, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags[0]);
|
||||
end_type = TranslateRules(wordpf, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
|
||||
sprintf(prefix_phonemes,"%s%s%s",phonemes,end_phonemes,prefix_phonemes2);
|
||||
}
|
||||
prefix_flags = 1;
|
||||
@@ -942,7 +944,7 @@ if((wmark > 0) && (wmark < 8))
|
||||
prefix_flags = 1;
|
||||
if(found == 0)
|
||||
{
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags[0]);
|
||||
end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
|
||||
|
||||
if(phonemes[0] == phonSWITCH)
|
||||
{
|
||||
@@ -1011,9 +1013,9 @@ strcpy(phonemes2,phonemes);
|
||||
else
|
||||
{
|
||||
if(end_flags & FLAG_SUFX)
|
||||
TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags[0]);
|
||||
TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags);
|
||||
else
|
||||
TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags[0]);
|
||||
TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags);
|
||||
|
||||
if(phonemes[0] == phonSWITCH)
|
||||
{
|
||||
@@ -1041,12 +1043,12 @@ strcpy(phonemes2,phonemes);
|
||||
{
|
||||
// s or 's suffix, append [s], [z] or [Iz] depending on previous letter
|
||||
if(last_char == 'f')
|
||||
TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
|
||||
TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
|
||||
else
|
||||
if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
|
||||
TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
|
||||
TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
|
||||
else
|
||||
TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
|
||||
TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
wflags |= emphasize_allcaps;
|
||||
@@ -1396,6 +1398,13 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
|
||||
|
||||
flags = translator->TranslateWord(word, next_pause, wtab);
|
||||
|
||||
if(flags & FLAG_SPELLWORD)
|
||||
{
|
||||
// re-translate the word as individual letters, separated by spaces
|
||||
memcpy(word, word_copy, word_copy_len);
|
||||
return(flags);
|
||||
}
|
||||
|
||||
if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
|
||||
{
|
||||
char *p2;
|
||||
@@ -2094,8 +2103,8 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
|
||||
c = ' ';
|
||||
}
|
||||
#endif
|
||||
if((c == 0x92) || (c == 0xb4) || (c == 0x2019))
|
||||
c = '\''; // 'microsoft' quote or sexed closing single quote - possibly used as apostrophe
|
||||
if((c == 0x92) || (c == 0xb4) || (c == 0x2019) || (c == 0x2032))
|
||||
c = '\''; // 'microsoft' quote or sexed closing single quote, or prime - possibly used as apostrophe
|
||||
|
||||
if((c == '?') && IsAlpha(prev_out) && IsAlpha(next_in))
|
||||
{
|
||||
@@ -2425,6 +2434,7 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
|
||||
for(ix=0; ix<word_count; ix++)
|
||||
{
|
||||
int j;
|
||||
int c_temp;
|
||||
char *pn;
|
||||
char *pw;
|
||||
char number_buf[80];
|
||||
@@ -2478,8 +2488,24 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
|
||||
else
|
||||
{
|
||||
dict_flags = TranslateWord2(word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
|
||||
|
||||
if(dict_flags & FLAG_SPELLWORD)
|
||||
{
|
||||
// redo the word, speaking single letters
|
||||
for(pw = word; *pw != ' ';)
|
||||
{
|
||||
memset(number_buf,' ',9);
|
||||
j = utf8_in(&c_temp, pw, 0);
|
||||
memcpy(&number_buf[2],pw,j);
|
||||
TranslateWord2(&number_buf[2], &words[ix], 0, 0 );
|
||||
pw += j;
|
||||
}
|
||||
}
|
||||
|
||||
if(dict_flags & FLAG_SKIPWORDS)
|
||||
ix += dictionary_skipwords; // dictionary indicates skip next word(s)
|
||||
{
|
||||
ix += dictionary_skipwords; // dictionary indicates skip next word(s)
|
||||
}
|
||||
|
||||
if((dict_flags & FLAG_DOT) && (ix == word_count-1) && (terminator == CLAUSE_PERIOD))
|
||||
{
|
||||
|
||||
+4
-2
@@ -46,6 +46,7 @@
|
||||
#define FLAG_STRESS_END2 0x1000 /* full stress if at end of clause, or only followed by unstressed */
|
||||
#define FLAG_UNSTRESS_END 0x2000 /* reduce stress at end of clause */
|
||||
#define FLAG_ATEND 0x4000 /* use this pronunciation if at end of clause */
|
||||
#define FLAG_SPELLWORD 0x8000 // re-translate the word as individual letters, separated by spaces
|
||||
|
||||
#define FLAG_DOT 0x10000 /* ignore '.' after word (abbreviation) */
|
||||
#define FLAG_ABBREV 0x20000 // spell as letters, even with a vowel, OR use specified pronunciation rather than split into letters
|
||||
@@ -85,7 +86,7 @@
|
||||
#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_SPELLING 0x20 // speak the word as individual letters
|
||||
#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
|
||||
@@ -360,6 +361,7 @@ typedef struct {
|
||||
char ideographs; // treat as separate words
|
||||
char textmode; // the meaning of FLAG_TEXTMODE is reversed (to save data when *_list file is compiled)
|
||||
int testing; // testing options: bit 1= specify stressed syllable in the form: "outdoor/2"
|
||||
int listx; // compile *_listx after *list
|
||||
const unsigned int *replace_chars; // characters to be substitutes
|
||||
} LANGUAGE_OPTIONS;
|
||||
|
||||
@@ -451,7 +453,7 @@ private:
|
||||
void AppendPhonemes(char *string, int size, const char *ph);
|
||||
char *DecodeRule(const char *group, char *rule);
|
||||
void MatchRule(char *word[], const char *group, char *rule, MatchRecord *match_out, int end_flags, int dict_flags);
|
||||
int TranslateRules(char *p, char *phonemes, int size, char *end_phonemes, int end_flags, int dict_flags);
|
||||
int TranslateRules(char *p, char *phonemes, int size, char *end_phonemes, int end_flags, unsigned int *dict_flags);
|
||||
void ApplySpecialAttribute(char *phonemes, int dict_flags);
|
||||
|
||||
int IsLetter(int letter, int group);
|
||||
|
||||
+2
-2
@@ -1670,11 +1670,11 @@ ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec)
|
||||
}
|
||||
else
|
||||
{
|
||||
// omit variant voices
|
||||
// list all: omit variant voices and mbrola voices
|
||||
j = 0;
|
||||
for(ix=0; (v = voices_list[ix]) != NULL; ix++)
|
||||
{
|
||||
if((v->languages[0] != 0) && (strcmp(&v->languages[1],"variant") != 0))
|
||||
if((v->languages[0] != 0) && (strcmp(&v->languages[1],"variant") != 0) && (memcmp(v->identifier,"mb/",3) != 0))
|
||||
{
|
||||
voices[j++] = v;
|
||||
}
|
||||
|
||||
+103
-35
@@ -37,6 +37,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef PLATFORM_WINDOWS
|
||||
#include <unistd.h>
|
||||
@@ -48,6 +49,18 @@
|
||||
|
||||
enum {ONE_BILLION=1000000000};
|
||||
|
||||
enum {
|
||||
// /* 100ms.
|
||||
// If a greater value is set (several seconds),
|
||||
// please update _pulse_timeout_start accordingly */
|
||||
// PULSE_TIMEOUT_IN_USEC = 100000,
|
||||
|
||||
/* return value */
|
||||
PULSE_OK = 0,
|
||||
PULSE_ERROR = -1,
|
||||
PULSE_NO_CONNECTION = -2
|
||||
};
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
||||
static t_wave_callback* my_callback_is_output_enabled=NULL;
|
||||
@@ -62,6 +75,8 @@ static t_wave_callback* my_callback_is_output_enabled=NULL;
|
||||
#define MINREQ 880
|
||||
#define FRAGSIZE 0
|
||||
|
||||
static pthread_mutex_t pulse_mutex;
|
||||
|
||||
static pa_context *context = NULL;
|
||||
static pa_stream *stream = NULL;
|
||||
static pa_threaded_mainloop *mainloop = NULL;
|
||||
@@ -81,7 +96,7 @@ if (!mainloop || \
|
||||
!context || pa_context_get_state(context) != PA_CONTEXT_READY || \
|
||||
!stream || pa_stream_get_state(stream) != PA_STREAM_READY) { \
|
||||
if (warn) \
|
||||
printf("Connection died: %s\n", context ? pa_strerror(pa_context_errno(context)) : "NULL"); \
|
||||
SHOW("Connection died: %s\n", context ? pa_strerror(pa_context_errno(context)) : "NULL"); \
|
||||
goto label; \
|
||||
} \
|
||||
} while(0);
|
||||
@@ -91,6 +106,11 @@ do { \
|
||||
if (!connected) return retval; \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_CONNECTED_NO_RETVAL(id) \
|
||||
do { \
|
||||
if (!connected){ SHOW("CHECK_CONNECTED_NO_RETVAL: !pulse_connected\n", ""); return; } \
|
||||
} while (0);
|
||||
|
||||
//>
|
||||
|
||||
|
||||
@@ -136,7 +156,7 @@ static void subscribe_cb(struct pa_context *c, enum pa_subscription_event_type t
|
||||
return;
|
||||
|
||||
if (!(o = pa_context_get_sink_input_info(c, index, info_cb, NULL))) {
|
||||
printf("pa_context_get_sink_input_info() failed: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
SHOW("pa_context_get_sink_input_info() failed: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -365,20 +385,21 @@ fail:
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
}
|
||||
|
||||
static void drain(void) {
|
||||
static int drain(void) {
|
||||
pa_operation *o = NULL;
|
||||
int success = 0;
|
||||
int ret = PULSE_ERROR;
|
||||
|
||||
ENTER(__FUNCTION__);
|
||||
|
||||
CHECK_CONNECTED();
|
||||
CHECK_CONNECTED(ret);
|
||||
|
||||
pa_threaded_mainloop_lock(mainloop);
|
||||
CHECK_DEAD_GOTO(fail, 0);
|
||||
|
||||
SHOW_TIME("pa_stream_drain (call)");
|
||||
if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) {
|
||||
printf("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -389,8 +410,12 @@ static void drain(void) {
|
||||
}
|
||||
SHOW_TIME("pa_threaded_mainloop_wait (ret)");
|
||||
|
||||
if (!success)
|
||||
printf("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
if (!success) {
|
||||
SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
}
|
||||
else {
|
||||
ret = PULSE_OK;
|
||||
}
|
||||
|
||||
fail:
|
||||
SHOW_TIME("pa_operation_unref (call)");
|
||||
@@ -399,6 +424,8 @@ fail:
|
||||
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
SHOW_TIME("drain (ret)");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -413,12 +440,7 @@ static void pulse_close(void) {
|
||||
if (mainloop)
|
||||
pa_threaded_mainloop_stop(mainloop);
|
||||
|
||||
if (stream) {
|
||||
SHOW_TIME("pa_stream_disconnect (call)");
|
||||
pa_stream_disconnect(stream);
|
||||
pa_stream_unref(stream);
|
||||
stream = NULL;
|
||||
}
|
||||
connected = 0;
|
||||
|
||||
if (context) {
|
||||
SHOW_TIME("pa_context_disconnect (call)");
|
||||
@@ -443,12 +465,15 @@ static int pulse_open()
|
||||
pa_sample_spec ss;
|
||||
pa_operation *o = NULL;
|
||||
int success;
|
||||
int ret = PULSE_ERROR;
|
||||
|
||||
assert(!mainloop);
|
||||
assert(!context);
|
||||
assert(!stream);
|
||||
assert(!connected);
|
||||
|
||||
pthread_mutex_init( &pulse_mutex, (const pthread_mutexattr_t *)NULL);
|
||||
|
||||
ss.format = ESPEAK_FORMAT;
|
||||
ss.rate = SAMPLE_RATE;
|
||||
ss.channels = ESPEAK_CHANNEL;
|
||||
@@ -464,7 +489,7 @@ static int pulse_open()
|
||||
|
||||
SHOW_TIME("pa_threaded_mainloop_new (call)");
|
||||
if (!(mainloop = pa_threaded_mainloop_new())) {
|
||||
printf("Failed to allocate main loop\n");
|
||||
SHOW("Failed to allocate main loop\n","");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -472,7 +497,7 @@ static int pulse_open()
|
||||
|
||||
SHOW_TIME("pa_context_new (call)");
|
||||
if (!(context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "eSpeak"))) {
|
||||
printf("Failed to allocate context\n");
|
||||
SHOW("Failed to allocate context\n","");
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -481,13 +506,14 @@ static int pulse_open()
|
||||
|
||||
SHOW_TIME("pa_context_connect (call)");
|
||||
if (pa_context_connect(context, NULL, (pa_context_flags_t)0, NULL) < 0) {
|
||||
printf("Failed to connect to server: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("Failed to connect to server: %s", pa_strerror(pa_context_errno(context)));
|
||||
ret = PULSE_NO_CONNECTION;
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
SHOW_TIME("pa_threaded_mainloop_start (call)");
|
||||
if (pa_threaded_mainloop_start(mainloop) < 0) {
|
||||
printf("Failed to start main loop");
|
||||
SHOW("Failed to start main loop","");
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -496,13 +522,16 @@ static int pulse_open()
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
|
||||
if (pa_context_get_state(context) != PA_CONTEXT_READY) {
|
||||
printf("Failed to connect to server: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("Failed to connect to server: %s", pa_strerror(pa_context_errno(context)));
|
||||
ret = PULSE_NO_CONNECTION;
|
||||
if (mainloop)
|
||||
pa_threaded_mainloop_stop(mainloop);
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
SHOW_TIME("pa_stream_new");
|
||||
if (!(stream = pa_stream_new(context, "unknown", &ss, NULL))) {
|
||||
printf("Failed to create stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("Failed to create stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -522,7 +551,7 @@ static int pulse_open()
|
||||
|
||||
SHOW_TIME("pa_connect_playback");
|
||||
if (pa_stream_connect_playback(stream, NULL, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), &volume, NULL) < 0) {
|
||||
printf("Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -531,14 +560,14 @@ static int pulse_open()
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
|
||||
if (pa_stream_get_state(stream) != PA_STREAM_READY) {
|
||||
printf("Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
/* Now subscribe to events */
|
||||
SHOW_TIME("pa_context_subscribe");
|
||||
if (!(o = pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_SINK_INPUT, context_success_cb, &success))) {
|
||||
printf("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -550,7 +579,7 @@ static int pulse_open()
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
printf("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -558,7 +587,7 @@ static int pulse_open()
|
||||
|
||||
/* Now request the initial stream info */
|
||||
if (!(o = pa_context_get_sink_input_info(context, pa_stream_get_index(stream), info_cb, NULL))) {
|
||||
printf("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context)));
|
||||
goto unlock_and_fail;
|
||||
}
|
||||
|
||||
@@ -569,7 +598,7 @@ static int pulse_open()
|
||||
}
|
||||
|
||||
/* if (!volume_valid) { */
|
||||
/* printf("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context))); */
|
||||
/* SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context))); */
|
||||
/* goto unlock_and_fail; */
|
||||
/* } */
|
||||
|
||||
@@ -583,7 +612,9 @@ static int pulse_open()
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
SHOW_TIME("pulse_open (ret true)");
|
||||
|
||||
return true;
|
||||
// return true;
|
||||
return PULSE_OK;
|
||||
|
||||
|
||||
unlock_and_fail:
|
||||
|
||||
@@ -594,13 +625,29 @@ unlock_and_fail:
|
||||
|
||||
fail:
|
||||
|
||||
// pulse_close();
|
||||
|
||||
if (ret == PULSE_NO_CONNECTION) {
|
||||
if (context) {
|
||||
SHOW_TIME("pa_context_disconnect (call)");
|
||||
pa_context_disconnect(context);
|
||||
pa_context_unref(context);
|
||||
context = NULL;
|
||||
}
|
||||
|
||||
if (mainloop) {
|
||||
SHOW_TIME("pa_threaded_mainloop_free (call)");
|
||||
pa_threaded_mainloop_free(mainloop);
|
||||
mainloop = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pulse_close();
|
||||
}
|
||||
|
||||
SHOW_TIME("pulse_open (ret false)");
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
SHOW_TIME("pulse_open (ret false)");
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@@ -661,13 +708,16 @@ size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSiz
|
||||
|
||||
size_t aTotalFreeMem=0;
|
||||
|
||||
pthread_mutex_lock(&pulse_mutex);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (my_callback_is_output_enabled
|
||||
&& (0==my_callback_is_output_enabled()))
|
||||
{
|
||||
SHOW_TIME("wave_write > my_callback_is_output_enabled: no!");
|
||||
return 0;
|
||||
theSize=0;
|
||||
goto terminate;
|
||||
}
|
||||
|
||||
aTotalFreeMem = pulse_free();
|
||||
@@ -698,9 +748,10 @@ size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSiz
|
||||
|
||||
pulse_write(aBuffer, bytes_to_write);
|
||||
|
||||
|
||||
terminate:
|
||||
pthread_mutex_unlock(&pulse_mutex);
|
||||
SHOW("wave_write: theSize=%d", theSize);
|
||||
SHOW_TIME("wave_write > LEAVE");
|
||||
|
||||
return theSize;
|
||||
}
|
||||
|
||||
@@ -711,9 +762,18 @@ int wave_close(void* theHandler)
|
||||
{
|
||||
SHOW_TIME("wave_close > ENTER");
|
||||
|
||||
int a_status = pthread_mutex_lock(&pulse_mutex);
|
||||
if (a_status) {
|
||||
SHOW("Error: pulse_mutex lock=%d (%s)\n", a_status, __FUNCTION__);
|
||||
return PULSE_ERROR;
|
||||
}
|
||||
|
||||
drain();
|
||||
|
||||
return 0;
|
||||
pthread_mutex_unlock(&pulse_mutex);
|
||||
SHOW_TIME("wave_close (ret)");
|
||||
|
||||
return PULSE_OK;
|
||||
}
|
||||
|
||||
//>
|
||||
@@ -738,8 +798,16 @@ void wave_terminate()
|
||||
|
||||
// Pa_Terminate();
|
||||
|
||||
int a_status;
|
||||
pthread_mutex_t* a_mutex = NULL;
|
||||
a_mutex = &pulse_mutex;
|
||||
a_status = pthread_mutex_lock(a_mutex);
|
||||
|
||||
pulse_close();
|
||||
|
||||
SHOW_TIME("unlock mutex");
|
||||
a_status = pthread_mutex_unlock(a_mutex);
|
||||
pthread_mutex_destroy(a_mutex);
|
||||
}
|
||||
|
||||
//>
|
||||
|
||||
Reference in New Issue
Block a user