ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, unsigned int* unique_identifier, void* user_data) {//========================================================================= #ifdef DEBUG_ENABLED ENTER("espeak_Synth_Mark"); SHOW("espeak_Synth_Mark > index_mark=%s, end_position=%d, flags=%d, text=%s\n", index_mark, end_position, flags, text); #endif espeak_ERROR a_error=EE_OK; static unsigned int temp_identifier; if (unique_identifier == NULL) { unique_identifier = &temp_identifier; } *unique_identifier = 0; if(synchronous_mode) { return(sync_espeak_Synth_Mark(0,text,size,index_mark,end_position,flags,user_data)); } #ifdef USE_ASYNC // Create the mark command t_espeak_command* c1 = create_espeak_mark(text, size, index_mark, end_position, flags, user_data); // Retrieve the unique identifier *unique_identifier = c1->u.my_mark.unique_identifier; // Create the "terminated msg" command (same uid) t_espeak_command* c2 = create_espeak_terminated_msg(*unique_identifier, user_data); // Try to add these 2 commands (single transaction) if (c1 && c2) { a_error = fifo_add_commands(c1, c2); if (a_error != EE_OK) { delete_espeak_command(c1); delete_espeak_command(c2); c1=c2=NULL; } } else { delete_espeak_command(c1); delete_espeak_command(c2); } #endif return a_error; } // end of espeak_Synth_Mark
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) {//===================================================================================== #ifdef DEBUG_ENABLED ENTER("espeak_Synth"); SHOW("espeak_Synth > position=%d, position_type=%d, end_position=%d, flags=%d, user_data=0x%x, text=%s\n", position, position_type, end_position, flags, user_data, text); #endif espeak_ERROR a_error=EE_INTERNAL_ERROR; static unsigned int temp_identifier; if (unique_identifier == NULL) { unique_identifier = &temp_identifier; } *unique_identifier = 0; if(synchronous_mode) { return(sync_espeak_Synth(0,text,size,position,position_type,end_position,flags,user_data)); } #ifdef USE_ASYNC // Create the text command t_espeak_command* c1 = create_espeak_text(text, size, position, position_type, end_position, flags, user_data); // Retrieve the unique identifier *unique_identifier = c1->u.my_text.unique_identifier; // Create the "terminated msg" command (same uid) t_espeak_command* c2 = create_espeak_terminated_msg(*unique_identifier, user_data); // Try to add these 2 commands (single transaction) if (c1 && c2) { a_error = fifo_add_commands(c1, c2); if (a_error != EE_OK) { delete_espeak_command(c1); delete_espeak_command(c2); c1=c2=NULL; } } else { delete_espeak_command(c1); delete_espeak_command(c2); } #endif return a_error; } // end of espeak_Synth
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SynthesizeMark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, unsigned int *unique_identifier, void *user_data) { (void)size; // unused in non-async modes static unsigned int temp_identifier; if (unique_identifier == NULL) unique_identifier = &temp_identifier; *unique_identifier = 0; if (my_mode & ENOUTPUT_MODE_SYNCHRONOUS) return sync_espeak_Synth_Mark(0, text, index_mark, end_position, flags, user_data); #ifdef USE_ASYNC // Create the mark command t_espeak_command *c1 = create_espeak_mark(text, size, index_mark, end_position, flags, user_data); if (c1) { // Retrieve the unique identifier *unique_identifier = c1->u.my_mark.unique_identifier; } // Create the "terminated msg" command (same uid) t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); // Try to add these 2 commands (single transaction) if (c1 && c2) { espeak_ng_STATUS status = fifo_add_commands(c1, c2); if (status != ENS_OK) { 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_Mark(0, text, index_mark, end_position, flags, user_data); #endif }
ESPEAK_API espeak_ERROR espeak_Key(const char *key) {//================================================ ENTER("espeak_Key"); // symbolic name, symbolicname_character - is there a system resource of symbolicnames per language if(f_logespeak) { fprintf(f_logespeak,"\nKEY %s\n",key); } espeak_ERROR a_error = EE_OK; if(synchronous_mode) { sync_espeak_Key(key); return(EE_OK); } #ifdef USE_ASYNC t_espeak_command* c = create_espeak_key( key, NULL); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } #endif return a_error; }
ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist) {//================================================================ ENTER("espeak_SetPunctuationList"); // Set the list of punctuation which are spoken for "some". #ifdef USE_ASYNC espeak_ERROR a_error; if(synchronous_mode) { sync_espeak_SetPunctuationList(punctlist); return(EE_OK); } t_espeak_command* c = create_espeak_punctuation_list( punctlist); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } return a_error; #else sync_espeak_SetPunctuationList(punctlist); return(EE_OK); #endif } // end of espeak_SetPunctuationList
ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative) {//============================================================================================= ENTER("espeak_SetParameter"); if(f_logespeak) { fprintf(f_logespeak,"SETPARAM %d %d %d\n",parameter,value,relative); } #ifdef USE_ASYNC espeak_ERROR a_error; if(synchronous_mode) { SetParameter(parameter,value,relative); return(EE_OK); } t_espeak_command* c = create_espeak_parameter(parameter, value, relative); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } return a_error; #else SetParameter(parameter,value,relative); return(EE_OK); #endif }
ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name) {//============================================================ ENTER("espeak_SetVoiceByName"); //#ifdef USE_ASYNC // I don't think there's a need to queue change voice requests #ifdef deleted espeak_ERROR a_error; if(synchronous_mode) { return(SetVoiceByName(name)); } t_espeak_command* c = create_espeak_voice_name(name); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } return a_error; #else return(SetVoiceByName(name)); #endif } // end of espeak_SetVoiceByName
ESPEAK_API espeak_ERROR espeak_Char(wchar_t character) {//=========================================== ENTER("espeak_Char"); // is there a system resource of character names per language? if(f_logespeak) { fprintf(f_logespeak,"\nCHAR U+%x\n",character); } #ifdef USE_ASYNC espeak_ERROR a_error; if(synchronous_mode) { sync_espeak_Char(character); return(EE_OK); } t_espeak_command* c = create_espeak_char( character, NULL); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } return a_error; #else sync_espeak_Char(character); return(EE_OK); #endif }
static void init() { ENTER("fifo > init"); while (delete_espeak_command( pop() )) {} node_counter = 0; }
static void init(int process_parameters) { // Changed by Tyler Spivey 30.Nov.2011 t_espeak_command *c = NULL; ENTER("fifo > init"); c = pop(); while (c != NULL) { if (process_parameters && (c->type == ET_PARAMETER || c->type == ET_VOICE_NAME || c->type == ET_VOICE_SPEC)) { process_espeak_command(c); } delete_espeak_command(c); c = pop(); } node_counter = 0; }
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SetParameter(espeak_PARAMETER parameter, int value, int relative) { #ifdef USE_ASYNC if (my_mode & ENOUTPUT_MODE_SYNCHRONOUS) return SetParameter(parameter, value, relative); t_espeak_command *c = create_espeak_parameter(parameter, value, relative); espeak_ng_STATUS status = fifo_add_command(c); if (status != ENS_OK) delete_espeak_command(c); return status; #else return SetParameter(parameter, value, relative); #endif }
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SpeakCharacter(wchar_t character) { // is there a system resource of character names per language? #ifdef USE_ASYNC if (my_mode & ENOUTPUT_MODE_SYNCHRONOUS) return sync_espeak_Char(character); t_espeak_command *c = create_espeak_char(character, NULL); espeak_ng_STATUS status = fifo_add_command(c); if (status != ENS_OK) delete_espeak_command(c); return status; #else return sync_espeak_Char(character); #endif }
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SpeakKeyName(const char *key_name) { // symbolic name, symbolicname_character - is there a system resource of symbolicnames per language if (my_mode & ENOUTPUT_MODE_SYNCHRONOUS) return sync_espeak_Key(key_name); #ifdef USE_ASYNC t_espeak_command *c = create_espeak_key(key_name, NULL); espeak_ng_STATUS status = fifo_add_command(c); if (status != ENS_OK) delete_espeak_command(c); return status; #else return sync_espeak_Key(key_name); #endif }
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SetPunctuationList(const wchar_t *punctlist) { // Set the list of punctuation which are spoken for "some". #ifdef USE_ASYNC if (my_mode & ENOUTPUT_MODE_SYNCHRONOUS) { sync_espeak_SetPunctuationList(punctlist); return ENS_OK; } t_espeak_command *c = create_espeak_punctuation_list(punctlist); espeak_ng_STATUS status = fifo_add_command(c); if (status != ENS_OK) delete_espeak_command(c); return status; #else sync_espeak_SetPunctuationList(punctlist); return ENS_OK; #endif }
ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector) {//============================================================================== ENTER("espeak_SetVoiceByProperties"); //#ifdef USE_ASYNC #ifdef deleted espeak_ERROR a_error; if(synchronous_mode) { return(SetVoiceByProperties(voice_selector)); } t_espeak_command* c = create_espeak_voice_spec( voice_selector); a_error = fifo_add_command(c); if (a_error != EE_OK) { delete_espeak_command(c); } return a_error; #else return(SetVoiceByProperties(voice_selector)); #endif } // end of espeak_SetVoiceByProperties
static void* say_thread(void*) { ENTER("say_thread"); SHOW_TIME("say_thread > post my_sem_stop_is_acknowledged\n"); // announce that thread is started sem_post(&my_sem_stop_is_acknowledged); int look_for_inactivity=0; while(1) { SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); int a_start_is_required = 0; if (look_for_inactivity) { a_start_is_required = sleep_until_start_request_or_inactivity(); if (!a_start_is_required) { close_stream(); } } look_for_inactivity = 1; if (!a_start_is_required) { while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } } SHOW_TIME("say_thread > get my_sem_start_is_required\n"); SHOW_TIME("say_thread > my_command_is_running = 1\n"); my_command_is_running = 1; while( my_command_is_running) { SHOW_TIME("say_thread > locking\n"); int a_status = pthread_mutex_lock(&my_mutex); assert (!a_status); t_espeak_command* a_command = (t_espeak_command*)pop(); if (a_command == NULL) { SHOW_TIME("say_thread > text empty (talking=0) \n"); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("say_thread > unlocked\n"); SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; } else { display_espeak_command(a_command); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); while(0 == sem_trywait(&my_sem_start_is_required)) { }; if (my_stop_is_required) { SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; } SHOW_TIME("say_thread > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); if (my_command_is_running) { process_espeak_command(a_command); } delete_espeak_command(a_command); } } if (my_stop_is_required) { // no mutex required since the stop command is synchronous // and waiting for my_sem_stop_is_acknowledged init(1); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); while(0==sem_trywait(&my_sem_start_is_required)) { }; // acknowledge the stop request SHOW_TIME("say_thread > post my_sem_stop_is_acknowledged\n"); int a_status = sem_post(&my_sem_stop_is_acknowledged); assert( a_status != -1); } // and wait for the next start SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); } return NULL; }