From 3857b83c19af0bd4d4ea8f44f9e9baf6167f0837 Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Fri, 28 Oct 2022 12:27:52 +0300 Subject: [PATCH 01/16] Respect custom N_PATH_HOME definition if passed --- src/libespeak-ng/speech.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libespeak-ng/speech.h b/src/libespeak-ng/speech.h index 01f8ae94..4d2f3684 100644 --- a/src/libespeak-ng/speech.h +++ b/src/libespeak-ng/speech.h @@ -56,19 +56,23 @@ extern "C" #define PLATFORM_WINDOWS #define PATHSEP '\\' -#define N_PATH_HOME 230 +#define N_PATH_HOME_DEF 230 #define NO_VARIADIC_MACROS #else #define PLATFORM_POSIX #define PATHSEP '/' -#define N_PATH_HOME 160 +#define N_PATH_HOME_DEF 160 #define USE_NANOSLEEP #define __cdecl #endif +#ifndef N_PATH_HOME +#define N_PATH_HOME N_PATH_HOME_DEF +#endif + // will look for espeak_data directory here, and also in user's home directory #ifndef PATH_ESPEAK_DATA #define PATH_ESPEAK_DATA "/usr/share/espeak-ng-data" From 16b2406f0688fffd267b53d88e88b79b3cdaf67f Mon Sep 17 00:00:00 2001 From: kirill-jjj Date: Sun, 23 Oct 2022 22:53:39 +0500 Subject: [PATCH 02/16] =?UTF-8?q?Russian:=20fix=20for=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dictsource/ru_rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dictsource/ru_rules b/dictsource/ru_rules index c026463f..9effff22 100644 --- a/dictsource/ru_rules +++ b/dictsource/ru_rules @@ -150,7 +150,7 @@ р) д (ц // Silent D(не произносимая д) мо) де (м dE% н) де (кс dE2 // яндекс, индекс/ yandex, index - мо) де (л dE + _мо) де (л dE _мо) де (лир dE% мо) де (льер dE% мо) де (лист dE% From 1bb3109181b85f718d755dcd765ead94281765ec Mon Sep 17 00:00:00 2001 From: kirill-jjj Date: Sun, 23 Oct 2022 22:59:40 +0500 Subject: [PATCH 03/16] Russian: add a new variant, Russian (classic) --- dictsource/ru_list | 11 +++++++++++ dictsource/ru_rules | 5 +++-- espeak-ng-data/lang/zle/ru-cl | 6 ++++++ tests/language-phonemes.test | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 espeak-ng-data/lang/zle/ru-cl diff --git a/dictsource/ru_list b/dictsource/ru_list index 52033a9f..34acd915 100644 --- a/dictsource/ru_list +++ b/dictsource/ru_list @@ -2,6 +2,7 @@ // Numbers _0 n'ojl; +?3 _0 n'ol^ _1 V#d;'in _1f V#dn'a _2 dv'A @@ -72,6 +73,7 @@ _0M10 nVn;il;i'onV#f _0MA10 nVn;il;i'ona _dpt _:'i_: // start of decimal fraction _dpt2 _d;Is;'atYx // end of decimal fraction +_dpt3 _sotyx // end of decimal fraction // symbols _` akts'Ent @@ -124,6 +126,7 @@ _, zVpit'aja из $u // from из $atend // stressed at the end на n@ $u // on +?3 на $u // on над $u от $u // from с s $u // with,from,since @@ -216,6 +219,7 @@ _ж ZE _к kA к kA $atend л El; +?3 л El^ м Em н En_ о o @@ -247,12 +251,14 @@ _с Es // phrases аудиокнига 'Aud;iV#kn;'iga# +?3 аудиокнига 'Aud;iV#kn'iga# (в виду) vv;id'u (в глаза) v||glaz'A (в города) v||gV#rV#d'A (в кому) f||k'omu (во время оно) v'o||v@-r;'em;V||'onV (вряд ли) v@-r;'Atl;I +?3 (вряд ли) v@-r;'Atl^I (всё-таки) fs;'8tVk;I (где-то) gd;'etV (зачем-то) zatS;'emtV @@ -271,11 +277,16 @@ _с Es (мои глаза) mV#'I||glaz'A (на свои места) n@||svV#'I||m;ist'A (наконец-то) nVkV#n;'etstV +?3 (наконец-то) nVkV#n'etstV# (на поводу) n@||pV#vV#d'u (не были) n;'ebyl;I +?3 (не были) n'ebyl;I (не было) n;'ebylV +?3 (не было) n'ebylV (не за что) n;'ezV#StV# +?3 (не за что) n'ezV#StV# (не с чем) n;'estS;im +?3 (не с чем) n'estS;im (одной стороны) V#dn'oj||stV#rV#n'y (от числа) ot||tS;isl'A (по поводу) pV#p'ovV#du diff --git a/dictsource/ru_rules b/dictsource/ru_rules index 9effff22..8c78e18e 100644 --- a/dictsource/ru_rules +++ b/dictsource/ru_rules @@ -150,7 +150,7 @@ р) д (ц // Silent D(не произносимая д) мо) де (м dE% н) де (кс dE2 // яндекс, индекс/ yandex, index - _мо) де (л dE + мо) де (л dE _мо) де (лир dE% мо) де (льер dE% мо) де (лист dE% @@ -244,6 +244,7 @@ л l ?2 л (Y l; л (Y l; +?3 л (Y l^ _дисп) ле lE п) ле (ер lE @@ -261,6 +262,7 @@ н n ?2 н (Y n^ н (Y n; +?3 н (Y n биз) не (с nE интер) не (т nE // интернет, интернетный, интернета... ?????????? _клар) не (т nE @@ -467,7 +469,6 @@ щ (зY Z; щ (з Z; помо) щ (ник S - .group ъ ъ (Y j ?2 ъ (Y _| diff --git a/espeak-ng-data/lang/zle/ru-cl b/espeak-ng-data/lang/zle/ru-cl new file mode 100644 index 00000000..ad100caf --- /dev/null +++ b/espeak-ng-data/lang/zle/ru-cl @@ -0,0 +1,6 @@ +name Russian (Classic) +language ru-cl +replace 03 a a# +dict_min 20000 +speed 95 +dictrules 3 diff --git a/tests/language-phonemes.test b/tests/language-phonemes.test index d1a22978..22e44110 100755 --- a/tests/language-phonemes.test +++ b/tests/language-phonemes.test @@ -118,6 +118,7 @@ test_phwav quc 0c7199d688488c4e71bb7096cd5c9ab518d4b19d "ma na Na pa ta ka ba da test_phwav qya b9b73f37cc0ecb4fb1d30830847123ac53a2bf4a "ma na Na pa ta ka ba da ga fa Ta sa Sa xa ha va Da za Za tSa dZa la ra ja wa t2a t#a d#a z#a r-a z/2a w#a m- n- N- _:_ mI mE ma m0 mV mU mi: mA: mO: mu: m3: mA@ mO@ mo@ mU@ mi@3 mIR mVR mi@ me@ mi m@ m3 me# mI# mI2 meI maI mOI moU maU maa mO2 maI@ maI3 maU@" test_phwav ro 1d4a597446e9c02da47af76ba08bb3b067d55c44 "ma na n^a pa ta ka ba da ga fa Ta sa Sa J^a xa Da tSa la l^a *a Ra ra v#a _:_ ma ma/ me me/ mE mi mo mo/ mu moI" test_phwav ru 20aaefaeb63d1a51af6f997ce74d82dc4dcf0f8c "ma na pa ba ta da tSa dZa tsa dza ca Ja Ca ka ga fa va sa za Sa Za xa Qa ha la ja wa Ra *a _:_ mi me m& my mW mu mo ma m@" +test_phwav ru-cl 20aaefaeb63d1a51af6f997ce74d82dc4dcf0f8c "ma na pa ba ta da tSa dZa tsa dza ca Ja Ca ka ga fa va sa za Sa Za xa Qa ha la ja wa Ra *a _:_ mi me m& my mW mu mo ma m@" test_phwav ru-LV d9e3e425268d7ed140d1bf0e883e4dacc25d7749 "ma na pa ba ta da tSa dZa tsa dza ca Ja Ca ka ga fa va sa za Sa Za xa Qa ha la ja wa Ra *a _:_ mi me m& my mW mu mo ma m@" test_phwav sd e0ce9b04c614df8b34180478f2f87ae58baa95ba "ma na n.a n^a pa t#a t.a tSa ka qa p#a t.#a c#a k#a ba d#a d.a dZa ga b#a d.#a J#a g#a fa sa Sa xa va za Za Qa Ha ra r.a la ja _:_ mI mU me m@ mo mE mV mO ma mi: mu: me: mo: mE: mO: ma: m&: mI~ mi~ mU~ mu~ mU~ me~ mo~ mE~ mV~ mO~ ma~ mAI maU" test_phwav shn e568aca66c2f58fdaf5dda8a67f4d21f05710234 "ma na Ja Na pa p_ha ba ta t_ha da ka k_ha ga ?a fa sa za Ta ha tS;a Ra ja wa la _:_ mi mI mW mu me m@ mo mE ma ma: mO miu meu mEu mau ma:u mWi mui m@i moi mai ma:i mOi maW _:_ ma1 ma2 ma3 ma4 ma5 ma6" From 5ded10cf93bc533c92c5b055a7f39c88f1ab9c0b Mon Sep 17 00:00:00 2001 From: Beqa Gozalishvili Date: Fri, 28 Oct 2022 19:27:01 +0400 Subject: [PATCH 04/16] Add missing compatibility check for older android versions. --- android/src/com/reecedunn/espeak/TtsService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/src/com/reecedunn/espeak/TtsService.java b/android/src/com/reecedunn/espeak/TtsService.java index 63b10716..1af0d9d3 100644 --- a/android/src/com/reecedunn/espeak/TtsService.java +++ b/android/src/com/reecedunn/espeak/TtsService.java @@ -76,7 +76,8 @@ public class TtsService extends TextToSpeechService { @Override public void onCreate() { storageContext = EspeakApp.getStorageContext(); - storageContext.moveSharedPreferencesFrom(this, this.getPackageName() + "_preferences"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + storageContext.moveSharedPreferencesFrom(this, this.getPackageName() + "_preferences"); initializeTtsEngine(); super.onCreate(); } From 5738827dbfd791360a8f77606a0da0699fb1eda0 Mon Sep 17 00:00:00 2001 From: FelipeZanabria <84168997+FelipeZanabria@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:26:33 -0300 Subject: [PATCH 05/16] Update es-419 This fixes the intonation in Latin American Spanish questions, removes the phoneme replacement (T to s) because it is already included in phonemes es_la. It also eliminates the line languaje es 6, because when the voice is in the dialect of Spain and it automatically changes to the dialect of Latin America, it does not return to the dialect of Spain. --- espeak-ng-data/lang/roa/es-419 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espeak-ng-data/lang/roa/es-419 b/espeak-ng-data/lang/roa/es-419 index 0acaa106..236bef0b 100644 --- a/espeak-ng-data/lang/roa/es-419 +++ b/espeak-ng-data/lang/roa/es-419 @@ -1,11 +1,11 @@ name Spanish (Latin America) language es-419 language es-mx 6 -language es 6 phonemes es-la dictrules 2 intonation 2 stressLength 170 200 230 180 0 0 250 280 -replace 00 T s +tunes s6 c6 q6 e6 + From a178ea1b130fb57e9372728ad1068912771d2c5e Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Sat, 29 Oct 2022 15:28:42 +0300 Subject: [PATCH 06/16] Remove system() call from compiledata.c --- src/libespeak-ng/compiledata.c | 62 +++------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 4c692b76..76b88d9c 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -1193,12 +1193,7 @@ static int LoadWavefile(FILE *f, const char *fname) int max = 0; int length; int sr1, sr2; - bool failed; int len; - bool resample_wav = false; - const char *fname2; - char fname_temp[100]; - char msg[120]; int scale_factor = 0; fseek(f, 24, SEEK_SET); @@ -1207,54 +1202,11 @@ static int LoadWavefile(FILE *f, const char *fname) fseek(f, 40, SEEK_SET); if ((sr1 != samplerate_native) || (sr2 != sr1*2)) { - char command[sizeof(path_home)+250]; - - failed = false; - -#ifdef HAVE_MKSTEMP - strcpy(fname_temp, "/tmp/espeakXXXXXX"); - int fd_temp; - if ((fd_temp = mkstemp(fname_temp)) >= 0) - close(fd_temp); -#else - strcpy(fname_temp, tmpnam(NULL)); -#endif - - fname2 = fname; - len = strlen(fname); - if (strcmp(&fname[len-4], ".wav") == 0) { - strcpy(msg, fname); - msg[len-4] = 0; - fname2 = msg; - } - - sprintf(command, "sox \"%s/%s.wav\" -r %d -c1 -t wav %s\n", phsrc, fname2, samplerate_native, fname_temp); - if (system(command) != 0) - failed = true; - - if (failed || (GetFileLength(fname_temp) <= 0)) { - if (resample_fails < 2) - error("Resample command failed: %s", command); - resample_fails++; - - if (sr1 != samplerate_native) - error("Can't resample (%d to %d): %s", sr1, samplerate_native, fname); - else - error("WAV file is not mono: %s", fname); - remove(fname_temp); - return 0; - } - - f = fopen(fname_temp, "rb"); - if (f == NULL) { - error("Can't read temp file: %s", fname_temp); - return 0; - } - if (f_report != NULL) - fprintf(f_report, "resampled %s\n", fname); - resample_count++; - resample_wav = true; - fseek(f, 40, SEEK_SET); // skip past the WAV header, up to before "data length" + if (sr1 != samplerate_native) + error("Can't resample (%d to %d): %s", sr1, samplerate_native, fname); + else + error("WAV file is not mono: %s", fname); + return 0; } displ = ftell(f_phdata); @@ -1325,10 +1277,6 @@ static int LoadWavefile(FILE *f, const char *fname) length++; } - if (resample_wav == true) { - fclose(f); - remove(fname_temp); - } return displ | 0x800000; // set bit 23 to indicate a wave file rather than a spectrum } From ae97fa16b4d2b99afc0a466381dcd733679cae0f Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Fri, 28 Oct 2022 23:18:15 +0300 Subject: [PATCH 07/16] Remove phoneme compile_report stuff --- src/libespeak-ng/compiledata.c | 91 ---------------------------------- 1 file changed, 91 deletions(-) diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 76b88d9c..020c1ab1 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -398,7 +398,6 @@ static FILE *f_phtab; static FILE *f_phcontents; static FILE *f_errors = NULL; static FILE *f_prog_log = NULL; -static FILE *f_report; static FILE *f_in; static int f_in_linenum; @@ -480,81 +479,6 @@ static int ref_sorter(char **a, char **b) return p1->ph_mnemonic - p2->ph_mnemonic; } -static void CompileReport(void) -{ - int ix; - int hash; - int n; - REF_HASH_TAB *p; - REF_HASH_TAB **list; - const char *data_path; - int prev_table; - int procedure_num; - int prev_mnemonic; - - if (f_report == NULL || count_references == 0) - return; - - // make a list of all the references and sort it - list = (REF_HASH_TAB **)malloc((count_references)* sizeof(REF_HASH_TAB *)); - if (list == NULL) - return; - - fprintf(f_report, "\n%d phoneme tables\n", n_phoneme_tabs); - fprintf(f_report, " new total\n"); - for (ix = 0; ix < n_phoneme_tabs; ix++) - fprintf(f_report, "%8s %3d %4d\n", phoneme_tab_list2[ix].name, phoneme_tab_list2[ix].n_phonemes, n_phcodes_list[ix]+1); - fputc('\n', f_report); - - fprintf(f_report, "Data file Used by\n"); - ix = 0; - for (hash = 0; (hash < 256) && (ix < count_references); hash++) { - p = ref_hash_tab[hash]; - while (p != NULL) { - list[ix++] = p; - p = (REF_HASH_TAB *)(p->link); - } - } - n = ix; - qsort((void *)list, n, sizeof(REF_HASH_TAB *), (int (*)(const void *, const void *))ref_sorter); - - data_path = ""; - prev_mnemonic = 0; - prev_table = 0; - for (ix = 0; ix < n; ix++) { - int j = 0; - - if (strcmp(list[ix]->string, data_path) != 0) { - data_path = list[ix]->string; - j = strlen(data_path); - fprintf(f_report, "%s", data_path); - } else if ((list[ix]->ph_table == prev_table) && (list[ix]->ph_mnemonic == prev_mnemonic)) - continue; // same phoneme, don't list twice - - while (j < 14) { - fputc(' ', f_report); // pad filename with spaces - j++; - } - - prev_mnemonic = list[ix]->ph_mnemonic; - if ((prev_mnemonic >> 24) == 'P') { - // a procedure, not a phoneme - procedure_num = atoi(WordToString(prev_mnemonic)); - fprintf(f_report, " %s %s", phoneme_tab_list2[prev_table = list[ix]->ph_table].name, proc_names[procedure_num]); - } else - fprintf(f_report, " [%s] %s", WordToString(prev_mnemonic), phoneme_tab_list2[prev_table = list[ix]->ph_table].name); - fputc('\n', f_report); - } - - for (ix = 0; ix < n; ix++) { - free(list[ix]); - list[ix] = NULL; - } - - free(list); - list = NULL; -} - static void error(const char *format, ...) { va_list args; @@ -2485,14 +2409,6 @@ espeak_ng_CompilePhonemeDataPath(long rate, if (f_in == NULL) return create_file_error_context(context, errno, fname); - sprintf(fname, "%s/%s", phsrc, "compile_report"); - f_report = fopen(fname, "w"); - if (f_report == NULL) { - int error = errno; - fclose(f_in); - return create_file_error_context(context, error, fname); - } - sprintf(fname, "%s/%s", phdst, "phondata-manifest"); if ((f_phcontents = fopen(fname, "w")) == NULL) f_phcontents = stderr; @@ -2516,7 +2432,6 @@ espeak_ng_CompilePhonemeDataPath(long rate, if (f_phdata == NULL) { int error = errno; fclose(f_in); - fclose(f_report); fclose(f_phcontents); return create_file_error_context(context, error, fname); } @@ -2526,7 +2441,6 @@ espeak_ng_CompilePhonemeDataPath(long rate, if (f_phindex == NULL) { int error = errno; fclose(f_in); - fclose(f_report); fclose(f_phcontents); fclose(f_phdata); return create_file_error_context(context, error, fname); @@ -2537,7 +2451,6 @@ espeak_ng_CompilePhonemeDataPath(long rate, if (f_phtab == NULL) { int error = errno; fclose(f_in); - fclose(f_report); fclose(f_phcontents); fclose(f_phdata); fclose(f_phindex); @@ -2579,10 +2492,6 @@ espeak_ng_CompilePhonemeDataPath(long rate, LoadPhData(NULL, NULL); - CompileReport(); - - fclose(f_report); - WavegenFini(); if (resample_count > 0) { From 7c7ab9e1778f9b8540fdfc142050c4608a600118 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 10:37:09 +0300 Subject: [PATCH 08/16] cleanup: fix duplicateCondition code smell --- src/libespeak-ng/klatt.c | 2 -- src/libespeak-ng/soundicon.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libespeak-ng/klatt.c b/src/libespeak-ng/klatt.c index 29bf9d05..78254409 100644 --- a/src/libespeak-ng/klatt.c +++ b/src/libespeak-ng/klatt.c @@ -1000,9 +1000,7 @@ static void SetSynth_Klatt(int length, frame_t *fr1, frame_t *fr2, voice_t *wvoi if ((cmd == WCMD_WAVE) || (cmd == WCMD_PAUSE)) break; // next is not from spectrum, so continue until end of wave cycle } - } - if (control & 1) { for (ix = 1; ix < 6; ix++) { if (prev_fr.ffreq[ix] != fr1->ffreq[ix]) { // Discontinuity in formants. diff --git a/src/libespeak-ng/soundicon.c b/src/libespeak-ng/soundicon.c index 7b883528..3d124d80 100644 --- a/src/libespeak-ng/soundicon.c +++ b/src/libespeak-ng/soundicon.c @@ -98,8 +98,8 @@ static espeak_ng_STATUS LoadSoundFile(const char *fname, int index, espeak_ng_ER strcpy(fname_temp, tmpnam(NULL)); #endif - sprintf(command, "sox \"%s\" -r %d -c1 -b 16 -t wav %s\n", fname, samplerate, fname_temp); - if (system(command) == 0) +// sprintf(command, "sox \"%s\" -r %d -c1 -b 16 -t wav %s\n", fname, samplerate, fname_temp); +// if (system(command) == 0) fname = fname_temp; } } From fa575b54cbdeb8f1c0ad6104eeb8a25593323fd4 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 10:55:37 +0300 Subject: [PATCH 09/16] cleanup: fix knownConditionTrueFalse code smells --- src/libespeak-ng/translate.c | 2 +- src/libespeak-ng/translateword.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libespeak-ng/translate.c b/src/libespeak-ng/translate.c index 737150a7..d838de40 100644 --- a/src/libespeak-ng/translate.c +++ b/src/libespeak-ng/translate.c @@ -763,7 +763,7 @@ static const char *FindReplacementChars(Translator *tr, const char **pfrom, unsi nmatched++; } - if (*from == 0 && matched) { + if (matched) { *ignore_next_n = nmatched; return from + 1; } diff --git a/src/libespeak-ng/translateword.c b/src/libespeak-ng/translateword.c index cfad6d39..2cc6551c 100644 --- a/src/libespeak-ng/translateword.c +++ b/src/libespeak-ng/translateword.c @@ -1065,7 +1065,7 @@ static int CheckDottedAbbrev(char *word1) nbytes += 2; // delete the final dot (eg. u.s.a.'s) ok = 2; } - } else if ((count > 0) && (word[nbytes] == ' ')) + } else if ((count > 0)) ok = 2; } From 54265990b514a33392b253ad64ac5d22d9815243 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 11:40:01 +0300 Subject: [PATCH 10/16] cleanup: reduce variable scopes in wavegen.c --- src/libespeak-ng/wavegen.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libespeak-ng/wavegen.c b/src/libespeak-ng/wavegen.c index 271aa90c..e1695a0e 100644 --- a/src/libespeak-ng/wavegen.c +++ b/src/libespeak-ng/wavegen.c @@ -449,7 +449,6 @@ int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control) int hmax; int hmax_samplerate; // highest harmonic allowed for the samplerate int x; - int ix; int h1; // initialise as much of *out as we will need @@ -516,6 +515,7 @@ int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control) x = htab[h] >> 15; htab[h] = (x * x) >> 8; + int ix; if ((ix = (f >> 19)) < N_TONE_ADJUST) htab[h] = (htab[h] * wvoice->tone_adjust[ix]) >> 13; // index tone_adjust with Hz/8 } @@ -666,12 +666,12 @@ static int ApplyBreath(void) int value = 0; int noise; int ix; - int amp; // use two random numbers, for alternate formants noise = (rand() & 0x3fff) - 0x2000; for (ix = 1; ix < N_PEAKS; ix++) { + int amp; if ((amp = wvoice->breath[ix]) != 0) { amp *= (peaks[ix].height >> 14); value += (int)resonator(&rbreath[ix], noise) * amp; @@ -910,7 +910,6 @@ static int Wavegen(int length, int modulation, bool resume, frame_t *fr1, frame_ static int PlaySilence(int length, bool resume) { static int n_samples; - int value = 0; nsamples = 0; samplecount = 0; @@ -922,6 +921,7 @@ static int PlaySilence(int length, bool resume) if (resume == false) n_samples = length; + int value = 0; while (n_samples-- > 0) { value = (echo_buf[echo_tail++] * echo_amp) >> 8; @@ -1111,12 +1111,12 @@ static void SetAmplitude(int length, unsigned char *amp_env, int value) void SetPitch2(voice_t *voice, int pitch1, int pitch2, int *pitch_base, int *pitch_range) { - int x; int base; int range; int pitch_value; if (pitch1 > pitch2) { + int x; x = pitch1; // swap values pitch1 = pitch2; pitch2 = x; @@ -1171,7 +1171,6 @@ static void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t * int length2; int length4; int qix; - int cmd; static const int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256 static const int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256 @@ -1194,7 +1193,7 @@ static void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t * if (qix >= N_WCMDQ) qix = 0; if (qix == wcmdq_tail) break; - cmd = wcmdq[qix][0]; + int cmd = wcmdq[qix][0]; if (cmd == WCMD_SPECT) { end_wave = 0; // next wave generation is from another spectrum break; From 5d4791ccd1f21c6e175067c20e51025b1fda6cbc Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 11:56:18 +0300 Subject: [PATCH 11/16] cleanup: reduce variable scopes in synthesize.c --- src/libespeak-ng/synthesize.c | 49 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/libespeak-ng/synthesize.c b/src/libespeak-ng/synthesize.c index 478bd6e6..7c301a4c 100644 --- a/src/libespeak-ng/synthesize.c +++ b/src/libespeak-ng/synthesize.c @@ -193,7 +193,6 @@ static void DoPause(int length, int control) // control = 1, less shortening at fast speeds unsigned int len; - int srate2; if (length == 0) len = 0; @@ -203,7 +202,7 @@ static void DoPause(int length, int control) if (len < 90000) len = (len * samplerate) / 1000; // convert from mS to number of samples else { - srate2 = samplerate / 25; // avoid overflow + int srate2 = samplerate / 25; // avoid overflow len = (len * srate2) / 40; } } @@ -402,7 +401,6 @@ static void set_frame_rms(frame_t *fr, int new_rms) // RMS just adjust the formant amplitudes by the appropriate ratio int x; - int h; int ix; static const short sqrt_tab[200] = { @@ -434,6 +432,7 @@ static void set_frame_rms(frame_t *fr, int new_rms) x = sqrt_tab[x]; // sqrt(new_rms/fr->rms)*0x200; for (ix = 0; ix < 8; ix++) { + int h; h = fr->fheight[ix] * x; fr->fheight[ix] = h/0x200; } @@ -442,13 +441,11 @@ static void set_frame_rms(frame_t *fr, int new_rms) static void formants_reduce_hf(frame_t *fr, int level) { // change height of peaks 2 to 8, percentage - int ix; - int x; - if (voice->klattv[0]) return; - for (ix = 2; ix < 8; ix++) { + for (int ix = 2; ix < 8; ix++) { + int x; x = fr->fheight[ix] * level; fr->fheight[ix] = x/100; } @@ -541,10 +538,6 @@ static int VowelCloseness(frame_t *fr) int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsigned int data2, PHONEME_TAB *other_ph, int which) { - int ix; - int formant; - int next_rms; - int len; int rms; int f1; @@ -593,7 +586,7 @@ int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsig seq[0].frflags |= FRFLAG_LEN_MOD2; // reduce length modification fr->frflags |= FRFLAG_LEN_MOD2; - next_rms = seq[1].frame->rms; + int next_rms = seq[1].frame->rms; if (voice->klattv[0]) fr->klattp[KLATT_AV] = seq[1].frame->klattp[KLATT_AV] - 4; @@ -637,11 +630,11 @@ int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsig set_frame_rms(fr, rms); if ((vcolour > 0) && (vcolour <= N_VCOLOUR)) { - for (ix = 0; ix < *n_frames; ix++) { + for (int ix = 0; ix < *n_frames; ix++) { fr = CopyFrame(seq[ix].frame, 0); seq[ix].frame = fr; - for (formant = 1; formant <= 5; formant++) { + for (int formant = 1; formant <= 5; formant++) { int x; x = fr->ffreq[formant] * vcolouring[vcolour-1][formant-1]; fr->ffreq[formant] = x / 256; @@ -854,12 +847,8 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L int frameix; frame_t *frame1; frame_t *frame2; - frame_t *fr; - int ix; intptr_t *q; int len; - int frame_length; - int length_factor; int length_mod; int length_sum; int length_min; @@ -927,8 +916,9 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L if (last_frame->frflags & FRFLAG_BREAK_LF) { // but flag indicates keep HF peaks in last segment + frame_t *fr; fr = CopyFrame(frame1, 1); - for (ix = 3; ix < 8; ix++) { + for (int ix = 3; ix < 8; ix++) { if (ix < 7) fr->ffreq[ix] = last_frame->ffreq[ix]; fr->fheight[ix] = last_frame->fheight[ix]; @@ -947,13 +937,13 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L length_sum = 0; for (frameix = 1; frameix < n_frames; frameix++) { - length_factor = length_mod; + int length_factor = length_mod; if (frames[frameix-1].frflags & FRFLAG_LEN_MOD) // reduce effect of length mod length_factor = (length_mod*(256-speed.lenmod_factor) + 256*speed.lenmod_factor)/256; else if (frames[frameix-1].frflags & FRFLAG_LEN_MOD2) // reduce effect of length mod, used for the start of a vowel length_factor = (length_mod*(256-speed.lenmod2_factor) + 256*speed.lenmod2_factor)/256; - frame_length = frames[frameix-1].length; + int frame_length = frames[frameix-1].length; len = (frame_length * samplerate)/1000; len = (len * length_factor)/256; length_sum += len; @@ -1078,10 +1068,11 @@ void DoEmbedded(int *embix, int sourceix) { // There were embedded commands in the text at this point unsigned int word; // bit 7=last command for this word, bits 5,6 sign, bits 0-4 command - unsigned int value; - int command; do { + unsigned int value; + int command; + word = embedded_list[*embix]; value = word >> 8; command = word & 0x7f; @@ -1133,9 +1124,6 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume) static int ix; static int embedded_ix; static int word_count; - PHONEME_LIST *prev; - PHONEME_LIST *next; - PHONEME_LIST *next2; PHONEME_LIST *p; bool released; int stress; @@ -1147,7 +1135,6 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume) unsigned char *amp_env; PHONEME_TAB *ph; int use_ipa = 0; - bool done_phoneme_marker; int vowelstart_prev; char phoneme_name[16]; static int sourceix = 0; @@ -1202,6 +1189,10 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume) if (WcmdqFree() <= free_min) return 1; // wait + PHONEME_LIST *prev; + PHONEME_LIST *next; + PHONEME_LIST *next2; + prev = &phoneme_list[ix-1]; next = &phoneme_list[ix+1]; next2 = &phoneme_list[ix+2]; @@ -1229,7 +1220,7 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume) if ((p->prepause > 0) && !(p->ph->phflags & phPREVOICE)) DoPause(p->prepause, 1); - done_phoneme_marker = false; + bool done_phoneme_marker = false; if (option_phoneme_events && (p->ph->code != phonEND_WORD)) { if ((p->type == phVOWEL) && (prev->type == phLIQUID || prev->type == phNASAL)) { // For vowels following a liquid or nasal, do the phoneme event after the vowel-start @@ -1547,7 +1538,6 @@ int SpeakNextClause(int control) int clause_tone; char *voice_change; - const char *phon_out; if (control == 2) { // stop speaking @@ -1573,6 +1563,7 @@ int SpeakNextClause(int control) CalcLengths(translator); if ((option_phonemes & 0xf) || (phoneme_callback != NULL)) { + const char *phon_out; phon_out = GetTranslatedPhonemeString(option_phonemes); if (option_phonemes & 0xf) fprintf(f_trans, "%s\n", phon_out); From f23ff8875532b987ae0217c82541939b3651d55c Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 12:29:55 +0300 Subject: [PATCH 12/16] cleanup: reduce variable scopes in synthdata.c --- src/libespeak-ng/synthdata.c | 37 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/libespeak-ng/synthdata.c b/src/libespeak-ng/synthdata.c index c7dc90f7..ede3b963 100644 --- a/src/libespeak-ng/synthdata.c +++ b/src/libespeak-ng/synthdata.c @@ -102,7 +102,6 @@ static espeak_ng_STATUS ReadPhFile(void **ptr, const char *fname, int *size, esp espeak_ng_STATUS LoadPhData(int *srate, espeak_ng_ERROR_CONTEXT *context) { int ix; - int n_phonemes; int version; int length = 0; int rate; @@ -137,7 +136,7 @@ espeak_ng_STATUS LoadPhData(int *srate, espeak_ng_ERROR_CONTEXT *context) p += 4; for (ix = 0; ix < n_phoneme_tables; ix++) { - n_phonemes = p[0]; + int n_phonemes = p[0]; phoneme_tab_list[ix].n_phonemes = p[0]; phoneme_tab_list[ix].includes = p[1]; p += 4; @@ -183,14 +182,13 @@ int PhonemeCode(unsigned int mnem) int LookupPhonemeString(const char *string) { int ix; - unsigned char c; unsigned int mnem; // Pack up to 4 characters into a word mnem = 0; for (ix = 0; ix < 4; ix++) { if (string[ix] == 0) break; - c = string[ix]; + unsigned char c = string[ix]; mnem |= (c << (ix*8)); } @@ -205,8 +203,6 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, int seq_break; frameref_t *frames; int length1; - int length_std; - int length_factor; SPECT_SEQ *seq, *seq2; SPECT_SEQK *seqk, *seqk2; frame_t *frame; @@ -279,11 +275,12 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, } if (length1 > 0) { + int length_factor; if (which == 2) { // adjust the length of the main part to match the standard length specified for the vowel // less the front part of the vowel and any added suffix - length_std = fmt_params->std_length + seq_len_adjust - 45; + int length_std = fmt_params->std_length + seq_len_adjust - 45; if (length_std < 10) length_std = 10; if (plist->synthflags & SFLAG_LENGTHEN) @@ -335,7 +332,6 @@ static void SetUpPhonemeTable(int number) { int ix; int includes; - int ph_code; PHONEME_TAB *phtab; if ((includes = phoneme_tab_list[number].includes) > 0) { @@ -346,7 +342,7 @@ static void SetUpPhonemeTable(int number) // now add the phonemes from this table phtab = phoneme_tab_list[number].phoneme_tab_ptr; for (ix = 0; ix < phoneme_tab_list[number].n_phonemes; ix++) { - ph_code = phtab[ix].code; + int ph_code = phtab[ix].code; phoneme_tab[ph_code] = &phtab[ix]; if (ph_code > n_phoneme_tab) { memset(&phoneme_tab[n_phoneme_tab+1], 0, (ph_code - (n_phoneme_tab+1)) * sizeof(*phoneme_tab)); @@ -458,14 +454,9 @@ static int CountVowelPosition(PHONEME_LIST *plist) static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, unsigned short *p_prog, WORD_PH_DATA *worddata) { - int which; - int ix; unsigned int data; int instn; int instn2; - bool check_endtype = false; - PHONEME_TAB *ph; - PHONEME_LIST *plist_this; // instruction: 2xxx, 3xxx @@ -480,8 +471,9 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, instn2 = instn >> 8; if (instn2 < 14) { + PHONEME_LIST *plist_this; plist_this = plist; - which = (instn2) % 7; + int which = (instn2) % 7; if (which == 6) { // the 'which' code is in the next instruction @@ -505,6 +497,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, return false; } + bool check_endtype = false; switch (which) { case 0: // prevPh @@ -540,7 +533,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, check_endtype = true; break; case 9: // next3PhW - for (ix = 1; ix <= 3; ix++) { + for (int ix = 1; ix <= 3; ix++) { if (plist[ix].sourceix) return false; } @@ -565,6 +558,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, // "change phonemes" pass plist->ph = phoneme_tab[plist->phcode]; } + PHONEME_TAB *ph; ph = plist->ph; if (instn2 < 7) { @@ -653,9 +647,8 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, static void SwitchOnVowelType(PHONEME_LIST *plist, PHONEME_DATA *phdata, unsigned short **p_prog, int instn_type) { - unsigned short *prog; int voweltype; - signed char x; + if (instn_type == 2) { phdata->pd_control |= pd_FORNEXTPH; @@ -665,6 +658,9 @@ static void SwitchOnVowelType(PHONEME_LIST *plist, PHONEME_DATA *phdata, unsigne voweltype -= phonVOWELTYPES; if ((voweltype >= 0) && (voweltype < 6)) { + unsigned short *prog; + signed char x; + prog = *p_prog + voweltype*2; phdata->sound_addr[instn_type] = (((prog[1] & 0xf) << 16) + prog[2]) * 4; x = (prog[1] >> 4) & 0xff; @@ -728,8 +724,6 @@ void InterpretPhoneme(Translator *tr, int control, PHONEME_LIST *plist, PHONEME_ PHONEME_TAB *ph; unsigned short *prog; - unsigned short instn; - int instn2; int or_flag; bool truth; bool truth2; @@ -759,6 +753,9 @@ void InterpretPhoneme(Translator *tr, int control, PHONEME_LIST *plist, PHONEME_ end_flag = 0; for (prog = &phoneme_index[ph->program]; end_flag != 1; prog++) { + unsigned short instn; + int instn2; + instn = *prog; instn2 = (instn >> 8) & 0xf; From 03ebb2fd11d9fd25a38bc27bf7f6c880eb3f578d Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 12:57:33 +0300 Subject: [PATCH 13/16] cleanup: reduce variable scopes dictionary.c --- src/libespeak-ng/dictionary.c | 55 ++++++++++++++--------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index d506f512..bff3e67e 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -1473,19 +1473,13 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ int ix; int match_type; // left, right, or consume - int failed; - int unpron_ignore; - int consumed; // number of letters consumed from input int syllable_count; int vowel; int letter_group; - int distance_right; - int distance_left; int lg_pts; int n_bytes; int add_points; int command; - bool check_atstart; unsigned int *flags; MatchRecord match; @@ -1516,13 +1510,15 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ // search through dictionary rules while (rule[0] != RULE_GROUP_END) { - unpron_ignore = word_flags & FLAG_UNPRON_TEST; + bool check_atstart = false; + int consumed = 0; // number of letters consumed from input + int distance_left = -2; + int distance_right = -6; // used to reduce points for matches further away the current letter + int failed = 0; + int unpron_ignore = word_flags & FLAG_UNPRON_TEST; + match_type = 0; - consumed = 0; letter_w = 0; - distance_right = -6; // used to reduce points for matches further away the current letter - distance_left = -2; - check_atstart = false; match.points = 1; match.end_type = 0; @@ -1534,9 +1530,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ // work through next rule until end, or until no-match proved rule_start = rule; - failed = 0; while (!failed) { rb = *rule++; + add_points = 0; if (rb <= RULE_LINENUM) { switch (rb) @@ -1603,8 +1599,6 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ continue; } - add_points = 0; - switch (match_type) { case 0: @@ -2079,12 +2073,10 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c unsigned char c, c2; unsigned int c12; int wc = 0; - int wc_bytes; char *p2; // copy of p for use in double letter chain match int found; int g; // group chain number int g1; // first group for this letter - int n; int letter; int any_alpha = 0; int ix; @@ -2133,11 +2125,11 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c end_phonemes[0] = 0; while (((c = *p) != ' ') && (c != 0)) { - wc_bytes = utf8_in(&wc, p); + int wc_bytes = utf8_in(&wc, p); if (IsAlpha(wc)) any_alpha++; - n = tr->groups2_count[c]; + int n = tr->groups2_count[c]; if (IsDigit(wc) && ((tr->langopts.tone_numbers == 0) || !any_alpha)) { // lookup the number in *_list not *_rules char string[8]; @@ -2331,8 +2323,6 @@ int TransposeAlphabet(Translator *tr, char *text) // return: number of bytes, bit 6: 1=used compression int c; - int c2; - int ix; int offset; int min; int max; @@ -2340,10 +2330,7 @@ int TransposeAlphabet(Translator *tr, char *text) char *p = text; char *p2; bool all_alpha = true; - int bits; - int acc; int pairs_start; - const short *pairs_list; int bufix; char buf[N_WORD_BYTES+1]; @@ -2380,14 +2367,16 @@ int TransposeAlphabet(Translator *tr, char *text) if (all_alpha) { // compress to 6 bits per character - acc = 0; - bits = 0; + int ix; + int acc = 0; + int bits = 0; p = buf; p2 = buf; while ((c = *p++) != 0) { + const short *pairs_list; if ((pairs_list = tr->frequent_pairs) != NULL) { - c2 = c + (*p << 8); + int c2 = c + (*p << 8); for (ix = 0; c2 >= pairs_list[ix]; ix++) { if (c2 == pairs_list[ix]) { // found an encoding for a 2-character pair @@ -2849,9 +2838,7 @@ int Lookup(Translator *tr, const char *word, char *ph_out) int flags0; unsigned int flags[2]; - int say_as; char *word1 = (char *)word; - char text[80]; flags[0] = 0; flags[1] = FLAG_LOOKUP_SYMBOL; @@ -2859,11 +2846,13 @@ int Lookup(Translator *tr, const char *word, char *ph_out) flags0 = flags[0]; if (flags[0] & FLAG_TEXTMODE) { - say_as = option_sayas; + int say_as = option_sayas; option_sayas = 0; // don't speak replacement word as letter names // NOTE: TranslateRoman checks text[-2] and IsLetterGroup looks // for a heading \0, so pad the start of text to prevent // it reading data on the stack. + char text[80]; + text[0] = 0; text[1] = ' '; text[2] = ' '; @@ -2902,8 +2891,6 @@ int RemoveEnding(Translator *tr, char *word, int end_type, char *word_copy) char *word_end; int len_ending; int end_flags; - const char *p; - int len; char ending[50] = {0}; // these lists are language specific, but are only relevant if the 'e' suffix flag is used @@ -2972,16 +2959,18 @@ int RemoveEnding(Translator *tr, char *word, int end_type, char *word_copy) if (IsLetter(tr, word_end[-1], LETTERGP_VOWEL2) && IsLetter(tr, word_end[0], 1)) { // vowel(incl.'y') + hard.consonant + const char *p; for (i = 0; (p = add_e_exceptions[i]) != NULL; i++) { - len = strlen(p); + int len = strlen(p); if (memcmp(p, &word_end[1-len], len) == 0) break; } if (p == NULL) end_flags |= FLAG_SUFX_E_ADDED; // no exception found } else { + const char *p; for (i = 0; (p = add_e_additions[i]) != NULL; i++) { - len = strlen(p); + int len = strlen(p); if (memcmp(p, &word_end[1-len], len) == 0) { end_flags |= FLAG_SUFX_E_ADDED; break; From d47d2d0a40d85f4966881fe3d6a2f53665634c89 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 16:03:20 +0300 Subject: [PATCH 14/16] cleanup: remove duplicate StringToWord() Found with pmd-cpd static analysis --- src/libespeak-ng/common.c | 19 +++++++++++++++++++ src/libespeak-ng/common.h | 1 + src/libespeak-ng/compiledata.c | 21 +-------------------- src/libespeak-ng/compilembrola.c | 20 +------------------- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/libespeak-ng/common.c b/src/libespeak-ng/common.c index 5acbc49c..f44cf5e3 100644 --- a/src/libespeak-ng/common.c +++ b/src/libespeak-ng/common.c @@ -298,6 +298,25 @@ int Read4Bytes(FILE *f) return acc; } +unsigned int StringToWord(const char *string) +{ + // Pack 4 characters into a word + int ix; + unsigned char c; + unsigned int word; + + if (string == NULL) + return 0; + + word = 0; + for (ix = 0; ix < 4; ix++) { + if (string[ix] == 0) break; + c = string[ix]; + word |= (c << (ix*8)); + } + return word; +} + int towlower2(unsigned int c, Translator *translator) { // check for non-standard upper to lower case conversions diff --git a/src/libespeak-ng/common.h b/src/libespeak-ng/common.h index 0ee270a0..76fff8bf 100644 --- a/src/libespeak-ng/common.h +++ b/src/libespeak-ng/common.h @@ -34,6 +34,7 @@ int IsSpace(unsigned int c); int isspace2(unsigned int c); int is_str_totally_null(const char* str, int size); // Tests if all bytes of str up to size are null int Read4Bytes(FILE *f); +unsigned int StringToWord(const char *string); int towlower2(unsigned int c, Translator *translator); // Supports Turkish I ESPEAK_NG_API int utf8_in(int *c, const char *buf); diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 020c1ab1..7aad556a 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -35,7 +35,7 @@ #include #include -#include "common.h" // for GetFileLength, strncpy0, ... +#include "common.h" // for GetFileLength, strncpy0, ...c #include "error.h" // for create_file_error_context #include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST @@ -502,25 +502,6 @@ static void error_from_status(espeak_ng_STATUS status, const char *context) error("%s.", message); } -static unsigned int StringToWord(const char *string) -{ - // Pack 4 characters into a word - int ix; - unsigned char c; - unsigned int word; - - if (string == NULL) - return 0; - - word = 0; - for (ix = 0; ix < 4; ix++) { - if (string[ix] == 0) break; - c = string[ix]; - word |= (c << (ix*8)); - } - return word; -} - static const MNEM_TAB reserved_phonemes[] = { { "_\001", phonCONTROL }, // NOT USED { "%", phonSTRESS_U }, diff --git a/src/libespeak-ng/compilembrola.c b/src/libespeak-ng/compilembrola.c index 09f74b09..ee3a8386 100644 --- a/src/libespeak-ng/compilembrola.c +++ b/src/libespeak-ng/compilembrola.c @@ -31,6 +31,7 @@ #include "mbrola.h" #include "error.h" // for create_file_error_context +#include "common.h" // for StringToWord #include "mbrola.h" // for MBROLA_TAB #include "phoneme.h" // for N_PHONEME_TAB #include "speech.h" // for path_home @@ -44,25 +45,6 @@ static const char *basename(const char *filename) return current == filename ? current : current + 1; } -static unsigned int StringToWord(const char *string) -{ - // Pack 4 characters into a word - int ix; - unsigned char c; - unsigned int word; - - if (string == NULL) - return 0; - - word = 0; - for (ix = 0; ix < 4; ix++) { - if (string[ix] == 0) break; - c = string[ix]; - word |= (c << (ix*8)); - } - return word; -} - #pragma GCC visibility push(default) espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log, espeak_ng_ERROR_CONTEXT *context) { From 55f1f8e113156b0317f9db382657e28cede108d3 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sun, 30 Oct 2022 08:32:37 +0200 Subject: [PATCH 15/16] cleanup: reduce code duplication with AddToVoicesList() Checking for return value & continue might be redundant. --- src/libespeak-ng/voices.c | 66 ++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index 9665e6e0..e2734d8b 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -52,6 +52,7 @@ #include "translate.h" // for LANGUAGE_OPTIONS, DeleteTranslator #include "wavegen.h" // for InitBreath +static int AddToVoicesList(const char *fname, int len_path_voices, int is_language_file); static const MNEM_TAB genders[] = { @@ -1175,9 +1176,6 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found) static void GetVoices(const char *path, int len_path_voices, int is_language_file) { - FILE *f_voice; - espeak_VOICE *voice_data; - int ftype; char fname[sizeof(path_home)+100]; #ifdef PLATFORM_WINDOWS @@ -1198,22 +1196,8 @@ static void GetVoices(const char *path, int len_path_voices, int is_language_fil if (FindFileData.cFileName[0] != '.') { sprintf(fname, "%s%c%s", path, PATHSEP, FindFileData.cFileName); - ftype = GetFileLength(fname); - - if (ftype == -EISDIR) { - // a sub-directory - GetVoices(fname, len_path_voices, is_language_file); - } else if (ftype > 0) { - // a regular file, add it to the voices list - if ((f_voice = fopen(fname, "r")) == NULL) - continue; - - // pass voice file name within the voices directory - voice_data = ReadVoiceFile(f_voice, fname+len_path_voices, is_language_file); - fclose(f_voice); - - if (voice_data != NULL) - voices_list[n_voices_list++] = voice_data; + if (AddToVoicesList(fname, len_path_voices, is_language_file) != 0) { + continue; } } } while (FindNextFileA(hFind, &FindFileData) != 0); @@ -1234,25 +1218,11 @@ static void GetVoices(const char *path, int len_path_voices, int is_language_fil if (ent->d_name[0] == '.') continue; - sprintf(fname, "%s%c%s", path, PATHSEP, ent->d_name); - - ftype = GetFileLength(fname); - - if (ftype == -EISDIR) { - // a sub-directory - GetVoices(fname, len_path_voices, is_language_file); - } else if (ftype > 0) { - // a regular file, add it to the voices list - if ((f_voice = fopen(fname, "r")) == NULL) + sprintf(fname, "%s%c%s", path, PATHSEP, ent->d_name); + if (AddToVoicesList(fname, len_path_voices, is_language_file) != 0) { continue; + } - // pass voice file name within the voices directory - voice_data = ReadVoiceFile(f_voice, fname+len_path_voices, is_language_file); - fclose(f_voice); - - if (voice_data != NULL) - voices_list[n_voices_list++] = voice_data; - } } closedir(dir); #endif @@ -1429,3 +1399,27 @@ ESPEAK_API espeak_VOICE *espeak_GetCurrentVoice(void) } #pragma GCC visibility pop + +static int AddToVoicesList(const char *fname, int len_path_voices, int is_language_file) { + int ftype = GetFileLength(fname); + + if (ftype == -EISDIR) { + // a sub-directory + GetVoices(fname, len_path_voices, is_language_file); + } else if (ftype > 0) { + // a regular file, add it to the voices list + FILE *f_voice; + if ((f_voice = fopen(fname, "r")) == NULL) + return 1; + + // pass voice file name within the voices directory + espeak_VOICE *voice_data; + voice_data = ReadVoiceFile(f_voice, fname+len_path_voices, is_language_file); + fclose(f_voice); + + if (voice_data != NULL) + voices_list[n_voices_list++] = voice_data; + return 0; + } + return 0; +} \ No newline at end of file From 8021528f5e8bdd84425f5df19c7c5485b3553113 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 21:01:01 +0300 Subject: [PATCH 16/16] cleanup: reduce code duplication with a new function StatusCreateTerminatedMsg. This is not covered by current tests. --- src/libespeak-ng/speech.c | 57 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index ed704623..1c0130d3 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -63,6 +63,8 @@ #include "voice.h" // for FreeVoiceList, VoiceReset, current_... #include "wavegen.h" // for WavegenFill, WavegenInit, WcmdqUsed +static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data); + unsigned char *outbuf = NULL; int outbuf_size = 0; unsigned char *out_start; @@ -686,22 +688,7 @@ espeak_ng_Synthesize(const void *text, size_t size, *unique_identifier = c1->u.my_text.unique_identifier; } - // Create the "terminated msg" command (same uid) - t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); - - // Try to add these 2 commands (single transaction) - if (c1 && c2) { - espeak_ng_STATUS status = fifo_add_commands(c1, c2); - if (status != ENS_OK) { - delete_espeak_command(c1); - delete_espeak_command(c2); - } - return status; - } - - delete_espeak_command(c1); - delete_espeak_command(c2); - return ENOMEM; + return StatusCreateTerminatedMsg(c1, unique_identifier, user_data); #else return sync_espeak_Synth(0, text, position, position_type, end_position, flags, user_data); #endif @@ -736,22 +723,7 @@ espeak_ng_SynthesizeMark(const void *text, *unique_identifier = c1->u.my_mark.unique_identifier; } - // Create the "terminated msg" command (same uid) - t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); - - // Try to add these 2 commands (single transaction) - if (c1 && c2) { - espeak_ng_STATUS status = fifo_add_commands(c1, c2); - if (status != ENS_OK) { - delete_espeak_command(c1); - delete_espeak_command(c2); - } - return status; - } - - delete_espeak_command(c1); - delete_espeak_command(c2); - return ENOMEM; + return StatusCreateTerminatedMsg(c1, unique_identifier, user_data); #else return sync_espeak_Synth_Mark(0, text, index_mark, end_position, flags, user_data); #endif @@ -964,4 +936,25 @@ ESPEAK_API const char *espeak_Info(const char **ptr) return version_string; } + #pragma GCC visibility pop + + +static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data) { +// Create the "terminated msg" command (same uid) + t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); + + // Try to add these 2 commands (single transaction) + if (c1 && c2) { + espeak_ng_STATUS status = fifo_add_commands(c1, c2); + if (status != ENS_OK) { + delete_espeak_command(c1); + delete_espeak_command(c2); + } + return status; + } + + delete_espeak_command(c1); + delete_espeak_command(c2); + return ENOMEM; +} \ No newline at end of file