12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
-
-
- #include "StdAfx.h"
-
- #include "stdio.h"
- #include "ctype.h"
- #include "string.h"
- #include "stdlib.h"
- #include "wchar.h"
- #include "locale.h"
- #include <assert.h>
- #include <time.h>
-
- #include "speech.h"
-
- #include <sys/stat.h>
- #ifndef PLATFORM_WINDOWS
- #include <unistd.h>
- #endif
-
- #include "speak_lib.h"
- #include "phoneme.h"
- #include "synthesize.h"
- #include "voice.h"
- #include "translate.h"
- #include "debug.h"
-
- #include "fifo.h"
- #include "event.h"
- #include "wave.h"
-
- unsigned char *outbuf=NULL;
- extern espeak_VOICE voice_selected;
-
- espeak_EVENT *event_list=NULL;
- int event_list_ix=0;
- int n_event_list;
- long count_samples;
- void* my_audio=NULL;
-
- static unsigned int my_unique_identifier=0;
- static void* my_user_data=NULL;
- static espeak_AUDIO_OUTPUT my_mode=AUDIO_OUTPUT_SYNCHRONOUS;
- static int synchronous_mode = 1;
- t_espeak_callback* synth_callback = NULL;
- int (* uri_callback)(int, const char *, const char *) = NULL;
- int (* phoneme_callback)(const char *) = NULL;
-
- char path_home[N_PATH_HOME];
-
-
- #ifdef USE_ASYNC
-
- static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event)
- {
- ENTER("dispatch_audio");
-
- int a_wave_can_be_played = fifo_is_command_enabled();
-
- SHOW("*** dispatch_audio > uid=%d, [write=%p (%d bytes)], sample=%d, a_wave_can_be_played = %d\n",
- (event) ? event->unique_identifier : 0, wave_test_get_write_buffer(), 2*length,
- (event) ? event->sample : 0,
- a_wave_can_be_played);
-
-
- switch(my_mode)
- {
- case AUDIO_OUTPUT_PLAYBACK:
- {
- if (outbuf && length && a_wave_can_be_played)
- {
- wave_write (my_audio, (char*)outbuf, 2*length);
- }
-
- while(a_wave_can_be_played) {
-
-
-
-
-
- if (event && (event->type == espeakEVENT_WORD) && (event->length==0))
- {
- break;
- }
- espeak_ERROR a_error = event_declare(event);
- if (a_error != EE_BUFFER_FULL)
- {
- break;
- }
- SHOW_TIME("dispatch_audio > EE_BUFFER_FULL\n");
- usleep(10000);
- a_wave_can_be_played = fifo_is_command_enabled();
- }
- }
- break;
-
- case AUDIO_OUTPUT_RETRIEVAL:
- if (synth_callback)
- {
- synth_callback(outbuf, length, event);
- }
- break;
-
- case AUDIO_OUTPUT_SYNCHRONOUS:
- case AUDIO_OUTPUT_SYNCH_PLAYBACK:
- break;
- }
-
- if (!a_wave_can_be_played)
- {
- SHOW_TIME("dispatch_audio > synth must be stopped!\n");
- }
-
- SHOW_TIME("LEAVE dispatch_audio\n");
-
- return (a_wave_can_be_played==0);
- }
-
-
-
- static int create_events(short* outbuf, int length, espeak_EVENT* event, uint32_t the_write_pos)
- {
- int finished;
- int i=0;
-
-
-
-
-
-
-
- do
- {
- espeak_EVENT* event;
- if (event_list_ix == 0)
- {
- event = NULL;
- }
- else
- {
- event = event_list + i;
-
- SHOW("Synthesize: event->sample(%d) + %d = %d\n", event->sample, the_write_pos, event->sample + the_write_pos);
- event->sample += the_write_pos;
- }
- SHOW("*** Synthesize: i=%d (event_list_ix=%d), length=%d\n",i,event_list_ix,length);
- finished = dispatch_audio((short *)outbuf, length, event);
- length = 0;
- i++;
- } while((i < event_list_ix) && !finished);
- return finished;
- }
-
-
- int sync_espeak_terminated_msg( uint unique_identifier, void* user_data)
- {
- ENTER("sync_espeak_terminated_msg");
-
- int finished=0;
-
- memset(event_list, 0, 2*sizeof(espeak_EVENT));
-
- event_list[0].type = espeakEVENT_MSG_TERMINATED;
- event_list[0].unique_identifier = unique_identifier;
- event_list[0].user_data = user_data;
- event_list[1].type = espeakEVENT_LIST_TERMINATED;
- event_list[1].unique_identifier = unique_identifier;
- event_list[1].user_data = user_data;
-
- if (my_mode==AUDIO_OUTPUT_PLAYBACK)
- {
- while(1)
- {
- espeak_ERROR a_error = event_declare(event_list);
- if (a_error != EE_BUFFER_FULL)
- {
- break;
- }
- SHOW_TIME("sync_espeak_terminated_msg > EE_BUFFER_FULL\n");
- usleep(10000);
- }
- }
- else
- {
- if (synth_callback)
- {
- finished=synth_callback(NULL,0,event_list);
- }
- }
- return finished;
- }
-
- #endif
-
-
- static void select_output(espeak_AUDIO_OUTPUT output_type)
- {
- my_mode = output_type;
- my_audio = NULL;
- synchronous_mode = 1;
- option_waveout = 1;
-
- switch(my_mode)
- {
- case AUDIO_OUTPUT_PLAYBACK:
- synchronous_mode = 0;
- #ifdef USE_ASYNC
- wave_init();
- wave_set_callback_is_output_enabled( fifo_is_command_enabled);
- my_audio = wave_open("alsa");
- event_init();
- #endif
- break;
-
- case AUDIO_OUTPUT_RETRIEVAL:
- synchronous_mode = 0;
- break;
-
- case AUDIO_OUTPUT_SYNCHRONOUS:
- break;
-
- case AUDIO_OUTPUT_SYNCH_PLAYBACK:
- option_waveout = 0;
- WavegenInitSound();
- break;
- }
- }
-
-
-
-
- int GetFileLength(const char *filename)
- {
- struct stat statbuf;
-
- if(stat(filename,&statbuf) != 0)
- return(0);
-
- if((statbuf.st_mode & S_IFMT) == S_IFDIR)
-
- return(-2);
-
- return(statbuf.st_size);
- }
-
-
- char *Alloc(int size)
- {
- char *p;
- if((p = (char *)malloc(size)) == NULL)
- fprintf(stderr,"Can't allocate memory\n");
- return(p);
- }
-
- void Free(void *ptr)
- {
- if(ptr != NULL)
- free(ptr);
- }
-
-
-
- static void init_path(const char *path)
- {
- #ifdef PLATFORM_WINDOWS
- HKEY RegKey;
- unsigned long size;
- unsigned long var_type;
- char *env;
- unsigned char buf[sizeof(path_home)-13];
-
- if(path != NULL)
- {
- sprintf(path_home,"%s/espeak-data",path);
- return;
- }
-
- if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
- {
- sprintf(path_home,"%s/espeak-data",env);
- if(GetFileLength(path_home) == -2)
- return;
- }
-
- buf[0] = 0;
- RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak", 0, KEY_READ, &RegKey);
- size = sizeof(buf);
- var_type = REG_SZ;
- RegQueryValueEx(RegKey, "path", 0, &var_type, buf, &size);
-
- sprintf(path_home,"%s\\espeak-data",buf);
-
- #else
- char *env;
-
- if(path != NULL)
- {
- snprintf(path_home,sizeof(path_home),"%s/espeak-data",path);
- return;
- }
-
-
- if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
- {
- snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
- if(GetFileLength(path_home) == -2)
- return;
- }
-
- snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME"));
- if(access(path_home,R_OK) != 0)
- {
- strcpy(path_home,PATH_ESPEAK_DATA);
- }
- #endif
- }
-
- static int initialise(void)
- {
- int param;
- int result;
-
- LoadConfig();
- WavegenInit(22050,0);
- if((result = LoadPhData()) != 1)
- {
- if(result == -1)
- fprintf(stderr,"Failed to load espeak-data\n");
- else
- fprintf(stderr,"Wrong version of espeak-data 0x%x (expects 0x%x)\n",result,version_phdata);
- }
-
- memset(&voice_selected,0,sizeof(voice_selected));
- SetVoiceStack(NULL);
- SynthesizeInit();
- InitNamedata();
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- param_stack[0].parameter[param] = param_defaults[param];
-
- return(0);
- }
-
-
- static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags)
- {
-
- ENTER("Synthesize");
- int length;
- int finished = 0;
- int count_buffers = 0;
- #ifdef USE_ASYNC
- uint32_t a_write_pos=0;
- #endif
-
- #ifdef DEBUG_ENABLED
- if (text)
- {
- SHOW("Synthesize > uid=%d, flags=%d, >>>text=%s<<<\n", unique_identifier, flags, text);
- }
- #endif
-
- if((outbuf==NULL) || (event_list==NULL))
- return(EE_INTERNAL_ERROR);
-
- option_multibyte = flags & 7;
- option_ssml = flags & espeakSSML;
- option_phoneme_input = flags & espeakPHONEMES;
- option_endpause = flags & espeakENDPAUSE;
-
- count_samples = 0;
-
- #ifdef USE_ASYNC
- if(my_mode == AUDIO_OUTPUT_PLAYBACK)
- {
- a_write_pos = wave_get_write_position(my_audio);
- }
- #endif
-
- if(translator == NULL)
- {
- SetVoiceByName("default");
- }
-
- SpeakNextClause(NULL,text,0);
-
- if(my_mode == AUDIO_OUTPUT_SYNCH_PLAYBACK)
- {
- for(;;)
- {
- #ifdef PLATFORM_WINDOWS
- Sleep(300);
- #else
- #ifdef USE_NANOSLEEP
- struct timespec period;
- struct timespec remaining;
- period.tv_sec = 0;
- period.tv_nsec = 300000000;
- nanosleep(&period,&remaining);
- #else
- sleep(1);
- #endif
- #endif
- if(SynthOnTimer() != 0)
- break;
- }
- return(EE_OK);
- }
-
- for(;;)
- {
- SHOW("Synthesize > %s\n","for (next)");
- out_ptr = outbuf;
- out_end = &outbuf[outbuf_size];
- event_list_ix = 0;
- WavegenFill(0);
-
- length = (out_ptr - outbuf)/2;
- count_samples += length;
- event_list[event_list_ix].type = espeakEVENT_LIST_TERMINATED;
- event_list[event_list_ix].unique_identifier = my_unique_identifier;
- event_list[event_list_ix].user_data = my_user_data;
-
- count_buffers++;
- if (my_mode==AUDIO_OUTPUT_PLAYBACK)
- {
- #ifdef USE_ASYNC
- finished = create_events((short *)outbuf, length, event_list, a_write_pos);
- length = 0;
- #endif
- }
- else
- {
- finished = synth_callback((short *)outbuf, length, event_list);
- }
- if(finished)
- {
- SpeakNextClause(NULL,0,2);
- break;
- }
-
- if(Generate(phoneme_list,&n_phoneme_list,1)==0)
- {
- if(WcmdqUsed() == 0)
- {
-
-
-
- event_list[0].type = espeakEVENT_LIST_TERMINATED;
- event_list[0].unique_identifier = my_unique_identifier;
- event_list[0].user_data = my_user_data;
-
- if(SpeakNextClause(NULL,NULL,1)==0)
- {
- #ifdef USE_ASYNC
- if (my_mode==AUDIO_OUTPUT_PLAYBACK)
- {
- dispatch_audio(NULL, 0, NULL);
- }
- else
- {
- synth_callback(NULL, 0, event_list);
- }
- #else
- synth_callback(NULL, 0, event_list);
- #endif
- break;
- }
- }
- }
- }
- return(EE_OK);
- }
-
- #ifdef DEBUG_ENABLED
- static const char* label[] = {
- "END_OF_EVENT_LIST",
- "WORD",
- "SENTENCE",
- "MARK",
- "PLAY",
- "END"};
- #endif
-
-
- void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
- {
-
- ENTER("MarkerEvent");
- espeak_EVENT *ep;
- double time;
-
- if((event_list == NULL) || (event_list_ix >= (n_event_list-2)))
- return;
-
- ep = &event_list[event_list_ix++];
- ep->type = (espeak_EVENT_TYPE)type;
- ep->unique_identifier = my_unique_identifier;
- ep->user_data = my_user_data;
- ep->text_position = char_position & 0xffff;
- ep->length = char_position >> 24;
-
- time = (double(count_samples + (out_ptr - out_start)/2)*1000.0)/samplerate;
- ep->audio_position = int(time);
- ep->sample = (count_samples + (out_ptr - out_start)/2);
-
- SHOW("MarkerEvent > count_samples=%d, out_ptr=%x, out_start=0x%x\n",count_samples, out_ptr, out_start);
- SHOW("*** MarkerEvent > type=%s, uid=%d, text_pos=%d, length=%d, audio_position=%d, sample=%d\n",
- label[ep->type], ep->unique_identifier, ep->text_position, ep->length,
- ep->audio_position, ep->sample);
-
- if((type == espeakEVENT_MARK) || (type == espeakEVENT_PLAY))
- ep->id.name = &namedata[value];
- else
- ep->id.number = value;
- }
-
-
-
-
- espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, size_t size,
- unsigned int position, espeak_POSITION_TYPE position_type,
- unsigned int end_position, unsigned int flags, void* user_data)
- {
- ENTER("sync_espeak_Synth");
-
- SHOW("sync_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);
-
- espeak_ERROR aStatus;
-
- InitText(flags);
- my_unique_identifier = unique_identifier;
- my_user_data = user_data;
-
- switch(position_type)
- {
- case POS_CHARACTER:
- skip_characters = position;
- break;
-
- case POS_WORD:
- skip_words = position;
- break;
-
- case POS_SENTENCE:
- skip_sentences = position;
- break;
-
- }
- if(skip_characters || skip_words || skip_sentences)
- skipping_text = 1;
-
- end_character_position = end_position;
-
- aStatus = Synthesize(unique_identifier, text, flags);
- #ifdef USE_ASYNC
- wave_flush(my_audio);
- #endif
-
- SHOW_TIME("LEAVE sync_espeak_Synth");
- return aStatus;
- }
-
-
-
-
- espeak_ERROR sync_espeak_Synth_Mark(unsigned int unique_identifier, const void *text, size_t size,
- const char *index_mark, unsigned int end_position,
- unsigned int flags, void* user_data)
- {
- espeak_ERROR aStatus;
-
- InitText(flags);
-
- my_unique_identifier = unique_identifier;
- my_user_data = user_data;
-
- if(index_mark != NULL)
- {
- strncpy0(skip_marker, index_mark, sizeof(skip_marker));
- skipping_text = 1;
- }
-
- end_character_position = end_position;
-
-
- aStatus = Synthesize(unique_identifier, text, flags | espeakSSML);
- SHOW_TIME("LEAVE sync_espeak_Synth_Mark");
-
- return (aStatus);
- }
-
-
-
- void sync_espeak_Key(const char *key)
- {
-
- my_unique_identifier = 0;
- my_user_data = NULL;
- Synthesize(0, key,0);
- }
-
-
- void sync_espeak_Char(wchar_t character)
- {
-
- char buf[80];
- my_unique_identifier = 0;
- my_user_data = NULL;
-
- sprintf(buf,"<say-as interpret-as=\"tts:char\">&#%d;</say-as>",character);
- Synthesize(0, buf,espeakSSML);
- }
-
-
-
- void sync_espeak_SetPunctuationList(const wchar_t *punctlist)
- {
-
- my_unique_identifier = 0;
- my_user_data = NULL;
-
- wcsncpy(option_punctlist, punctlist, N_PUNCTLIST);
- option_punctlist[N_PUNCTLIST-1] = 0;
- }
-
-
-
-
- #pragma GCC visibility push(default)
-
-
- ESPEAK_API void espeak_SetSynthCallback(t_espeak_callback* SynthCallback)
- {
- ENTER("espeak_SetSynthCallback");
- synth_callback = SynthCallback;
- #ifdef USE_ASYNC
- event_set_callback(synth_callback);
- #endif
- }
-
- ESPEAK_API void espeak_SetUriCallback(int (* UriCallback)(int, const char*, const char *))
- {
- ENTER("espeak_SetUriCallback");
- uri_callback = UriCallback;
- }
-
-
- ESPEAK_API void espeak_SetPhonemeCallback(int (* PhonemeCallback)(const char*))
- {
- phoneme_callback = PhonemeCallback;
- }
-
- ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options)
- {
- ENTER("espeak_Initialize");
- int param;
-
-
-
-
- #ifdef PLATFORM_RISCOS
- setlocale(LC_CTYPE,"ISO8859-1");
- #else
- if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
- {
- if(setlocale(LC_CTYPE,"UTF-8") == NULL)
- setlocale(LC_CTYPE,"");
- }
- #endif
-
- init_path(path);
- initialise();
- select_output(output_type);
-
-
- if(buf_length == 0)
- buf_length = 200;
- outbuf_size = (buf_length * samplerate)/500;
- outbuf = (unsigned char*)realloc(outbuf,outbuf_size);
- if((out_start = outbuf) == NULL)
- return(EE_INTERNAL_ERROR);
-
-
- n_event_list = (buf_length*200)/1000;
- if((event_list = (espeak_EVENT *)realloc(event_list,sizeof(espeak_EVENT) * n_event_list)) == NULL)
- return(EE_INTERNAL_ERROR);
-
- option_phonemes = 0;
- option_phoneme_events = (options & 1);
-
- SetVoiceByName("default");
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- param_stack[0].parameter[param] = param_defaults[param];
-
- SetParameter(espeakRATE,170,0);
- SetParameter(espeakVOLUME,100,0);
- SetParameter(espeakCAPITALS,option_capitals,0);
- SetParameter(espeakPUNCTUATION,option_punctuation,0);
- SetParameter(espeakWORDGAP,0,0);
- DoVoiceChange(voice);
-
- #ifdef USE_ASYNC
- fifo_init();
- #endif
-
- return(samplerate);
- }
-
-
-
- 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)
- {
- 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);
-
- 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
-
- t_espeak_command* c1 = create_espeak_text(text, size, position, position_type, end_position, flags, user_data);
-
-
- *unique_identifier = c1->u.my_text.unique_identifier;
-
-
- t_espeak_command* c2 = create_espeak_terminated_msg(*unique_identifier, user_data);
-
-
- 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;
- }
-
-
-
- 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)
- {
- 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);
-
- 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
-
- t_espeak_command* c1 = create_espeak_mark(text, size, index_mark, end_position,
- flags, user_data);
-
-
- *unique_identifier = c1->u.my_mark.unique_identifier;
-
-
- t_espeak_command* c2 = create_espeak_terminated_msg(*unique_identifier, user_data);
-
-
- 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;
- }
-
-
-
- ESPEAK_API espeak_ERROR espeak_Key(const char *key)
- {
- ENTER("espeak_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);
- a_error = fifo_add_command(c);
- if (a_error != EE_OK)
- {
- delete_espeak_command(c);
- }
-
- #endif
- return a_error;
- }
-
-
- ESPEAK_API espeak_ERROR espeak_Char(wchar_t character)
- {
- ENTER("espeak_Char");
-
-
- #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);
- 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
- }
-
-
- ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name)
- {
- ENTER("espeak_SetVoiceByName");
-
- #ifdef USE_ASYNC
- 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
- }
-
-
-
- ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector)
- {
- ENTER("espeak_SetVoiceByProperties");
-
- #ifdef USE_ASYNC
- 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
- }
-
-
- ESPEAK_API int espeak_GetParameter(espeak_PARAMETER parameter, int current)
- {
- ENTER("espeak_GetParameter");
-
- if(current)
- {
- return(param_stack[0].parameter[parameter]);
- }
- else
- {
- return(param_defaults[parameter]);
- }
- }
-
-
- ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative)
- {
- ENTER("espeak_SetParameter");
-
- #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_SetPunctuationList(const wchar_t *punctlist)
- {
- ENTER("espeak_SetPunctuationList");
-
-
- #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
- }
-
-
- ESPEAK_API void espeak_SetPhonemeTrace(int value, FILE *stream)
- {
- ENTER("espeak_SetPhonemes");
-
-
- option_phonemes = value;
- f_trans = stream;
- if(stream == NULL)
- f_trans = stdout;
-
- }
-
-
- ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags)
- {
- ENTER("espeak_CompileDictionary");
- CompileDictionary(path, dictionary_name, log, NULL, flags);
- }
-
-
- ESPEAK_API espeak_ERROR espeak_Cancel(void)
- {
- #ifdef USE_ASYNC
- ENTER("espeak_Cancel");
- fifo_stop();
- event_clear_all();
-
- if(my_mode == AUDIO_OUTPUT_PLAYBACK)
- {
- wave_close(my_audio);
- }
- SHOW_TIME("espeak_Cancel > LEAVE");
- #endif
- return EE_OK;
- }
-
-
- ESPEAK_API int espeak_IsPlaying(void)
- {
-
- #ifdef USE_ASYNC
- if((my_mode == AUDIO_OUTPUT_PLAYBACK) && wave_is_busy(my_audio))
- return(1);
-
- return(fifo_is_busy());
- #else
- return(0);
- #endif
- }
-
-
- ESPEAK_API espeak_ERROR espeak_Synchronize(void)
- {
- #ifdef USE_ASYNC
- SHOW_TIME("espeak_Synchronize > ENTER");
- while (espeak_IsPlaying())
- {
- usleep(20000);
- }
- #endif
- SHOW_TIME("espeak_Synchronize > LEAVE");
- return EE_OK;
- }
-
-
- extern void FreePhData(void);
-
- ESPEAK_API espeak_ERROR espeak_Terminate(void)
- {
- ENTER("espeak_Terminate");
- #ifdef USE_ASYNC
- fifo_stop();
- fifo_terminate();
- event_terminate();
-
- if(my_mode == AUDIO_OUTPUT_PLAYBACK)
- {
- wave_close(my_audio);
- wave_terminate();
- }
-
- #endif
- Free(event_list);
- event_list = NULL;
- Free(outbuf);
- outbuf = NULL;
- FreePhData();
-
- return EE_OK;
- }
-
- ESPEAK_API const char *espeak_Info(void *)
- {
- return(version_string);
- }
-
- #pragma GCC visibility pop
-
-
|