Add callback event: espeakEVENT_PHONEME git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@39 d46cf337-b52f-0410-862d-fd96e6ae7743master
| break; | break; | ||||
| case 0x104: // --voices | case 0x104: // --voices | ||||
| espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL); | |||||
| espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL,0); | |||||
| DisplayVoices(stdout,optarg); | DisplayVoices(stdout,optarg); | ||||
| exit(0); | exit(0); | ||||
| if(option_waveout || quiet) | if(option_waveout || quiet) | ||||
| { | { | ||||
| // writing to a file (or no output), we can use synchronous mode | // writing to a file (or no output), we can use synchronous mode | ||||
| samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL); | |||||
| samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL,0); | |||||
| espeak_SetSynthCallback(SynthCallback); | espeak_SetSynthCallback(SynthCallback); | ||||
| if(option_waveout) | if(option_waveout) | ||||
| else | else | ||||
| { | { | ||||
| // play the sound output | // play the sound output | ||||
| samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,NULL); | |||||
| samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,NULL,0); | |||||
| } | } | ||||
| {//==================================================================== | {//==================================================================== | ||||
| int type; | int type; | ||||
| fprintf(f_events,"--\n"); | |||||
| if(f_wavtest == NULL) return(0); | if(f_wavtest == NULL) return(0); | ||||
| if(wav == NULL) | if(wav == NULL) | ||||
| fprintf(f_events,"%5d %4d (%2d) %d ",events->audio_position,events->text_position,events->length,type); | fprintf(f_events,"%5d %4d (%2d) %d ",events->audio_position,events->text_position,events->length,type); | ||||
| if((type==3) || (type==4)) | if((type==3) || (type==4)) | ||||
| fprintf(f_events,"'%s'\n",events->id.name); | fprintf(f_events,"'%s'\n",events->id.name); | ||||
| else | |||||
| if(type==espeakEVENT_PHONEME) | |||||
| fprintf(f_events,"[%s]\n",WordToString(events->id.number)); | |||||
| else | else | ||||
| fprintf(f_events,"%d\n",events->id.number); | fprintf(f_events,"%d\n",events->id.number); | ||||
| espeak_VOICE *newvoice; | espeak_VOICE *newvoice; | ||||
| int x; | int x; | ||||
| espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,100,NULL); | |||||
| espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,100,NULL,0); | |||||
| memset(&voicespec,0,sizeof(voicespec)); | memset(&voicespec,0,sizeof(voicespec)); | ||||
| voicespec.languages = "de"; | voicespec.languages = "de"; | ||||
| espeak_SetVoiceByProperties(&voicespec); | espeak_SetVoiceByProperties(&voicespec); | ||||
| f_events = fopen("/home/jsd1/speechdata/text/events","w"); | f_events = fopen("/home/jsd1/speechdata/text/events","w"); | ||||
| fprintf(f_events,"Audio Text Length Type Id\n"); | fprintf(f_events,"Audio Text Length Type Id\n"); | ||||
| espeak_Initialize(AUDIO_OUTPUT_SYNCH_PLAYBACK,0,NULL); | |||||
| espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL,0,NULL,1); | |||||
| espeak_SetSynthCallback(TestSynthCallback); | espeak_SetSynthCallback(TestSynthCallback); | ||||
| unsigned int unique_identifier=0; | unsigned int unique_identifier=0; |
| uri_callback = UriCallback; | uri_callback = UriCallback; | ||||
| } | } | ||||
| ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path) | |||||
| {//================================================================================================ | |||||
| ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length, const char *path, int options) | |||||
| {//============================================================================================================= | |||||
| ENTER("espeak_Initialize"); | ENTER("espeak_Initialize"); | ||||
| int param; | int param; | ||||
| if((out_start = outbuf) == NULL) | if((out_start = outbuf) == NULL) | ||||
| return(EE_INTERNAL_ERROR); | return(EE_INTERNAL_ERROR); | ||||
| // allocate space for event list. Allow 500 events per minute | |||||
| n_event_list = (buf_length*500)/1000; | |||||
| // allocate space for event list. Allow 200 events per second | |||||
| n_event_list = (buf_length*200)/1000; | |||||
| if((event_list = (espeak_EVENT *)realloc(event_list,sizeof(espeak_EVENT) * n_event_list)) == NULL) | if((event_list = (espeak_EVENT *)realloc(event_list,sizeof(espeak_EVENT) * n_event_list)) == NULL) | ||||
| return(EE_INTERNAL_ERROR); | return(EE_INTERNAL_ERROR); | ||||
| option_phonemes = 0; | option_phonemes = 0; | ||||
| option_phoneme_events = (options & 1); | |||||
| SetVoiceByName("default"); | SetVoiceByName("default"); | ||||
| for(param=0; param<N_SPEECH_PARAM; param++) | for(param=0; param<N_SPEECH_PARAM; param++) |
| espeakEVENT_MARK, // Mark | espeakEVENT_MARK, // Mark | ||||
| espeakEVENT_PLAY, // Audio element | espeakEVENT_PLAY, // Audio element | ||||
| espeakEVENT_END, // End of sentence | espeakEVENT_END, // End of sentence | ||||
| espeakEVENT_MSG_TERMINATED // End of message | |||||
| espeakEVENT_MSG_TERMINATED, // End of message | |||||
| espeakEVENT_PHONEME // Phoneme, if enabled in espeak_Initialize() | |||||
| } espeak_EVENT_TYPE; | } espeak_EVENT_TYPE; | ||||
| int sample; // sample id (internal use) | int sample; // sample id (internal use) | ||||
| void* user_data; // pointer supplied by the calling program | void* user_data; // pointer supplied by the calling program | ||||
| union { | union { | ||||
| int number; // used for WORD and SENTENCE events | |||||
| int number; // used for WORD and SENTENCE events. For PHONEME events this is the phoneme mnemonic. | |||||
| const char *name; // used for MARK and PLAY events. UTF8 string | const char *name; // used for MARK and PLAY events. UTF8 string | ||||
| } id; | } id; | ||||
| } espeak_EVENT; | } espeak_EVENT; | ||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" | extern "C" | ||||
| #endif | #endif | ||||
| int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path); | |||||
| int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path, int options); | |||||
| /* Must be called before any synthesis functions are called. | /* Must be called before any synthesis functions are called. | ||||
| output: the audio data can either be played by eSpeak or passed back by the SynthCallback function. | output: the audio data can either be played by eSpeak or passed back by the SynthCallback function. | ||||
| path: The directory which contains the espeak-data directory, or NULL for the default location. | path: The directory which contains the espeak-data directory, or NULL for the default location. | ||||
| options: bit 0: 1=allow espeakEVENT_PHONEME events. | |||||
| Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR). | Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR). | ||||
| */ | */ | ||||
| #include "translate.h" | #include "translate.h" | ||||
| #include "wave.h" | #include "wave.h" | ||||
| const char *version_string = "1.26 09.Jun.07"; | |||||
| const char *version_string = "1.26.01 09.Jun.07"; | |||||
| const int version_phdata = 0x012601; | const int version_phdata = 0x012601; | ||||
| int option_device_number = -1; | int option_device_number = -1; |
| if(p->prepause > 0) | if(p->prepause > 0) | ||||
| DoPause(p->prepause); | DoPause(p->prepause); | ||||
| // printf("phoneme [%s]\n",WordToString(p->ph->mnemonic)); | |||||
| if(option_phoneme_events) | |||||
| { | |||||
| DoMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, p->ph->mnemonic); | |||||
| } | |||||
| switch(p->type) | switch(p->type) | ||||
| { | { | ||||
| case phPAUSE: | case phPAUSE: |
| int option_tone1 = 0; | int option_tone1 = 0; | ||||
| int option_tone2 = 0; | int option_tone2 = 0; | ||||
| int option_phonemes = 0; | int option_phonemes = 0; | ||||
| int option_phoneme_events = 0; | |||||
| int option_quiet = 0; | int option_quiet = 0; | ||||
| int option_endpause = 0; // suppress pause after end of text | int option_endpause = 0; // suppress pause after end of text | ||||
| int option_capitals = 0; | int option_capitals = 0; |
| extern int option_waveout; | extern int option_waveout; | ||||
| extern int option_quiet; | extern int option_quiet; | ||||
| extern int option_phonemes; | extern int option_phonemes; | ||||
| extern int option_phoneme_events; | |||||
| extern int option_linelength; // treat lines shorter than this as end-of-clause | extern int option_linelength; // treat lines shorter than this as end-of-clause | ||||
| extern int option_harmonic1; | extern int option_harmonic1; | ||||
| extern int option_multibyte; | extern int option_multibyte; |