Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent compile-phonemes use of phontab, en_dict #930

Merged
merged 2 commits into from May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile.am
Expand Up @@ -484,10 +484,16 @@ dictsource/%_emoji:
dictsource/%_extra:
touch $@

# NOTE: % (pattern) rules are GNU make specific we can extract the 'stem' that
# matched the % in the target ($@) using $(*F) (which isn't GNU make specific,
# just this interpretation is.)
#
# The rm $@ stops espeak-ng trying to load the old dictionary when it is run
# (at the cost of a spurious error message.)
espeak-ng-data/%_dict: src/espeak-ng phsource/phonemes.stamp
@echo " DICT $@"
@cd dictsource && ESPEAK_DATA_PATH=$(CURDIR) LD_LIBRARY_PATH=../src:${LD_LIBRARY_PATH} ../src/espeak-ng \
--compile=`echo $@ | sed -e 's,espeak-ng-data/,,g' -e 's,_dict,,g'` && cd ..
rm -f $@
cd dictsource && ESPEAK_DATA_PATH=$(CURDIR) ../src/espeak-ng --compile="$(*F)"

dictionaries: \
espeak-ng-data/af_dict \
Expand Down
4 changes: 2 additions & 2 deletions src/libespeak-ng/compiledata.c
Expand Up @@ -1853,7 +1853,7 @@ static PHONEME_TAB_LIST *FindPhonemeTable(const char *string)
if (strcmp(phoneme_tab_list2[ix].name, string) == 0)
return &phoneme_tab_list2[ix];
}
error("Unknown phoneme table: '%s'", string);
error("compile: unknown phoneme table: '%s'", string);
return NULL;
}

Expand Down Expand Up @@ -2541,7 +2541,7 @@ espeak_ng_CompilePhonemeDataPath(long rate,

samplerate_native = samplerate = rate;
LoadPhData(NULL, NULL);
if (LoadVoice("", 0) == NULL)
if (LoadVoice("", 8/*compiling phonemes*/) == NULL)
return ENS_VOICE_NOT_FOUND;

WavegenInit(rate, 0);
Expand Down
33 changes: 25 additions & 8 deletions src/libespeak-ng/voices.c
Expand Up @@ -477,6 +477,9 @@ voice_t *LoadVoice(const char *vname, int control)
// bit 1 1 = change tone only, not language
// bit 2 1 = don't report error on LoadDictionary
// bit 4 1 = vname = full path
// bit 8 1 = INTERNAL: compiling phonemes; do not try to
// load the phoneme table
// bit 16 1 = UNDOCUMENTED

FILE *f_voice = NULL;
char *p;
Expand Down Expand Up @@ -526,7 +529,7 @@ voice_t *LoadVoice(const char *vname, int control)
if (GetFileLength(buf) <= 0)
return NULL;
} else {
if (voicename[0] == 0)
if (voicename[0] == 0 && !(control & 8)/*compiling phonemes*/)
strcpy(voicename, ESPEAKNG_DEFAULT_VOICE);

sprintf(path_voices, "%s%cvoices%c", path_home, PATHSEP, PATHSEP);
Expand All @@ -540,7 +543,11 @@ voice_t *LoadVoice(const char *vname, int control)

f_voice = fopen(buf, "r");

language_type = "en"; // default
if (!(control & 8)/*compiling phonemes*/)
language_type = "en"; // default
else
language_type = "";

if (f_voice == NULL) {
if (control & 3)
return NULL; // can't open file
Expand Down Expand Up @@ -867,18 +874,28 @@ voice_t *LoadVoice(const char *vname, int control)
if (tone_only)
new_translator = translator;
else {
if ((ix = SelectPhonemeTableName(phonemes_name)) < 0) {
if (!!(control & 8/*compiling phonemes*/)) {
/* Set by espeak_ng_CompilePhonemeDataPath when it
* calls LoadVoice("", 8) to set up a dummy(?) voice.
* As phontab may not yet exist this avoids the spurious
* error message and guarantees consistent results by
* not actually reading a potentially bogus phontab...
*/
ix = 0;
} else if ((ix = SelectPhonemeTableName(phonemes_name)) < 0) {
fprintf(stderr, "Unknown phoneme table: '%s'\n", phonemes_name);
ix = 0;
}
voice->phoneme_tab_ix = ix;
new_translator->phoneme_tab_ix = ix;
new_translator->dict_min_size = dict_min;
LoadDictionary(new_translator, new_dictionary, control & 4);
if (dictionary_name[0] == 0) {
DeleteTranslator(new_translator);
return NULL; // no dictionary loaded
}
if (!(control & 8/*compiling phonemes*/)) {
LoadDictionary(new_translator, new_dictionary, control & 4);
if (dictionary_name[0] == 0) {
DeleteTranslator(new_translator);
return NULL; // no dictionary loaded
}
}

new_translator->dict_condition = conditional_rules;

Expand Down