Browse Source

Share the initialise implementation between libespeak-ng and speak-ng.

master
Reece H. Dunn 9 years ago
parent
commit
75f7558801
3 changed files with 35 additions and 55 deletions
  1. 3
    0
      src/include/espeak-ng/espeak_ng.h
  2. 24
    22
      src/libespeak-ng/speak_lib.c
  3. 8
    33
      src/speak-ng.c

+ 3
- 0
src/include/espeak-ng/espeak_ng.h View File

ESPEAK_NG_API void ESPEAK_NG_API void
espeak_ng_InitializePath(const char *path); espeak_ng_InitializePath(const char *path);


ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_Initialize(void);

ESPEAK_NG_API espeak_ng_STATUS ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_CompileDictionary(const char *dsource, espeak_ng_CompileDictionary(const char *dsource,
const char *dict_name, const char *dict_name,

+ 24
- 22
src/libespeak-ng/speak_lib.c View File

strcpy(path_home, PATH_ESPEAK_DATA); strcpy(path_home, PATH_ESPEAK_DATA);
#endif #endif
} }
#pragma GCC visibility pop


static int initialise(int control) ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Initialize(void)
{ {
int param; int param;
int srate = 22050; // default sample rate 22050 Hz int srate = 22050; // default sample rate 22050 Hz


err = EE_OK; // It seems that the wctype functions don't work until the locale has been set
LoadConfig(); // 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); espeak_ng_STATUS result = LoadPhData(&srate);
if (result != ENS_OK) { if (result != ENS_OK)
if (result == ENE_READ_ERROR) { return result;
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);
}
WavegenInit(srate, 0); WavegenInit(srate, 0);
LoadConfig();


memset(&current_voice_selected, 0, sizeof(current_voice_selected)); memset(&current_voice_selected, 0, sizeof(current_voice_selected));
SetVoiceStack(NULL, ""); SetVoiceStack(NULL, "");


return 0; return 0;
} }
#pragma GCC visibility pop


static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags) static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags)
{ {
{ {
int param; 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); 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); select_output(output_type);


if (f_logespeak) if (f_logespeak)

+ 8
- 33
src/speak-ng.c View File

return finished; 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 #ifdef NEED_GETOPT
struct option { struct option {
char *name; char *name;
} }


espeak_ng_InitializePath(data_path); 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) if (voicename[0] == 0)
strcpy(voicename, "default"); strcpy(voicename, "default");

Loading…
Cancel
Save