From 75f75588011abf84f99bdb0c11d1c22c54c73e2b Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Fri, 1 Jan 2016 14:39:52 +0000 Subject: [PATCH] Share the initialise implementation between libespeak-ng and speak-ng. --- src/include/espeak-ng/espeak_ng.h | 3 ++ src/libespeak-ng/speak_lib.c | 46 ++++++++++++++++--------------- src/speak-ng.c | 41 ++++++--------------------- 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 63570670..94093a1c 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -47,6 +47,9 @@ typedef enum { ESPEAK_NG_API void espeak_ng_InitializePath(const char *path); +ESPEAK_NG_API espeak_ng_STATUS +espeak_ng_Initialize(void); + ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompileDictionary(const char *dsource, const char *dict_name, diff --git a/src/libespeak-ng/speak_lib.c b/src/libespeak-ng/speak_lib.c index a399fde0..3c09a119 100644 --- a/src/libespeak-ng/speak_lib.c +++ b/src/libespeak-ng/speak_lib.c @@ -303,26 +303,28 @@ ESPEAK_NG_API void espeak_ng_InitializePath(const char *path) strcpy(path_home, PATH_ESPEAK_DATA); #endif } -#pragma GCC visibility pop -static int initialise(int control) +ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Initialize(void) { int param; int srate = 22050; // default sample rate 22050 Hz - err = EE_OK; - LoadConfig(); + // It seems that the wctype functions don't work until the locale has been set + // to something other than the default "C". Then, not only Latin1 but also the + // other characters give the correct results with iswalpha() etc. + if (setlocale(LC_CTYPE, "C.UTF-8") == NULL) { + if (setlocale(LC_CTYPE, "UTF-8") == NULL) { + if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) + setlocale(LC_CTYPE, ""); + } + } espeak_ng_STATUS result = LoadPhData(&srate); - if (result != ENS_OK) { - if (result == ENE_READ_ERROR) { - fprintf(stderr, "Failed to load espeak-data\n"); - if ((control & espeakINITIALIZE_DONT_EXIT) == 0) - exit(1); - } else - fprintf(stderr, "Wrong version of espeak-data (expected 0x%x) at %s\n", version_phdata, path_home); - } + if (result != ENS_OK) + return result; + WavegenInit(srate, 0); + LoadConfig(); memset(¤t_voice_selected, 0, sizeof(current_voice_selected)); SetVoiceStack(NULL, ""); @@ -334,6 +336,7 @@ static int initialise(int control) return 0; } +#pragma GCC visibility pop static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags) { @@ -603,17 +606,16 @@ ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length { int param; - // It seems that the wctype functions don't work until the locale has been set - // to something other than the default "C". Then, not only Latin1 but also the - // other characters give the correct results with iswalpha() etc. - if (setlocale(LC_CTYPE, "C.UTF-8") == NULL) { - if (setlocale(LC_CTYPE, "UTF-8") == NULL) - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - setlocale(LC_CTYPE, ""); - } - espeak_ng_InitializePath(path); - initialise(options); + espeak_ng_STATUS result = espeak_ng_Initialize(); + if (result != ENS_OK) { + if (result == ENE_READ_ERROR) { + fprintf(stderr, "Failed to load espeak-data\n"); + if ((options & espeakINITIALIZE_DONT_EXIT) == 0) + exit(1); + } else + fprintf(stderr, "Wrong version of espeak-data (expected 0x%x) at %s\n", version_phdata, path_home); + } select_output(output_type); if (f_logespeak) diff --git a/src/speak-ng.c b/src/speak-ng.c index df78ec3f..6531692a 100644 --- a/src/speak-ng.c +++ b/src/speak-ng.c @@ -284,38 +284,6 @@ static int WavegenFile(void) return finished; } -static int initialise(void) -{ - int param; - int srate = 22050; // default sample rate - - // It seems that the wctype functions don't work until the locale has been set - // to something other than the default "C". Then, not only Latin1 but also the - // other characters give the correct results with iswalpha() etc. - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) { - if (setlocale(LC_CTYPE, "UTF-8") == NULL) - setlocale(LC_CTYPE, ""); - } - - espeak_ng_STATUS result = LoadPhData(&srate); - if (result != ENS_OK) { - if (result == ENE_READ_ERROR) { - fprintf(stderr, "Failed to load espeak-data\n"); - exit(1); - } else - fprintf(stderr, "Wrong version of espeak-data (expected 0x%x) at %s\n", version_phdata, path_home); - } - WavegenInit(srate, 0); - LoadConfig(); - SetVoiceStack(NULL, ""); - SynthesizeInit(); - - for (param = 0; param < N_SPEECH_PARAM; param++) - param_stack[0].parameter[param] = param_defaults[param]; - - return 0; -} - #ifdef NEED_GETOPT struct option { char *name; @@ -607,7 +575,14 @@ int main(int argc, char **argv) } espeak_ng_InitializePath(data_path); - initialise(); + espeak_ng_STATUS result = espeak_ng_Initialize(); + if (result != ENS_OK) { + if (result == ENE_READ_ERROR) + fprintf(stderr, "Failed to load espeak-data\n"); + else + fprintf(stderr, "Wrong version of espeak-data (expected 0x%x) at %s\n", version_phdata, path_home); + exit(1); + } if (voicename[0] == 0) strcpy(voicename, "default");