From 06cbd9d096da888426739acc74d4edc1dcb1fff6 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 2 Jan 2016 17:06:01 +0000 Subject: [PATCH] Create an espeak-ng version of espeak_Synth. --- src/include/espeak-ng/espeak_ng.h | 12 +++++++++- src/libespeak-ng/espeak_api.c | 9 ++++++++ src/libespeak-ng/espeak_command.h | 6 ++--- src/libespeak-ng/speech.c | 38 ++++++++++++++++--------------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 0bb0916f..7ba93445 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -19,7 +19,7 @@ #ifndef ESPEAK_NG_H #define ESPEAK_NG_H -#include +#include "speak_lib.h" #ifdef __cplusplus extern "C" @@ -64,6 +64,16 @@ espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode, ESPEAK_NG_API int espeak_ng_GetSampleRate(void); +ESPEAK_NG_API espeak_ng_STATUS +espeak_ng_Synthesize(const void *text, + size_t size, + unsigned int position, + espeak_POSITION_TYPE position_type, + unsigned int end_position, + unsigned int flags, + unsigned int *unique_identifier, + void *user_data); + ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SpeakKeyName(const char *key_name); diff --git a/src/libespeak-ng/espeak_api.c b/src/libespeak-ng/espeak_api.c index 712c3503..fba55364 100644 --- a/src/libespeak-ng/espeak_api.c +++ b/src/libespeak-ng/espeak_api.c @@ -102,6 +102,15 @@ ESPEAK_API void espeak_SetPhonemeCallback(int (*PhonemeCallback)(const char *)) phoneme_callback = PhonemeCallback; } +ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, + unsigned int position, + espeak_POSITION_TYPE position_type, + unsigned int end_position, unsigned int flags, + unsigned int *unique_identifier, void *user_data) +{ + return status_to_espeak_error(espeak_ng_Synthesize(text, size, position, position_type, end_position, flags, unique_identifier, user_data)); +} + ESPEAK_API espeak_ERROR espeak_Key(const char *key_name) { return status_to_espeak_error(espeak_ng_SpeakKeyName(key_name)); diff --git a/src/libespeak-ng/espeak_command.h b/src/libespeak-ng/espeak_command.h index 3471b2ce..2dddb68d 100644 --- a/src/libespeak-ng/espeak_command.h +++ b/src/libespeak-ng/espeak_command.h @@ -131,9 +131,9 @@ void process_espeak_command(t_espeak_command *the_command); int delete_espeak_command(t_espeak_command *the_command); -espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, - unsigned int position, espeak_POSITION_TYPE position_type, - unsigned int end_position, unsigned int flags, void *user_data); +espeak_ng_STATUS sync_espeak_Synth(unsigned int unique_identifier, const void *text, + unsigned int position, espeak_POSITION_TYPE position_type, + unsigned int end_position, unsigned int flags, void *user_data); espeak_ERROR sync_espeak_Synth_Mark(unsigned int unique_identifier, const void *text, const char *index_mark, unsigned int end_position, unsigned int flags, void *user_data); diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index b693d92f..1d575415 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -511,9 +511,9 @@ void MarkerEvent(int type, unsigned int char_position, int value, int value2, un ep->id.number = value; } -espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, - unsigned int position, espeak_POSITION_TYPE position_type, - unsigned int end_position, unsigned int flags, void *user_data) +espeak_ng_STATUS sync_espeak_Synth(unsigned int unique_identifier, const void *text, + unsigned int position, espeak_POSITION_TYPE position_type, + unsigned int end_position, unsigned int flags, void *user_data) { InitText(flags); my_unique_identifier = unique_identifier; @@ -540,7 +540,7 @@ espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, end_character_position = end_position; - espeak_ERROR aStatus = status_to_espeak_error(Synthesize(unique_identifier, text, flags)); + espeak_ng_STATUS aStatus = Synthesize(unique_identifier, text, flags); #ifdef USE_ASYNC wave_flush(my_audio); #endif @@ -608,15 +608,15 @@ void sync_espeak_SetPunctuationList(const wchar_t *punctlist) #pragma GCC visibility push(default) -ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, - unsigned int position, - espeak_POSITION_TYPE position_type, - unsigned int end_position, unsigned int flags, - unsigned int *unique_identifier, void *user_data) +ESPEAK_NG_API espeak_ng_STATUS +espeak_ng_Synthesize(const void *text, size_t size, + unsigned int position, + espeak_POSITION_TYPE position_type, + unsigned int end_position, unsigned int flags, + unsigned int *unique_identifier, void *user_data) { - (void)size; // unused + (void)size; // unused in non-async modes - espeak_ERROR a_error = EE_INTERNAL_ERROR; static unsigned int temp_identifier; if (unique_identifier == NULL) @@ -638,18 +638,20 @@ ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, // Try to add these 2 commands (single transaction) if (c1 && c2) { - a_error = status_to_espeak_error(fifo_add_commands(c1, c2)); - if (a_error != EE_OK) { + espeak_ng_STATUS status = fifo_add_commands(c1, c2); + if (status != ENS_OK) { delete_espeak_command(c1); delete_espeak_command(c2); - c1 = c2 = NULL; } - } else { - delete_espeak_command(c1); - delete_espeak_command(c2); + return status; } + + delete_espeak_command(c1); + delete_espeak_command(c2); + return ENOMEM; +#else + return sync_espeak_Synth(0, text, position, position_type, end_position, flags, user_data); #endif - return a_error; } ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size,