diff options
Diffstat (limited to 'navit/support/espeak/speak_lib.h')
-rw-r--r-- | navit/support/espeak/speak_lib.h | 207 |
1 files changed, 139 insertions, 68 deletions
diff --git a/navit/support/espeak/speak_lib.h b/navit/support/espeak/speak_lib.h index 25c24c173..f33e03136 100644 --- a/navit/support/espeak/speak_lib.h +++ b/navit/support/espeak/speak_lib.h @@ -1,7 +1,7 @@ #ifndef SPEAK_LIB_H #define SPEAK_LIB_H /*************************************************************************** - * Copyright (C) 2005 to 2007 by Jonathan Duddington * + * Copyright (C) 2005 to 2012 by Jonathan Duddington * * email: jonsd@users.sourceforge.net * * * * This program is free software; you can redistribute it and/or modify * @@ -26,8 +26,15 @@ /*************************************************************/ #include <stdio.h> -#include <wchar.h> -#define ESPEAK_API_REVISION 5 +#include <stddef.h> + +#ifdef __WIN32__ +#define ESPEAK_API __declspec(dllexport) +#else +#define ESPEAK_API +#endif + +#define ESPEAK_API_REVISION 9 /* Revision 2 Added parameter "options" to eSpeakInitialize() @@ -40,21 +47,41 @@ Revision 4 Revision 5 Added espeakCHARS_16BIT + +Revision 6 + Added macros: espeakRATE_MINIMUM, espeakRATE_MAXIMUM, espeakRATE_NORMAL + +Revision 7 24.Dec.2011 + Changed espeak_EVENT structure to add id.string[] for phoneme mnemonics. + Added espeakINITIALIZE_PHONEME_IPA option for espeak_Initialize() to report phonemes as IPA names. + +Revision 8 26.Apr.2013 + Added function espeak_TextToPhonemes(). + +Revision 9 30.May.2013 + Changed function espeak_TextToPhonemes(). + */ /********************/ /* Initialization */ /********************/ +// values for 'value' in espeak_SetParameter(espeakRATE, value, 0), nominally in words-per-minute +#define espeakRATE_MINIMUM 80 +#define espeakRATE_MAXIMUM 450 +#define espeakRATE_NORMAL 175 + typedef enum { espeakEVENT_LIST_TERMINATED = 0, // Retrieval mode: terminates the event list. espeakEVENT_WORD = 1, // Start of word - espeakEVENT_SENTENCE, // Start of sentence - espeakEVENT_MARK, // Mark - espeakEVENT_PLAY, // Audio element - espeakEVENT_END, // End of sentence or clause - espeakEVENT_MSG_TERMINATED, // End of message - espeakEVENT_PHONEME // Phoneme, if enabled in espeak_Initialize() + espeakEVENT_SENTENCE = 2, // Start of sentence + espeakEVENT_MARK = 3, // Mark + espeakEVENT_PLAY = 4, // Audio element + espeakEVENT_END = 5, // End of sentence or clause + espeakEVENT_MSG_TERMINATED = 6, // End of message + espeakEVENT_PHONEME = 7, // Phoneme, if enabled in espeak_Initialize() + espeakEVENT_SAMPLERATE = 8 // internal use, set sample rate } espeak_EVENT_TYPE; @@ -68,11 +95,12 @@ typedef struct { int sample; // sample id (internal use) void* user_data; // pointer supplied by the calling program union { - int number; // used for WORD and SENTENCE events. For PHONEME events this is the phoneme mnemonic. + int number; // used for WORD and SENTENCE events. const char *name; // used for MARK and PLAY events. UTF8 string + char string[8]; // used for phoneme names (UTF8). Terminated by a zero byte unless the name needs the full 8 bytes. } id; } espeak_EVENT; -/* +/* When a message is supplied to espeak_synth, the request is buffered and espeak_synth returns. When the message is really processed, the callback function will be repetedly called. @@ -80,16 +108,16 @@ typedef struct { In PLAYBACK mode, the callback function is called as soon as an event happens. - For example suppose that the following message is supplied to espeak_Synth: + For example suppose that the following message is supplied to espeak_Synth: "hello, hello." * Once processed in RETRIEVAL mode, it could lead to 3 calls of the callback function : ** Block 1: - <audio data> + + <audio data> + List of events: SENTENCE + WORD + LIST_TERMINATED - + ** Block 2: <audio data> + List of events: WORD + END + LIST_TERMINATED @@ -126,11 +154,11 @@ typedef enum { typedef enum { /* PLAYBACK mode: plays the audio data, supplies events to the calling program*/ - AUDIO_OUTPUT_PLAYBACK, + AUDIO_OUTPUT_PLAYBACK, /* RETRIEVAL mode: supplies audio data and events to the calling program */ AUDIO_OUTPUT_RETRIEVAL, - + /* SYNCHRONOUS mode: as RETRIEVAL but doesn't return until synthesis is completed */ AUDIO_OUTPUT_SYNCHRONOUS, @@ -147,20 +175,26 @@ typedef enum { EE_NOT_FOUND=2 } espeak_ERROR; +#define espeakINITIALIZE_PHONEME_EVENTS 0x0001 +#define espeakINITIALIZE_PHONEME_IPA 0x0002 +#define espeakINITIALIZE_DONT_EXIT 0x8000 #ifdef __cplusplus extern "C" #endif -int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path, int options); +ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path, int options); /* 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. buflength: The length in mS of sound buffers passed to the SynthCallback function. + Value=0 gives a default of 200mS. + This paramater is only used for AUDIO_OUTPUT_RETRIEVAL and AUDIO_OUTPUT_SYNCHRONOUS modes. path: The directory which contains the espeak-data directory, or NULL for the default location. - options: bit 0: 1=allow espeakEVENT_PHONEME events. - + options: bit 0: 1=allow espeakEVENT_PHONEME events. + bit 1: 1= espeakEVENT_PHONEME events give IPA phoneme names, not eSpeak phoneme names + bit 15: 1=don't exit if espeak_data is not found (used for --help) Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR). */ @@ -170,10 +204,10 @@ typedef int (t_espeak_callback)(short*, int, espeak_EVENT*); #ifdef __cplusplus extern "C" #endif -void espeak_SetSynthCallback(t_espeak_callback* SynthCallback); +ESPEAK_API void espeak_SetSynthCallback(t_espeak_callback* SynthCallback); /* Must be called before any synthesis functions are called. This specifies a function in the calling program which is called when a buffer of - speech sound data has been produced. + speech sound data has been produced. The callback function is of the form: @@ -198,7 +232,7 @@ int SynthCallback(short *wav, int numsamples, espeak_EVENT *events); #ifdef __cplusplus extern "C" #endif -void espeak_SetUriCallback(int (*UriCallback)(int, const char*, const char*)); +ESPEAK_API void espeak_SetUriCallback(int (*UriCallback)(int, const char*, const char*)); /* This function may be called before synthesis functions are used, in order to deal with <audio> tags. It specifies a callback function which is called when an <audio> element is encountered and allows the calling program to indicate whether the sound file which @@ -239,7 +273,7 @@ int UriCallback(int type, const char *uri, const char *base); #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Synth(const void *text, +ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, @@ -262,7 +296,7 @@ espeak_ERROR espeak_Synth(const void *text, start of the text. position_type: Determines whether "position" is a number of characters, words, or sentences. - Values: + Values: end_position: If set, this gives a character position at which speaking will stop. A value of zero indicates no end position. @@ -273,6 +307,7 @@ espeak_ERROR espeak_Synth(const void *text, espeakCHARS_8BIT The 8 bit ISO-8859 character set for the particular language. espeakCHARS_AUTO 8 bit or UTF8 (this is the default) espeakCHARS_WCHAR Wide characters (wchar_t) + espeakCHARS_16BIT 16 bit characters. espeakSSML Elements within < > are treated as SSML elements, or if not recognised are ignored. @@ -281,13 +316,16 @@ espeak_ERROR espeak_Synth(const void *text, espeakENDPAUSE If set then a sentence pause is added at the end of the text. If not set then this pause is suppressed. - unique_identifier: message identifier; helpful for identifying later - data supplied to the callback. + unique_identifier: This must be either NULL, or point to an integer variable to + which eSpeak writes a message identifier number. + eSpeak includes this number in espeak_EVENT messages which are the result of + this call of espeak_Synth(). - user_data: pointer which will be passed to the callback function. + user_data: a pointer (or NULL) which will be passed to the callback function in + espeak_EVENT messages. - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -295,7 +333,7 @@ espeak_ERROR espeak_Synth(const void *text, #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Synth_Mark(const void *text, +ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, @@ -310,8 +348,8 @@ espeak_ERROR espeak_Synth_Mark(const void *text, For the other parameters, see espeak_Synth() - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -319,13 +357,13 @@ espeak_ERROR espeak_Synth_Mark(const void *text, #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Key(const char *key_name); +ESPEAK_API espeak_ERROR espeak_Key(const char *key_name); /* Speak the name of a keyboard key. If key_name is a single character, it speaks the name of the character. Otherwise, it speaks key_name as a text string. - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -333,11 +371,11 @@ espeak_ERROR espeak_Key(const char *key_name); #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Char(wchar_t character); -/* Speak the name of the given character +ESPEAK_API espeak_ERROR espeak_Char(wchar_t character); +/* Speak the name of the given character - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -378,22 +416,23 @@ typedef enum { #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative); +ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative); /* Sets the value of the specified parameter. relative=0 Sets the absolute value of the parameter. relative=1 Sets a relative value of the parameter. parameter: - espeakRATE: speaking speed in word per minute. + espeakRATE: speaking speed in word per minute. Values 80 to 450. - espeakVOLUME: volume in range 0-100 0=silence + espeakVOLUME: volume in range 0-200 or more. + 0=silence, 100=normal full volume, greater values may produce amplitude compression or distortion espeakPITCH: base pitch, range 0-100. 50=normal espeakRANGE: pitch range, range 0-100. 0-monotone, 50=normal espeakPUNCTUATION: which punctuation characters to announce: - value in espeak_PUNCT_TYPE (none, all, some), + value in espeak_PUNCT_TYPE (none, all, some), see espeak_GetParameter() to specify which characters are announced. espeakCAPITALS: announce capital letters by: @@ -405,8 +444,8 @@ espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int rela espeakWORDGAP: pause between words, units of 10mS (at the default speed) - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -414,7 +453,7 @@ espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int rela #ifdef __cplusplus extern "C" #endif -int espeak_GetParameter(espeak_PARAMETER parameter, int current); +ESPEAK_API int espeak_GetParameter(espeak_PARAMETER parameter, int current); /* current=0 Returns the default value of the specified parameter. current=1 Returns the current value of the specified parameter, as set by SetParameter() */ @@ -422,14 +461,14 @@ int espeak_GetParameter(espeak_PARAMETER parameter, int current); #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist); +ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist); /* Specified a list of punctuation characters whose names are to be spoken when the value of the Punctuation parameter is set to "some". punctlist: A list of character codes, terminated by a zero character. - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -437,11 +476,12 @@ espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist); #ifdef __cplusplus extern "C" #endif -void espeak_SetPhonemeTrace(int value, FILE *stream); +ESPEAK_API void espeak_SetPhonemeTrace(int value, FILE *stream); /* Controls the output of phoneme symbols for the text value=0 No phoneme output (default) value=1 Output the translated phoneme symbols for the text value=2 as (1), but also output a trace of how the translation was done (matching rules and list entries) + value=3 as (1), but produces IPA rather than ascii phoneme names stream output stream for the phoneme symbols (and trace). If stream=NULL then it uses stdout. */ @@ -449,7 +489,38 @@ void espeak_SetPhonemeTrace(int value, FILE *stream); #ifdef __cplusplus extern "C" #endif -void espeak_CompileDictionary(const char *path, FILE *log, int flags); +ESPEAK_API const char *espeak_TextToPhonemes(const void **textptr, int textmode, int phonememode); +/* Translates text into phonemes. Call espeak_SetVoiceByName() first, to select a language. + + It returns a pointer to a character string which contains the phonemes for the text up to + end of a sentence, or comma, semicolon, colon, or similar punctuation. + + textptr: The address of a pointer to the input text which is terminated by a zero character. + On return, the pointer has been advanced past the text which has been translated, or else set + to NULL to indicate that the end of the text has been reached. + + textmode: Type of character codes, one of: + espeakCHARS_UTF8 UTF8 encoding + espeakCHARS_8BIT The 8 bit ISO-8859 character set for the particular language. + espeakCHARS_AUTO 8 bit or UTF8 (this is the default) + espeakCHARS_WCHAR Wide characters (wchar_t) + espeakCHARS_16BIT 16 bit characters. + + phonememode: bits0-3: + 0= just phonemes. + 1= include ties (U+361) for phoneme names of more than one letter. + 2= include zero-width-joiner for phoneme names of more than one letter. + 3= separate phonemes with underscore characters. + + bits 4-7: + 0= eSpeak's ascii phoneme names. + 1= International Phonetic Alphabet (as UTF-8 characters). +*/ + +#ifdef __cplusplus +extern "C" +#endif +ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log, int flags); /* Compile pronunciation dictionary for a language which corresponds to the currently selected voice. The required voice should be selected before calling this function. @@ -473,7 +544,7 @@ typedef struct { unsigned char gender; // 0=none 1=male, 2=female, unsigned char age; // 0=not specified, or age in years unsigned char variant; // only used when passed as a parameter to espeak_SetVoiceByProperties - unsigned char xx1; // for internal use + unsigned char xx1; // for internal use int score; // for internal use void *spare; // for internal use } espeak_VOICE; @@ -502,24 +573,24 @@ typedef struct { #ifdef __cplusplus extern "C" #endif -const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec); +ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec); /* Reads the voice files from espeak-data/voices and creates an array of espeak_VOICE pointers. The list is terminated by a NULL pointer If voice_spec is NULL then all voices are listed. - If voice spec is give, then only the voices which are compatible with the voice_spec + If voice spec is given, then only the voices which are compatible with the voice_spec are listed, and they are listed in preference order. */ #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_SetVoiceByName(const char *name); +ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name); /* Searches for a voice with a matching "name" field. Language is not considered. "name" is a UTF8 string. - Return: EE_OK: operation achieved - EE_BUFFER_FULL: the command can not be buffered; + Return: EE_OK: operation achieved + EE_BUFFER_FULL: the command can not be buffered; you may try after a while to call the function again. EE_INTERNAL_ERROR. */ @@ -527,7 +598,7 @@ espeak_ERROR espeak_SetVoiceByName(const char *name); #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_spec); +ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_spec); /* An espeak_VOICE structure is used to pass criteria to select a voice. Any of the following fields may be set: @@ -547,7 +618,7 @@ espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_spec); #ifdef __cplusplus extern "C" #endif -espeak_VOICE *espeak_GetCurrentVoice(void); +ESPEAK_API espeak_VOICE *espeak_GetCurrentVoice(void); /* Returns the espeak_VOICE data for the currently selected voice. This is not affected by temporary voice changes caused by SSML elements such as <voice> and <s> */ @@ -555,12 +626,12 @@ espeak_VOICE *espeak_GetCurrentVoice(void); #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Cancel(void); +ESPEAK_API espeak_ERROR espeak_Cancel(void); /* Stop immediately synthesis and audio output of the current text. When this function returns, the audio output is fully stopped and the synthesizer is ready to synthesize a new message. - Return: EE_OK: operation achieved + Return: EE_OK: operation achieved EE_INTERNAL_ERROR. */ @@ -568,25 +639,25 @@ espeak_ERROR espeak_Cancel(void); #ifdef __cplusplus extern "C" #endif -int espeak_IsPlaying(void); +ESPEAK_API int espeak_IsPlaying(void); /* Returns 1 if audio is played, 0 otherwise. */ #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Synchronize(void); +ESPEAK_API espeak_ERROR espeak_Synchronize(void); /* This function returns when all data have been spoken. - Return: EE_OK: operation achieved + Return: EE_OK: operation achieved EE_INTERNAL_ERROR. */ #ifdef __cplusplus extern "C" #endif -espeak_ERROR espeak_Terminate(void); +ESPEAK_API espeak_ERROR espeak_Terminate(void); /* last function to be called. - Return: EE_OK: operation achieved + Return: EE_OK: operation achieved EE_INTERNAL_ERROR. */ @@ -594,8 +665,8 @@ espeak_ERROR espeak_Terminate(void); #ifdef __cplusplus extern "C" #endif -const char *espeak_Info(void); +ESPEAK_API const char *espeak_Info(const char **path_data); /* Returns the version number string. - The parameter is for future use, and should be set to NULL + path_data returns the path to espeak_data */ #endif |