diff --git a/src/espeak-ng.c b/src/espeak-ng.c index 0ce2b0ec..8a522792 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -574,8 +574,17 @@ int main(int argc, char **argv) phonemes_separator = 0x200d; // ZWJ break; case 0x10e: // --compile-mbrola + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompileMbrolaVoice(optarg2, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompileMbrolaVoice(optarg2, stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } case 0x10f: // --compile-intonations espeak_ng_InitializePath(data_path); return (espeak_ng_CompileIntonation(stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 95cc13f8..2fc0a86a 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -143,7 +143,8 @@ espeak_ng_CompileDictionary(const char *dsource, ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *path, - FILE *log); + FILE *log, + espeak_ng_ERROR_CONTEXT *context); ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompilePhonemeData(long rate, diff --git a/src/libespeak-ng/compilembrola.c b/src/libespeak-ng/compilembrola.c index ca8dc88b..24a93643 100644 --- a/src/libespeak-ng/compilembrola.c +++ b/src/libespeak-ng/compilembrola.c @@ -30,6 +30,7 @@ #include "speak_lib.h" #include "espeak_ng.h" +#include "error.h" #include "phoneme.h" #include "speech.h" #include "synthesize.h" @@ -62,7 +63,7 @@ static unsigned int StringToWord(const char *string) } #pragma GCC visibility push(default) -espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) +espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log, espeak_ng_ERROR_CONTEXT *context) { if (!log) log = stderr; @@ -85,10 +86,8 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) MBROLA_TAB data[N_PHONEME_TAB]; strcpy(buf, filepath); - if ((f_in = fopen(buf, "r")) == NULL) { - fprintf(log, "Can't read: %s\n", filepath); - return errno; - } + if ((f_in = fopen(buf, "r")) == NULL) + return create_file_error_context(context, errno, buf); while (fgets(buf, sizeof(phoneme), f_in) != NULL) { buf[sizeof(phoneme)-1] = 0; @@ -126,10 +125,8 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) strcpy(mbrola_voice, basename(filepath)); sprintf(buf, "%s/mbrola_ph/%s_phtrans", path_home, mbrola_voice); - if ((f_out = fopen(buf, "wb")) == NULL) { - fprintf(log, "Can't write to: %s\n", buf); - return errno; - } + if ((f_out = fopen(buf, "wb")) == NULL) + return create_file_error_context(context, errno, buf); data[count].name = 0; // list terminator Write4Bytes(f_out, mbrola_ctrl); diff --git a/src/speak-ng.c b/src/speak-ng.c index b3ab8a8b..0b4a5aa0 100644 --- a/src/speak-ng.c +++ b/src/speak-ng.c @@ -561,8 +561,17 @@ int main(int argc, char **argv) phonemes_separator = 0x200d; // ZWJ break; case 0x10e: // --compile-mbrola + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompileMbrolaVoice(optarg2, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompileMbrolaVoice(optarg2, stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } case 0x10f: // --compile-intonations espeak_ng_InitializePath(data_path); return (espeak_ng_CompileIntonation(stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE;