Support deterministic PRNG mode in CLI

This commit is contained in:
Yury Popov
2022-11-15 10:00:17 +03:00
parent 09cdf8ce66
commit 24892aae06
+11 -1
View File
@@ -79,6 +79,7 @@ static const char *help_text =
"-x\t Write phoneme mnemonics to stdout\n" "-x\t Write phoneme mnemonics to stdout\n"
"-X\t Write phonemes mnemonics and translation trace to stdout\n" "-X\t Write phonemes mnemonics and translation trace to stdout\n"
"-z\t No final sentence pause at the end of the text\n" "-z\t No final sentence pause at the end of the text\n"
"-D\t Enable deterministic random mode\n"
"--compile=<voice name>\n" "--compile=<voice name>\n"
"\t Compile pronunciation rules and dictionary from the current\n" "\t Compile pronunciation rules and dictionary from the current\n"
"\t directory. <voice name> specifies the language\n" "\t directory. <voice name> specifies the language\n"
@@ -353,6 +354,7 @@ int main(int argc, char **argv)
int phoneme_options = 0; int phoneme_options = 0;
int option_linelength = 0; int option_linelength = 0;
int option_waveout = 0; int option_waveout = 0;
bool deterministic = 0;
espeak_VOICE voice_select; espeak_VOICE voice_select;
char filename[200]; char filename[200];
@@ -368,7 +370,7 @@ int main(int argc, char **argv)
option_punctlist[0] = 0; option_punctlist[0] = 0;
while (true) { while (true) {
c = getopt_long(argc, argv, "a:b:d:f:g:hk:l:mp:qs:v:w:xXz", c = getopt_long(argc, argv, "a:b:Dd:f:g:hk:l:mp:qs:v:w:xXz",
long_options, &option_index); long_options, &option_index);
// Detect the end of the options. // Detect the end of the options.
@@ -388,6 +390,9 @@ int main(int argc, char **argv)
case 'd': case 'd':
strncpy0(devicename, optarg2, sizeof(devicename)); strncpy0(devicename, optarg2, sizeof(devicename));
break; break;
case 'D':
deterministic = 1;
break;
case 'h': case 'h':
printf("\n"); printf("\n");
PrintVersion(); PrintVersion();
@@ -583,6 +588,11 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (deterministic) {
// Set random generator state to well-known
espeak_ng_SetRandSeed(1);
}
if (option_waveout || quiet) { if (option_waveout || quiet) {
// writing to a file (or no output), we can use synchronous mode // writing to a file (or no output), we can use synchronous mode
result = espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, 0, devicename[0] ? devicename : NULL); result = espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, 0, devicename[0] ? devicename : NULL);