[1.39.42]

Languages which use non-Latin alphabets will automatically speak a word of Latin characters as English (or another specified language) without the need for entries in its *_rules file.

synthesize.cpp, SynthOnTimer():  Ensure the sound channel is open if there items still to be spoken, to prevent sound output lock-up.

Reduce warning messages from compilers.


git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@211 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
jonsd
2008-12-17 12:17:53 +00:00
parent 90cb171a52
commit 7758b77459
35 changed files with 359 additions and 438 deletions
+22 -23
View File
@@ -85,13 +85,10 @@
static const int flags_alternative[] = {phBEFOREVOWEL,phBEFOREVOWELPAUSE,phBEFORENOTVOWEL,phBEFORENOTVOWEL2,phSWITCHVOICING};
extern void Write4Bytes(FILE *f, int value);
extern int Read4Bytes(FILE *f);
extern void MakeVowelLists(void);
extern void FindPhonemesUsed(void);
extern void DrawEnvelopes();
extern int LoadEnvelope2(FILE *f, const char *fname);
extern int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *fname, int flags);
static int markers_used[8];
@@ -109,7 +106,7 @@ typedef struct {
int n_envelopes = 0;
char envelope_paths[N_ENVELOPES][80];
unsigned char envelope_dat[N_ENVELOPES][ENV_LEN];
FILE *f_phdata;
static FILE *f_phdata;
@@ -343,8 +340,8 @@ static FILE *fopen_log(FILE *f_log, const char *fname,const char *access)
}
int Hash8(const char *string)
//===========================
static int Hash8(const char *string)
//==================================
/* Generate a hash code from the specified string */
{
int c;
@@ -807,8 +804,6 @@ int Compile::LoadWavefile(FILE *f, const char *fname)
int resample_wav = 0;
char fname_temp[100];
int scale_factor=0;
int fd_temp;
char command[sizeof(path_source)+200];
fseek(f,24,SEEK_SET);
sr1 = Read4Bytes(f);
@@ -828,26 +823,30 @@ int Compile::LoadWavefile(FILE *f, const char *fname)
Error("Not mono: ",fname);
}
#else
strcpy(fname_temp,"/tmp/espeakXXXXXX");
if((fd_temp = mkstemp(fname_temp)) >= 0)
{
close(fd_temp);
sprintf(command,"sox \"%s%s.wav\" -r %d -c 1 -w %s polyphase\n",path_source,fname,samplerate,fname_temp);
if(system(command) < 0)
int fd_temp;
char command[sizeof(path_source)+200];
strcpy(fname_temp,"/tmp/espeakXXXXXX");
if((fd_temp = mkstemp(fname_temp)) >= 0)
{
Error("Failed to resample: ",command);
close(fd_temp);
sprintf(command,"sox \"%s%s.wav\" -r %d -c 1 -w %s polyphase\n",path_source,fname,samplerate,fname_temp);
if(system(command) < 0)
{
Error("Failed to resample: ",command);
return(0);
}
}
f = fopen(fname_temp,"rb");
if(f == NULL)
{
Error("Can't read temp file: ",fname_temp);
return(0);
}
resample_wav = 1;
fseek(f,40,SEEK_SET); // skip past the WAV header, up to before "data length"
}
f = fopen(fname_temp,"rb");
if(f == NULL)
{
Error("Can't read temp file: ",fname_temp);
return(0);
}
resample_wav = 1;
fseek(f,40,SEEK_SET); // skip past the WAV header, up to before "data length"
#endif
}
+19 -1
View File
@@ -779,6 +779,13 @@ int Unpronouncable(Translator *tr, char *word)
return(Unpronouncable_en(tr,word));
}
utf8_in(&c,word);
if((tr->letter_bits_offset > 0) && (c < 0x241))
{
// Latin characters for a language with a non-latin alphabet
return(0); // so we can re-translate the word as English
}
if(tr->langopts.param[LOPT_UNPRONOUNCABLE] == 1)
return(0);
@@ -2523,8 +2530,19 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
if((match1.points == 0) && ((option_sayas & 0x10) == 0))
{
// no match, try removing the accent and re-translating the word
n = utf8_in(&letter,p-1)-1;
if(tr->letter_bits_offset > 0)
{
// not a Latin alphabet, switch to the default Latin alphabet language
if((letter <= 0x241) && iswalpha(letter))
{
sprintf(phonemes,"%c%s",phonSWITCH,tr->langopts.ascii_language);
return(0);
}
}
// no match, try removing the accent and re-translating the word
if((letter >= 0xc0) && (letter <= 0x241) && ((ix = remove_accent[letter-0xc0]) != 0))
{
// within range of the remove_accent table
+1 -1
View File
@@ -619,9 +619,9 @@ const long style):
MyChild::~MyChild(void)
{
wxWindow *w;
canvas = NULL;
#ifndef PLATFORM_WINDOWS
wxWindow *w;
// bug in wxMDIChildFrame, we need to explicitly remove the ChildFrame from the ClientWindow
w = myframe->GetClientWindow();
w->RemoveChild(this);
+4 -3
View File
@@ -496,7 +496,7 @@ void Lexicon_Ru()
char fname[sizeof(path_dsource)+20];
// KOI8-R codes for Russian vowels
static char vowels[] = {0xa3,0xc0,0xc1,0xc5,0xc9,0xcf,0xd1,0xd5,0xd9,0xdc,0};
static unsigned char vowels[] = {0xa3,0xc0,0xc1,0xc5,0xc9,0xcf,0xd1,0xd5,0xd9,0xdc,0};
typedef struct {
const char *suffix;
@@ -617,7 +617,7 @@ p_unicode = unicode;
ru_stress = vcount;
break;
}
if(strchr(vowels,c) != NULL)
if(strchr((char *)vowels,c) != NULL)
{
vcount++;
}
@@ -1163,6 +1163,7 @@ void Test2()
const char* text1 = "Hello world. Testing.";
extern void TestCompile2(void);
void TestTest(int control)
{//=======================
@@ -1177,7 +1178,7 @@ void TestTest(int control)
//CharsetToUnicode("ISO-8859-4");
//CharsetToUnicode("ISCII");
TestCompile2();
return;
if(control==2)
+4 -3
View File
@@ -654,7 +654,6 @@ static int LoadSoundFile(const char *fname, int index)
int length;
char fname_temp[100];
char fname2[sizeof(path_home)+13+40];
char command[sizeof(fname2)+sizeof(fname2)+40];
if(fname == NULL)
{
@@ -680,6 +679,7 @@ static int LoadSoundFile(const char *fname, int index)
int fd_temp;
const char *resample;
int header[3];
char command[sizeof(fname2)+sizeof(fname2)+40];
fseek(f,20,SEEK_SET);
for(ix=0; ix<3; ix++)
@@ -1243,9 +1243,10 @@ static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out)
} // end of attr_prosody_value
static int AddNameData(const char *name, int wide)
{//===============================================
int AddNameData(const char *name, int wide)
{//========================================
// Add the name to the namedata and return its position
// (Used by the Windows SAPI wrapper)
int ix;
int len;
void *vp;
+21 -7
View File
@@ -74,11 +74,12 @@ static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event)
int a_wave_can_be_played = fifo_is_command_enabled();
#ifdef DEBUG_ENABLED
SHOW("*** dispatch_audio > uid=%d, [write=%p (%d bytes)], sample=%d, a_wave_can_be_played = %d\n",
(event) ? event->unique_identifier : 0, wave_test_get_write_buffer(), 2*length,
(event) ? event->sample : 0,
a_wave_can_be_played);
#endif
switch(my_mode)
{
@@ -156,11 +157,14 @@ static int create_events(short* outbuf, int length, espeak_EVENT* event, uint32_
else
{
event = event_list + i;
#ifdef DEBUG_ENABLED
SHOW("Synthesize: event->sample(%d) + %d = %d\n", event->sample, the_write_pos, event->sample + the_write_pos);
#endif
event->sample += the_write_pos;
}
#ifdef DEBUG_ENABLED
SHOW("*** Synthesize: i=%d (event_list_ix=%d), length=%d\n",i,event_list_ix,length);
#endif
finished = dispatch_audio((short *)outbuf, length, event);
length = 0; // the wave data are played once.
i++;
@@ -365,7 +369,6 @@ static int initialise(void)
static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags)
{//========================================================================================
// Fill the buffer with output sound
ENTER("Synthesize");
int length;
int finished = 0;
int count_buffers = 0;
@@ -374,6 +377,7 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text,
#endif
#ifdef DEBUG_ENABLED
ENTER("Synthesize");
if (text)
{
SHOW("Synthesize > uid=%d, flags=%d, >>>text=%s<<<\n", unique_identifier, flags, text);
@@ -429,7 +433,9 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text,
for(;;)
{
#ifdef DEBUG_ENABLED
SHOW("Synthesize > %s\n","for (next)");
#endif
out_ptr = outbuf;
out_end = &outbuf[outbuf_size];
event_list_ix = 0;
@@ -524,11 +530,13 @@ void MarkerEvent(int type, unsigned int char_position, int value, unsigned char
ep->audio_position = int(time);
ep->sample = (count_samples + mbrola_delay + (out_ptr - out_start)/2);
#ifdef DEBUG_ENABLED
SHOW("MarkerEvent > count_samples=%d, out_ptr=%x, out_start=0x%x\n",count_samples, out_ptr, out_start);
SHOW("*** MarkerEvent > type=%s, uid=%d, text_pos=%d, length=%d, audio_position=%d, sample=%d\n",
label[ep->type], ep->unique_identifier, ep->text_position, ep->length,
ep->audio_position, ep->sample);
#endif
if((type == espeakEVENT_MARK) || (type == espeakEVENT_PLAY))
ep->id.name = &namedata[value];
else
@@ -542,11 +550,13 @@ espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text,
unsigned int position, espeak_POSITION_TYPE position_type,
unsigned int end_position, unsigned int flags, void* user_data)
{//===========================================================================
#ifdef DEBUG_ENABLED
ENTER("sync_espeak_Synth");
SHOW("sync_espeak_Synth > position=%d, position_type=%d, end_position=%d, flags=%d, user_data=0x%x, text=%s\n", position, position_type, end_position, flags, user_data, text);
espeak_ERROR aStatus;
#endif
espeak_ERROR aStatus;
InitText(flags);
my_unique_identifier = unique_identifier;
@@ -748,8 +758,10 @@ ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size,
unsigned int end_position, unsigned int flags,
unsigned int* unique_identifier, void* user_data)
{//=====================================================================================
#ifdef DEBUG_ENABLED
ENTER("espeak_Synth");
SHOW("espeak_Synth > position=%d, position_type=%d, end_position=%d, flags=%d, user_data=0x%x, text=%s\n", position, position_type, end_position, flags, user_data, text);
#endif
espeak_ERROR a_error=EE_INTERNAL_ERROR;
static unsigned int temp_identifier;
@@ -805,8 +817,10 @@ ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,
unsigned int* unique_identifier,
void* user_data)
{//=========================================================================
#ifdef DEBUG_ENABLED
ENTER("espeak_Synth_Mark");
SHOW("espeak_Synth_Mark > index_mark=%s, end_position=%d, flags=%d, text=%s\n", index_mark, end_position, flags, text);
#endif
espeak_ERROR a_error=EE_OK;
static unsigned int temp_identifier;
+13 -13
View File
@@ -35,7 +35,7 @@
#include "translate.h"
#include "wave.h"
const char *version_string = "1.39.39 11.Dec.08";
const char *version_string = "1.39.42 17.Dec.08";
const int version_phdata = 0x013900;
int option_device_number = -1;
@@ -69,8 +69,8 @@ int FormantTransition2(frameref_t *seq, int &n_frames, unsigned int data1, unsig
static int ReadPhFile(char **ptr, const char *fname)
{//=================================================
static char *ReadPhFile(void *ptr, const char *fname)
{//==================================================
FILE *f_in;
char *p;
unsigned int length;
@@ -82,25 +82,25 @@ static int ReadPhFile(char **ptr, const char *fname)
if((f_in = fopen(buf,"rb")) == NULL)
{
fprintf(stderr,"Can't read data file: '%s'\n",buf);
return(1);
return(NULL);
}
if(*ptr != NULL)
Free(*ptr);
if(ptr != NULL)
Free(ptr);
if((p = Alloc(length)) == NULL)
{
fclose(f_in);
return(-1);
return(NULL);
}
if(fread(p,1,length,f_in) != length)
{
fclose(f_in);
return(-1);
return(NULL);
}
*ptr = p;
fclose(f_in);
return(0);
return(p);
} // end of ReadPhFile
@@ -112,11 +112,11 @@ int LoadPhData()
int result = 1;
unsigned char *p;
if(ReadPhFile((char **)(&phoneme_tab_data),"phontab") != 0)
if((phoneme_tab_data = (unsigned char *)ReadPhFile((void *)(phoneme_tab_data),"phontab")) == NULL)
return(-1);
if(ReadPhFile((char **)(&phoneme_index),"phonindex") != 0)
if((phoneme_index = (unsigned int *)ReadPhFile((void *)(phoneme_index),"phonindex")) == NULL)
return(-1);
if(ReadPhFile((char **)(&spects_data),"phondata") != 0)
if((spects_data = ReadPhFile((void *)(spects_data),"phondata")) == NULL)
return(-1);
wavefile_data = (unsigned char *)spects_data;
+9 -4
View File
@@ -1479,6 +1479,9 @@ int SynthOnTimer()
}
do {
if(WcmdqUsed() > 0)
WavegenOpenSound();
if(Generate(phoneme_list,&n_phoneme_list,1)==0)
{
SpeakNextClause(NULL,NULL,1);
@@ -1511,7 +1514,6 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control)
int clause_tone;
char *voice_change;
FILE *f_mbrola;
static FILE *f_text=NULL;
static const void *p_text=NULL;
@@ -1629,9 +1631,12 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control)
#ifdef USE_MBROLA_LIB
MbrolaTranslate(phoneme_list,n_phoneme_list,NULL);
#else
if((f_mbrola = f_trans) == stderr)
f_mbrola = stdout;
MbrolaTranslate(phoneme_list,n_phoneme_list,f_mbrola);
{
FILE *f_mbrola;
if((f_mbrola = f_trans) == stderr)
f_mbrola = stdout;
MbrolaTranslate(phoneme_list,n_phoneme_list,f_mbrola);
}
#endif
}
+4
View File
@@ -297,6 +297,10 @@ void SetEmbedded(int control, int value);
void SelectPhonemeTable(int number);
int SelectPhonemeTableName(const char *name);
void Write4Bytes(FILE *f, int value);
int Read4Bytes(FILE *f);
int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *err_name,int flags);
extern unsigned char *envelope_data[18];
extern int formant_rate[]; // max rate of change of each formant
+4 -2
View File
@@ -153,6 +153,7 @@ static Translator* NewTranslator(void)
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 's'; // don't count this character at start of word
tr->langopts.max_initial_consonants = 3;
tr->langopts.replace_chars = NULL;
tr->langopts.ascii_language = ""; // Non-Latin alphabet languages, use this language to speak Latin words, default is English
SetLengthMods(tr,201);
// tr->langopts.length_mods = length_mods_en;
@@ -576,6 +577,7 @@ SetLengthMods(tr,3); // all equal
SetLetterBits(tr,LETTERGP_C,hy_consonants);
tr->langopts.max_initial_consonants = 6;
tr->langopts.numbers = 0x409;
// tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
}
break;
@@ -652,13 +654,13 @@ SetLengthMods(tr,3); // all equal
case L('k','o'): // Korean, TEST
{
static const char ko_ivowels[] = {0x63,0x64,0x67,0x68,0x6d,0x72,0x74,0x75,0}; // y and i vowels
static const char ko_voiced[] = {0x02,0x05,0x06,0xab,0xaf,0xb7,0xbc,0}; // voiced consonants, l,m,n,N
static const unsigned char ko_voiced[] = {0x02,0x05,0x06,0xab,0xaf,0xb7,0xbc,0}; // voiced consonants, l,m,n,N
tr->letter_bits_offset = OFFSET_KOREAN;
memset(tr->letter_bits,0,sizeof(tr->letter_bits));
SetLetterBitsRange(tr,LETTERGP_A,0x61,0x75);
SetLetterBits(tr,LETTERGP_Y,ko_ivowels);
SetLetterBits(tr,LETTERGP_G,ko_voiced);
SetLetterBits(tr,LETTERGP_G,(const char *)ko_voiced);
tr->langopts.stress_rule = 8; // ?? 1st syllable if it is heavy, else 2nd syllable
tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
+1 -1
View File
@@ -378,6 +378,7 @@ typedef struct {
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
const char *ascii_language; // switch to this language for Latin characters
} LANGUAGE_OPTIONS;
@@ -517,7 +518,6 @@ extern int (* uri_callback)(int, const char *, const char *);
extern int (* phoneme_callback)(const char *);
extern void SetLengthMods(Translator *tr, int value);
int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *err_name,int flags);
void LoadConfig(void);
int TransposeAlphabet(char *text, int offset, int min, int max);
int utf8_in(int *c, const char *buf);