mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-10 08:13:55 +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:
+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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user