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

@@ -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,

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

@@ -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(&current_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)

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

@@ -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");

Loading…
Cancel
Save