mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-04 07:48:47 +00:00
[1.30.10]
Remove pause before <say-as> if it's at the beginning of a sentence. Added --split=<minutes> command-line option. Splits output WAV file (at sentence boundaries). Fix: espeakEVENT_SENTENCE events were missing. git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@121 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
#define tVOWELOUT 23
|
||||
#define tAPPENDPH 24 // always insert another phoneme (linkout) after this one
|
||||
#define tIMPORTPH 25
|
||||
#define tBEFOREPAUSE 26
|
||||
|
||||
#define tPHONEMENUMBER 29
|
||||
#define tPHONEMETABLE 30
|
||||
@@ -238,6 +239,7 @@ static keywtab_t keywords[] = {
|
||||
{"vowelout",23},
|
||||
{"appendph",24},
|
||||
{"import_phoneme",25},
|
||||
{"beforepause",26},
|
||||
|
||||
// flags
|
||||
{"wavef", 0x2000000+phWAVE},
|
||||
@@ -1389,6 +1391,13 @@ int Compile::CPhoneme()
|
||||
ph->alternative_ph = phcode;
|
||||
break;
|
||||
|
||||
case tBEFOREPAUSE:
|
||||
ph->phflags |= phBEFOREPAUSE;
|
||||
if((phcode = NextItem(tPHONEMEMNEM)) == -1)
|
||||
phcode = LookupPhoneme(item_string,1);
|
||||
ph->link_out = phcode;
|
||||
break;
|
||||
|
||||
case tAPPENDPH:
|
||||
ph->phflags |= phAPPENDPH; // drop through to tLINKOUT
|
||||
case tLINKOUT:
|
||||
|
||||
+54
-7
@@ -76,8 +76,14 @@ static const char *help_text =
|
||||
|
||||
|
||||
int samplerate;
|
||||
int quiet = 0;
|
||||
unsigned int samples_total = 0;
|
||||
unsigned int samples_split = 0;
|
||||
unsigned int wavefile_count = 0;
|
||||
|
||||
FILE *f_wavfile = NULL;
|
||||
char wavefile[160];
|
||||
char filetype[5];
|
||||
char wavefile[200];
|
||||
|
||||
|
||||
int GetFileLength(const char *filename)
|
||||
@@ -217,8 +223,8 @@ int OpenWavFile(char *path, int rate)
|
||||
|
||||
|
||||
|
||||
static void CloseWavFile(int rate)
|
||||
//================================
|
||||
static void CloseWavFile()
|
||||
//========================
|
||||
{
|
||||
unsigned int pos;
|
||||
|
||||
@@ -240,20 +246,42 @@ static void CloseWavFile(int rate)
|
||||
} // end of CloseWavFile
|
||||
|
||||
|
||||
|
||||
static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events)
|
||||
{//========================================================================
|
||||
char fname[210];
|
||||
|
||||
if(f_wavfile == NULL) return(0); // -q quiet mode
|
||||
if(quiet) return(0); // -q quiet mode
|
||||
|
||||
if(wav == NULL)
|
||||
{
|
||||
CloseWavFile(samplerate);
|
||||
CloseWavFile();
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(samples_split > 0)
|
||||
{
|
||||
// start a new WAV file when this limit is reached, at the next sentence boundary
|
||||
while(events->type != 0)
|
||||
{
|
||||
if((events->type == espeakEVENT_SENTENCE) && (samples_total > samples_split))
|
||||
{
|
||||
CloseWavFile();
|
||||
samples_total = 0;
|
||||
}
|
||||
events++;
|
||||
}
|
||||
}
|
||||
|
||||
if(f_wavfile == NULL)
|
||||
{
|
||||
sprintf(fname,"%s_%.2d%s",wavefile,++wavefile_count,filetype);
|
||||
if(OpenWavFile(fname, samplerate) != 0)
|
||||
return(1);
|
||||
}
|
||||
|
||||
if(numsamples > 0)
|
||||
{
|
||||
samples_total += numsamples;
|
||||
fwrite(wav,numsamples*2,1,f_wavfile);
|
||||
}
|
||||
return(0);
|
||||
@@ -279,6 +307,7 @@ int main (int argc, char **argv)
|
||||
{"punct", optional_argument, 0, 0x103},
|
||||
{"voices", optional_argument, 0, 0x104},
|
||||
{"stdout", no_argument, 0, 0x105},
|
||||
{"split", optional_argument, 0, 0x106},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -291,7 +320,6 @@ int main (int argc, char **argv)
|
||||
int option_index = 0;
|
||||
int c;
|
||||
int ix;
|
||||
int quiet = 0;
|
||||
int flag_stdin = 0;
|
||||
int flag_compile = 0;
|
||||
int filesize = 0;
|
||||
@@ -431,6 +459,13 @@ int main (int argc, char **argv)
|
||||
DisplayVoices(stdout,optarg);
|
||||
exit(0);
|
||||
|
||||
case 0x106: // -- split
|
||||
if(optarg == NULL)
|
||||
samples_split = 30; // default 30 minutes
|
||||
else
|
||||
samples_split = atoi(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
@@ -441,8 +476,20 @@ int main (int argc, char **argv)
|
||||
{
|
||||
// writing to a file (or no output), we can use synchronous mode
|
||||
samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL,0);
|
||||
samples_split = (samplerate * samples_split) * 60;
|
||||
|
||||
espeak_SetSynthCallback(SynthCallback);
|
||||
if(samples_split)
|
||||
{
|
||||
char *extn;
|
||||
extn = strrchr(wavefile,'.');
|
||||
if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4))
|
||||
{
|
||||
strcpy(filetype,extn);
|
||||
*extn = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(option_waveout)
|
||||
{
|
||||
if(OpenWavFile(wavefile,samplerate) != 0)
|
||||
|
||||
+9
-3
@@ -179,13 +179,13 @@ void Translator::SetSpellingStress(char *phonemes, int control)
|
||||
else
|
||||
if(c == 0xff)
|
||||
{
|
||||
if(control < 2)
|
||||
if((control < 2) || (ix==0))
|
||||
continue; // don't insert pauses
|
||||
|
||||
if(control == 4)
|
||||
c = phonPAUSE; // pause after each character
|
||||
if(((count % 3) == 0) || (control == 4))
|
||||
c = phonPAUSE_NOLINK; // pause following a primary stress
|
||||
c = phonPAUSE_SHORT; // pause following a primary stress
|
||||
else
|
||||
continue; // remove marker
|
||||
}
|
||||
@@ -807,7 +807,13 @@ int Translator::TranslateNumber_1(char *word, char *ph_out, unsigned int *flags,
|
||||
if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH))
|
||||
{
|
||||
int next_char;
|
||||
utf8_in(&next_char,&word[n_digits+1],0);
|
||||
char *p;
|
||||
p = &word[n_digits+1];
|
||||
|
||||
p += utf8_in(&next_char,p,0);
|
||||
if((langopts.numbers & NUM_NOPAUSE) && (next_char == ' '))
|
||||
utf8_in(&next_char,p,0);
|
||||
|
||||
if(!iswalpha(next_char))
|
||||
strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc.
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#define phLONG 0x1000
|
||||
#define phAPPENDPH 0x2000 // always insert another phoneme (link_out) after this one
|
||||
#define phBRKAFTER 0x4000 // [*] add a post-pause
|
||||
#define phBEFOREPAUSE 0x8000 // replace with the link_out phoneme if the next phoneme is a pause
|
||||
|
||||
#define phALTERNATIVE 0x0c00 // bits 10,11 specifying use of alternative_ph
|
||||
#define phBEFOREVOWEL 0x0000
|
||||
|
||||
+23
-18
@@ -383,10 +383,10 @@ void Translator::MakePhonemeList(int post_pause, int start_sentence)
|
||||
}
|
||||
}
|
||||
|
||||
alternative = 0;
|
||||
|
||||
if(ph->alternative_ph > 0)
|
||||
{
|
||||
alternative = 0;
|
||||
|
||||
switch(ph->phflags & phALTERNATIVE)
|
||||
{
|
||||
// This phoneme changes if vowel follows, or doesn't follow, depending on its phNOTFOLLOWS flag
|
||||
@@ -405,25 +405,30 @@ void Translator::MakePhonemeList(int post_pause, int start_sentence)
|
||||
alternative = ph->alternative_ph;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(ph->phflags & phBEFOREPAUSE)
|
||||
{
|
||||
if(next->type == phPAUSE)
|
||||
alternative = ph->link_out; // replace with the link_out phoneme
|
||||
}
|
||||
|
||||
if(alternative == 1)
|
||||
continue; // NULL phoneme, discard
|
||||
if(alternative == 1)
|
||||
continue; // NULL phoneme, discard
|
||||
|
||||
if(alternative > 1)
|
||||
if(alternative > 1)
|
||||
{
|
||||
PHONEME_TAB *ph2;
|
||||
ph2 = ph;
|
||||
ph = phoneme_tab[alternative];
|
||||
|
||||
if(ph->type == phVOWEL)
|
||||
{
|
||||
PHONEME_TAB *ph2;
|
||||
ph2 = ph;
|
||||
ph = phoneme_tab[alternative];
|
||||
|
||||
if(ph->type == phVOWEL)
|
||||
{
|
||||
plist2->synthflags |= SFLAG_SYLLABLE;
|
||||
if(ph2->type != phVOWEL)
|
||||
plist2->stress = 0; // change from non-vowel to vowel, make sure it's unstressed
|
||||
}
|
||||
else
|
||||
plist2->synthflags &= ~SFLAG_SYLLABLE;
|
||||
plist2->synthflags |= SFLAG_SYLLABLE;
|
||||
if(ph2->type != phVOWEL)
|
||||
plist2->stress = 0; // change from non-vowel to vowel, make sure it's unstressed
|
||||
}
|
||||
else
|
||||
plist2->synthflags &= ~SFLAG_SYLLABLE;
|
||||
}
|
||||
|
||||
if(langopts.param[LOPT_REDUCE_T])
|
||||
@@ -547,7 +552,7 @@ void Translator::MakePhonemeList(int post_pause, int start_sentence)
|
||||
|
||||
next2 = phoneme_tab[(plist2+2)->phcode];
|
||||
|
||||
if((insert_ph == 0) && (ph->link_out != 0) && (((plist2+1)->synthflags & SFLAG_EMBEDDED)==0))
|
||||
if((insert_ph == 0) && (ph->link_out != 0) && !(ph->phflags && phBEFOREPAUSE) && (((plist2+1)->synthflags & SFLAG_EMBEDDED)==0))
|
||||
{
|
||||
if(ph->phflags & phAPPENDPH)
|
||||
{
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ static const unsigned short punct_chars[] = {',','.','?','!',':',';',
|
||||
|
||||
// indexed by (entry num. in punct_chars) + 1
|
||||
// bits 0-7 pause x 10mS, bits 12-14 intonation type, bit 15 don't need following space or bracket
|
||||
static const unsigned short punct_attributes [] = { 0,
|
||||
static const unsigned int punct_attributes [] = { 0,
|
||||
CLAUSE_COMMA, CLAUSE_PERIOD, CLAUSE_QUESTION, CLAUSE_EXCLAMATION, CLAUSE_COLON, CLAUSE_SEMICOLON,
|
||||
CLAUSE_SEMICOLON, // en-dash
|
||||
CLAUSE_SEMICOLON, // em-dash
|
||||
|
||||
+131
-3
@@ -50,12 +50,20 @@
|
||||
|
||||
|
||||
|
||||
extern void Write4Bytes(FILE *f, int value);
|
||||
char path_home[N_PATH_HOME]; // this is the espeak-data directory
|
||||
|
||||
char wavefile[120];
|
||||
char filetype[5];
|
||||
char wavefile[200];
|
||||
int (* uri_callback)(int, const char *, const char *) = NULL;
|
||||
int (* phoneme_callback)(const char *) = NULL;
|
||||
|
||||
FILE *f_wave = NULL;
|
||||
int quiet = 0;
|
||||
unsigned int samples_total = 0;
|
||||
unsigned int samples_split = 0;
|
||||
unsigned int wavefile_count = 0;
|
||||
int end_of_sentence = 0;
|
||||
|
||||
static const char *help_text =
|
||||
"\nspeak [options] [\"<words>\"]\n\n"
|
||||
@@ -216,12 +224,111 @@ static void PitchAdjust(int pitch_adjustment)
|
||||
} // end of PitchAdjustment
|
||||
|
||||
|
||||
|
||||
|
||||
static int OpenWaveFile(const char *path, int rate)
|
||||
//=================================================
|
||||
{
|
||||
// Set the length of 0x7fffffff for --stdout
|
||||
// This will be changed to the correct length for -w (write to file)
|
||||
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, 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);
|
||||
|
||||
if(strcmp(path,"stdout")==0)
|
||||
f_wave = stdout;
|
||||
else
|
||||
f_wave = fopen(path,"wb");
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(wave_hdr,1,24,f_wave);
|
||||
Write4Bytes(f_wave,rate);
|
||||
Write4Bytes(f_wave,rate * 2);
|
||||
fwrite(&wave_hdr[32],1,12,f_wave);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
} // end of OpenWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
static void CloseWaveFile()
|
||||
//=========================
|
||||
{
|
||||
unsigned int pos;
|
||||
|
||||
if((f_wave == NULL) || (f_wave == stdout))
|
||||
return;
|
||||
|
||||
fflush(f_wave);
|
||||
pos = ftell(f_wave);
|
||||
|
||||
fseek(f_wave,4,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 8);
|
||||
|
||||
fseek(f_wave,40,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 44);
|
||||
|
||||
|
||||
fclose(f_wave);
|
||||
f_wave = NULL;
|
||||
|
||||
} // end of CloseWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
|
||||
{//======================================================================================
|
||||
// Do nothing in the command-line version.
|
||||
if(type == 2)
|
||||
end_of_sentence = 1;
|
||||
} // end of MarkerEvent
|
||||
|
||||
|
||||
static int WavegenFile(void)
|
||||
{//=========================
|
||||
int finished;
|
||||
unsigned char wav_outbuf[512];
|
||||
char fname[210];
|
||||
|
||||
out_ptr = out_start = wav_outbuf;
|
||||
out_end = wav_outbuf + sizeof(wav_outbuf);
|
||||
|
||||
finished = WavegenFill(0);
|
||||
|
||||
if(f_wave == NULL)
|
||||
{
|
||||
sprintf(fname,"%s_%.2d%s",wavefile,++wavefile_count,filetype);
|
||||
if(OpenWaveFile(fname, samplerate) != 0)
|
||||
return(1);
|
||||
}
|
||||
|
||||
if(end_of_sentence)
|
||||
{
|
||||
end_of_sentence = 0;
|
||||
if(samples_total > samples_split)
|
||||
{
|
||||
CloseWaveFile();
|
||||
samples_total = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
samples_total += (out_ptr - wav_outbuf)/2;
|
||||
fwrite(wav_outbuf, 1, out_ptr - wav_outbuf, f_wave);
|
||||
}
|
||||
return(finished);
|
||||
} // end of WavegenFile
|
||||
|
||||
|
||||
|
||||
static void init_path(char *argv0)
|
||||
{//===============================
|
||||
@@ -359,6 +466,7 @@ int main (int argc, char **argv)
|
||||
{"punct", optional_argument, 0, 0x103},
|
||||
{"voices", optional_argument, 0, 0x104},
|
||||
{"stdout", no_argument, 0, 0x105},
|
||||
{"split", optional_argument, 0, 0x106},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -376,7 +484,6 @@ int main (int argc, char **argv)
|
||||
int amp = 100; // default
|
||||
int wordgap = 0;
|
||||
int speaking = 0;
|
||||
int quiet = 0;
|
||||
int flag_stdin = 0;
|
||||
int flag_compile = 0;
|
||||
int pitch_adjustment = 50;
|
||||
@@ -559,6 +666,13 @@ int main (int argc, char **argv)
|
||||
DisplayVoices(stdout,optarg2);
|
||||
exit(0);
|
||||
|
||||
|
||||
case 0x106: // -- split
|
||||
if(optarg2 == NULL)
|
||||
samples_split = 30; // default 30 minutes
|
||||
else
|
||||
samples_split = atoi(optarg2);
|
||||
break;
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
@@ -650,6 +764,20 @@ int main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
// write sound output to a WAV file
|
||||
samples_split = (samplerate * samples_split) * 60;
|
||||
|
||||
if(samples_split)
|
||||
{
|
||||
// don't open the wav file until we start generating speech
|
||||
char *extn;
|
||||
extn = strrchr(wavefile,'.');
|
||||
if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4))
|
||||
{
|
||||
strcpy(filetype,extn);
|
||||
*extn = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(OpenWaveFile(wavefile,samplerate) != 0)
|
||||
{
|
||||
fprintf(stderr,"Can't write to output file '%s'\n'",wavefile);
|
||||
@@ -671,7 +799,7 @@ int main (int argc, char **argv)
|
||||
SpeakNextClause(NULL,NULL,1);
|
||||
}
|
||||
|
||||
CloseWaveFile(samplerate);
|
||||
CloseWaveFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ typedef enum {
|
||||
espeakEVENT_SENTENCE, // Start of sentence
|
||||
espeakEVENT_MARK, // Mark
|
||||
espeakEVENT_PLAY, // Audio element
|
||||
espeakEVENT_END, // End of sentence
|
||||
espeakEVENT_END, // End of sentence or clause
|
||||
espeakEVENT_MSG_TERMINATED, // End of message
|
||||
espeakEVENT_PHONEME // Phoneme, if enabled in espeak_Initialize()
|
||||
} espeak_EVENT_TYPE;
|
||||
|
||||
@@ -57,12 +57,14 @@ extern void RiscosOpenSound();
|
||||
extern int WcmdqUsed();
|
||||
extern void FreePhData();
|
||||
extern void FreeDictionary();
|
||||
extern void Write4Bytes(FILE *f, int value);
|
||||
|
||||
extern int wcmdq_head;
|
||||
extern int wcmdq_tail;
|
||||
extern int current_source_index;
|
||||
|
||||
FILE *f_text;
|
||||
FILE *f_wave = NULL;
|
||||
int (* uri_callback)(int, const char *, const char *) = NULL;
|
||||
int (* phoneme_callback)(const char *) = NULL;
|
||||
|
||||
@@ -272,12 +274,90 @@ void Free(void **ptr)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
static int OpenWaveFile(const char *path, int rate)
|
||||
//=================================================
|
||||
{
|
||||
// Set the length of 0x7fffffff for --stdout
|
||||
// This will be changed to the correct length for -w (write to file)
|
||||
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, 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);
|
||||
|
||||
if(strcmp(path,"stdout")==0)
|
||||
f_wave = stdout;
|
||||
else
|
||||
f_wave = fopen(path,"wb");
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(wave_hdr,1,24,f_wave);
|
||||
Write4Bytes(f_wave,rate);
|
||||
Write4Bytes(f_wave,rate * 2);
|
||||
fwrite(&wave_hdr[32],1,12,f_wave);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
} // end of OpenWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
static void CloseWaveFile(int rate)
|
||||
//=================================
|
||||
{
|
||||
unsigned int pos;
|
||||
|
||||
if((f_wave == NULL) || (f_wave == stdout))
|
||||
return;
|
||||
|
||||
fflush(f_wave);
|
||||
pos = ftell(f_wave);
|
||||
|
||||
fseek(f_wave,4,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 8);
|
||||
|
||||
fseek(f_wave,40,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 44);
|
||||
|
||||
|
||||
fclose(f_wave);
|
||||
f_wave = NULL;
|
||||
|
||||
} // end of CloseWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
|
||||
{//======================================================================================
|
||||
// Do nothing in the command-line version.
|
||||
} // end of MarkerEvent
|
||||
|
||||
|
||||
static int WavegenFile(void)
|
||||
{//=========================
|
||||
int finished;
|
||||
unsigned char wav_outbuf[1024];
|
||||
|
||||
out_ptr = out_start = wav_outbuf;
|
||||
out_end = wav_outbuf + sizeof(wav_outbuf);
|
||||
|
||||
finished = WavegenFill(0);
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(wav_outbuf, 1, out_ptr - wav_outbuf, f_wave);
|
||||
}
|
||||
return(finished);
|
||||
} // end of WavegenFile
|
||||
|
||||
|
||||
|
||||
|
||||
void FillSoundBuf(int size)
|
||||
|
||||
+24
-2
@@ -36,6 +36,9 @@
|
||||
|
||||
int SpeakNextClause(FILE *f_text, const void *text_in, int control);
|
||||
extern void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2);
|
||||
extern int Wavegen();
|
||||
extern void CloseWaveFile2();
|
||||
extern FILE *f_wave;
|
||||
|
||||
static int frame_width;
|
||||
|
||||
@@ -96,6 +99,25 @@ static void PeaksZero(peak_t *sp, peak_t *zero)
|
||||
} // end of PeaksZero
|
||||
|
||||
|
||||
|
||||
void MakeWaveFile()
|
||||
{//================
|
||||
int result=1;
|
||||
unsigned char wav_outbuf[1024];
|
||||
|
||||
while(result != 0)
|
||||
{
|
||||
out_ptr = out_start = wav_outbuf;
|
||||
out_end = &wav_outbuf[sizeof(wav_outbuf)];
|
||||
result = Wavegen();
|
||||
if(f_wave != NULL)
|
||||
fwrite(wav_outbuf, 1, out_ptr - wav_outbuf, f_wave);
|
||||
}
|
||||
} // end of MakeWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
SpectSeq::SpectSeq(int n)
|
||||
{//======================
|
||||
numframes = n;
|
||||
@@ -1004,7 +1026,7 @@ void SpectSeq::MakeWave(int start, int end, PitchEnvelope &pitch)
|
||||
SetSynth_mS(30,peaks2,peaks0);
|
||||
MakeWaveFile();
|
||||
|
||||
CloseWaveFile(samplerate);
|
||||
CloseWaveFile2();
|
||||
PlayWavFile(fname_speech);
|
||||
|
||||
} // end of SpectSeq::MakeWave
|
||||
@@ -1085,7 +1107,7 @@ void SpectFrame::MakeWave(int control, PitchEnvelope &pitche, int amplitude, int
|
||||
#endif
|
||||
}
|
||||
|
||||
CloseWaveFile(samplerate);
|
||||
CloseWaveFile2();
|
||||
PlayWavFile(fname_speech);
|
||||
|
||||
} // end of SpectFrame::MakeWaveFrame
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@
|
||||
#include "translate.h"
|
||||
#include "wave.h"
|
||||
|
||||
const char *version_string = "1.30.05 07.Jan.08";
|
||||
const int version_phdata = 0x013005;
|
||||
const char *version_string = "1.30.10 13.Jan.08";
|
||||
const int version_phdata = 0x013010;
|
||||
|
||||
int option_device_number = -1;
|
||||
|
||||
|
||||
@@ -204,10 +204,7 @@ int WavegenOpenSound();
|
||||
int WavegenCloseSound();
|
||||
int WavegenInitSound();
|
||||
void WavegenInit(int rate, int wavemult_fact);
|
||||
int OpenWaveFile(const char *path, int rate);
|
||||
void CloseWaveFile(int rate);
|
||||
float polint(float xa[],float ya[],int n,float x);
|
||||
int WavegenFile(void);
|
||||
int WavegenFill(int fill_zeros);
|
||||
void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr);
|
||||
|
||||
|
||||
+19
-1
@@ -277,7 +277,7 @@ Translator *SelectTranslator(const char *name)
|
||||
tr->langopts.stress_flags = 0x0024; // don't use secondary stress
|
||||
tr->langopts.param[LOPT_IT_LENGTHEN] = 1; // remove lengthen indicator from unstressed syllables
|
||||
|
||||
tr->langopts.numbers = 0x1509;
|
||||
tr->langopts.numbers = 0x1509 + NUM_NOPAUSE | NUM_ROMAN;
|
||||
SetLetterVowel(tr,'y');
|
||||
}
|
||||
break;
|
||||
@@ -633,6 +633,24 @@ SetLengthMods(tr,3); // all equal
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case L('t','h'): // Thai
|
||||
{
|
||||
static const short stress_lengths_th[8] = {230,150, 230,230, 230,0, 230,250};
|
||||
static const unsigned char stress_amps_th[] = {22,16, 22,22, 22,22, 22,22 };
|
||||
|
||||
tr = new Translator;
|
||||
SetupTranslator(tr,stress_lengths_th,stress_amps_th);
|
||||
|
||||
tr->langopts.stress_rule = 0; // stress on final syllable of a "word"
|
||||
tr->langopts.stress_flags = 1; // don't automatically set diminished stress (may be set in the intonation module)
|
||||
tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
|
||||
tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
|
||||
// tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
|
||||
tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
|
||||
}
|
||||
break;
|
||||
|
||||
case L('t','r'): // Turkish
|
||||
{
|
||||
static const unsigned char stress_amps_tr[8] = {16,16, 20,20, 20,24, 24,22 };
|
||||
|
||||
+6
-2
@@ -1212,8 +1212,11 @@ int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int ne
|
||||
|
||||
if((option_sayas & 0xf0) == 0x10)
|
||||
{
|
||||
// SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
|
||||
pre_pause += 4;
|
||||
if(!(word_flags & FLAG_FIRST_WORD))
|
||||
{
|
||||
// SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
|
||||
pre_pause += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if(word_flags & FLAG_FIRST_UPPER)
|
||||
@@ -2251,6 +2254,7 @@ if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_ou
|
||||
words[word_count].pre_pause = 8;
|
||||
if(word_count > 0)
|
||||
words[word_count-1].flags |= FLAG_LAST_WORD;
|
||||
words[0].flags |= FLAG_FIRST_WORD;
|
||||
|
||||
for(ix=0; ix<word_count; ix++)
|
||||
{
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
#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_FIRST_WORD 0x200 // first word in clause
|
||||
#define FLAG_DONT_SWITCH_TRANSLATOR 0x1000
|
||||
#define FLAG_SUFFIX_REMOVED 0x2000
|
||||
#define FLAG_HYPHEN_AFTER 0x4000
|
||||
@@ -308,6 +309,7 @@ typedef struct {
|
||||
|
||||
#define NUM_ROMAN 0x20000
|
||||
#define NUM_ROMAN_UC 0x40000
|
||||
#define NUM_NOPAUSE 0x80000
|
||||
|
||||
// bits0-1=which numbers routine to use.
|
||||
// bit2= thousands separator must be space
|
||||
@@ -325,6 +327,7 @@ typedef struct {
|
||||
// bit16=dot after number indicates ordinal
|
||||
// bit17=recognize roman numbers
|
||||
// bit18=Roman numbers only if upper case
|
||||
// bit19=don't add pause after a number
|
||||
int numbers;
|
||||
|
||||
// bits 1-4 use variant form of numbers before thousands,millions,etc.
|
||||
|
||||
+78
-9
@@ -47,6 +47,7 @@
|
||||
TranslDlg *transldlg = NULL;
|
||||
extern char *speech_to_phonemes(char *data, char *phout);
|
||||
extern ProsodyDisplay *prosodycanvas;
|
||||
extern void Write4Bytes(FILE *f, int value);
|
||||
|
||||
BEGIN_EVENT_TABLE(TranslDlg, wxPanel)
|
||||
EVT_BUTTON(T_TRANSLATE,TranslDlg::OnCommand)
|
||||
@@ -55,6 +56,8 @@ BEGIN_EVENT_TABLE(TranslDlg, wxPanel)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
FILE *f_wave = NULL;
|
||||
|
||||
|
||||
class IPATextCtrl : public wxTextCtrl
|
||||
{
|
||||
@@ -157,16 +160,82 @@ char *WavFileName(void)
|
||||
}
|
||||
|
||||
|
||||
int OpenWaveFile2(const char *fname)
|
||||
{//=================================
|
||||
int result;
|
||||
|
||||
if((result = OpenWaveFile(fname, samplerate)) != 0)
|
||||
int OpenWaveFile2(const char *path)
|
||||
/*********************************/
|
||||
{
|
||||
// Set the length of 0x7fffffff for --stdout
|
||||
// This will be changed to the correct length for -w (write to file)
|
||||
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, 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);
|
||||
|
||||
if(strcmp(path,"stdout")==0)
|
||||
f_wave = stdout;
|
||||
else
|
||||
f_wave = fopen(path,"wb");
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
wxLogStatus(_T("Can't write to WAV file: '"+wxString(fname,wxConvLocal))+_T("'"));
|
||||
fwrite(wave_hdr,1,24,f_wave);
|
||||
Write4Bytes(f_wave,samplerate);
|
||||
Write4Bytes(f_wave,samplerate * 2);
|
||||
fwrite(&wave_hdr[32],1,12,f_wave);
|
||||
return(0);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
wxLogStatus(_T("Can't write to WAV file: '"+wxString(path,wxConvLocal))+_T("'"));
|
||||
return(1);
|
||||
} // end of OpenWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
void CloseWaveFile2()
|
||||
/******************/
|
||||
{
|
||||
unsigned int pos;
|
||||
|
||||
if((f_wave == NULL) || (f_wave == stdout))
|
||||
return;
|
||||
|
||||
fflush(f_wave);
|
||||
pos = ftell(f_wave);
|
||||
|
||||
fseek(f_wave,4,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 8);
|
||||
|
||||
fseek(f_wave,40,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 44);
|
||||
|
||||
|
||||
fclose(f_wave);
|
||||
f_wave = NULL;
|
||||
|
||||
} // end of CloseWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
int WavegenFile2(void)
|
||||
{//==================
|
||||
int finished;
|
||||
unsigned char wav_outbuf[1024];
|
||||
|
||||
out_ptr = out_start = wav_outbuf;
|
||||
out_end = wav_outbuf + sizeof(wav_outbuf);
|
||||
|
||||
finished = WavegenFill(0);
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(wav_outbuf, 1, out_ptr-wav_outbuf, f_wave);
|
||||
}
|
||||
return(finished);
|
||||
} // end of WavegenFile
|
||||
|
||||
|
||||
void MakeWave2(PHONEME_LIST *p, int n_phonemes)
|
||||
@@ -183,13 +252,13 @@ void MakeWave2(PHONEME_LIST *p, int n_phonemes)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
result = WavegenFile();
|
||||
result = WavegenFile2();
|
||||
if(result != 0)
|
||||
break;
|
||||
Generate(p,&n_ph,1);
|
||||
}
|
||||
|
||||
CloseWaveFile(samplerate);
|
||||
CloseWaveFile2();
|
||||
PlayWavFile(fname_speech);
|
||||
|
||||
} // end of MakeWave2
|
||||
|
||||
+3
-103
@@ -137,7 +137,6 @@ unsigned char *out_ptr;
|
||||
unsigned char *out_start;
|
||||
unsigned char *out_end;
|
||||
int outbuf_size = 0;
|
||||
static unsigned char outbuf[1024]; // used when writing to file
|
||||
|
||||
// the queue of operations passed to wavegen from sythesize
|
||||
long wcmdq[N_WCMDQ][4];
|
||||
@@ -151,7 +150,7 @@ static int embedded_max[N_EMBEDDED_VALUES] = {0,0x7fff,360,300,99,99,99, 0,3
|
||||
#define N_CALLBACK_IX N_WAV_BUF-2 // adjust this delay to match display with the currently spoken word
|
||||
int current_source_index=0;
|
||||
|
||||
FILE *f_wave = NULL;
|
||||
extern FILE *f_wave;
|
||||
|
||||
#if (USE_PORTAUDIO == 18)
|
||||
static PortAudioStream *pa_stream=NULL;
|
||||
@@ -1114,8 +1113,8 @@ int ApplyBreath(void)
|
||||
|
||||
|
||||
|
||||
static int Wavegen()
|
||||
{//=================
|
||||
int Wavegen()
|
||||
{//==========
|
||||
unsigned short waveph;
|
||||
unsigned short theta;
|
||||
int total;
|
||||
@@ -1761,88 +1760,6 @@ void Write4Bytes(FILE *f, int value)
|
||||
|
||||
|
||||
|
||||
int OpenWaveFile(const char *path, int rate)
|
||||
/******************************************/
|
||||
{
|
||||
// Set the length of 0x7fffffff for --stdout
|
||||
// This will be changed to the correct length for -w (write to file)
|
||||
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, 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);
|
||||
|
||||
wavephase = 0x7fffffff;
|
||||
|
||||
if(strcmp(path,"stdout")==0)
|
||||
f_wave = stdout;
|
||||
else
|
||||
f_wave = fopen(path,"wb");
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(wave_hdr,1,24,f_wave);
|
||||
Write4Bytes(f_wave,rate);
|
||||
Write4Bytes(f_wave,rate * 2);
|
||||
fwrite(&wave_hdr[32],1,12,f_wave);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
} // end of OpenWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
void CloseWaveFile(int rate)
|
||||
/******************/
|
||||
{
|
||||
unsigned int pos;
|
||||
|
||||
if(f_log != NULL)
|
||||
{
|
||||
fclose(f_log);
|
||||
f_log = NULL;
|
||||
}
|
||||
|
||||
if((f_wave == NULL) || (f_wave == stdout))
|
||||
return;
|
||||
|
||||
fflush(f_wave);
|
||||
pos = ftell(f_wave);
|
||||
|
||||
fseek(f_wave,4,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 8);
|
||||
|
||||
fseek(f_wave,40,SEEK_SET);
|
||||
Write4Bytes(f_wave,pos - 44);
|
||||
|
||||
|
||||
fclose(f_wave);
|
||||
f_wave = NULL;
|
||||
|
||||
} // end of CloseWaveFile
|
||||
|
||||
|
||||
|
||||
void MakeWaveFile()
|
||||
{//================
|
||||
int result=1;
|
||||
|
||||
while(result != 0)
|
||||
{
|
||||
out_ptr = out_start = outbuf;
|
||||
out_end = &outbuf[sizeof(outbuf)];
|
||||
result = Wavegen();
|
||||
if(f_wave != NULL)
|
||||
fwrite(outbuf,1,out_ptr-outbuf,f_wave);
|
||||
}
|
||||
} // end of MakeWaveFile
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int WavegenFill(int fill_zeros)
|
||||
{//============================
|
||||
@@ -1965,20 +1882,3 @@ int WavegenFill(int fill_zeros)
|
||||
} // end of WavegenFill
|
||||
|
||||
|
||||
|
||||
int WavegenFile(void)
|
||||
{//==================
|
||||
int finished;
|
||||
|
||||
out_ptr = out_start = outbuf;
|
||||
out_end = outbuf + sizeof(outbuf);
|
||||
|
||||
finished = WavegenFill(0);
|
||||
|
||||
if(f_wave != NULL)
|
||||
{
|
||||
fwrite(outbuf,1,out_ptr-outbuf,f_wave);
|
||||
}
|
||||
return(finished);
|
||||
} // end of WavegenFile
|
||||
|
||||
|
||||
Reference in New Issue
Block a user