/native/external/espeak/platforms/windows/windows_dll/src/speak_lib.h

http://eyes-free.googlecode.com/ · C Header · 593 lines · 186 code · 60 blank · 347 comment · 0 complexity · ad1c3fd58ab00ceb879a2bd1dae5c8c9 MD5 · raw file

  1. #ifndef SPEAK_LIB_H
  2. #define SPEAK_LIB_H
  3. /***************************************************************************
  4. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  5. * email: jonsd@users.sourceforge.net *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * You should have received a copy of the GNU General Public License *
  18. * along with this program; if not, see: *
  19. * <http://www.gnu.org/licenses/>. *
  20. ***************************************************************************/
  21. /*************************************************************/
  22. /* This is the header file for the library version of espeak */
  23. /* */
  24. /*************************************************************/
  25. #define ESPEAK_API __declspec(dllexport)
  26. #include <stdio.h>
  27. #define ESPEAK_API_REVISION 3
  28. /*
  29. Revision 2
  30. Added parameter "options" to eSpeakInitialize()
  31. Revision 3
  32. Added espeakWORDGAP to espeak_PARAMETER
  33. */
  34. /********************/
  35. /* Initialization */
  36. /********************/
  37. typedef enum {
  38. espeakEVENT_LIST_TERMINATED = 0, // Retrieval mode: terminates the event list.
  39. espeakEVENT_WORD = 1, // Start of word
  40. espeakEVENT_SENTENCE, // Start of sentence
  41. espeakEVENT_MARK, // Mark
  42. espeakEVENT_PLAY, // Audio element
  43. espeakEVENT_END, // End of sentence
  44. espeakEVENT_MSG_TERMINATED, // End of message
  45. espeakEVENT_PHONEME // Phoneme, if enabled in espeak_Initialize()
  46. } espeak_EVENT_TYPE;
  47. typedef struct {
  48. espeak_EVENT_TYPE type;
  49. unsigned int unique_identifier; // message identifier (or 0 for key or character)
  50. int text_position; // the number of characters from the start of the text
  51. int length; // word length, in characters (for espeakEVENT_WORD)
  52. int audio_position; // the time in mS within the generated speech output data
  53. int sample; // sample id (internal use)
  54. void* user_data; // pointer supplied by the calling program
  55. union {
  56. int number; // used for WORD and SENTENCE events. For PHONEME events this is the phoneme mnemonic.
  57. const char *name; // used for MARK and PLAY events. UTF8 string
  58. } id;
  59. } espeak_EVENT;
  60. /*
  61. 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.
  62. In RETRIEVAL mode, the callback function supplies to the calling program the audio data and an event list terminated by 0 (LIST_TERMINATED).
  63. In PLAYBACK mode, the callback function is called as soon as an event happens.
  64. For example suppose that the following message is supplied to espeak_Synth:
  65. "hello, hello."
  66. * Once processed in RETRIEVAL mode, it could lead to 3 calls of the callback function :
  67. ** Block 1:
  68. <audio data> +
  69. List of events: SENTENCE + WORD + LIST_TERMINATED
  70. ** Block 2:
  71. <audio data> +
  72. List of events: WORD + END + LIST_TERMINATED
  73. ** Block 3:
  74. no audio data
  75. List of events: MSG_TERMINATED + LIST_TERMINATED
  76. * Once processed in PLAYBACK mode, it could lead to 5 calls of the callback function:
  77. ** SENTENCE
  78. ** WORD (call when the sounds are actually played)
  79. ** WORD
  80. ** END (call when the end of sentence is actually played.)
  81. ** MSG_TERMINATED
  82. The MSG_TERMINATED event is the last event. It can inform the calling program to clear the user data related to the message.
  83. So if the synthesis must be stopped, the callback function is called for each pending message with the MSG_TERMINATED event.
  84. A MARK event indicates a <mark> element in the text.
  85. A PLAY event indicates an <audio> element in the text, for which the calling program should play the named sound file.
  86. */
  87. typedef enum {
  88. POS_CHARACTER = 1,
  89. POS_WORD,
  90. POS_SENTENCE
  91. } espeak_POSITION_TYPE;
  92. typedef enum {
  93. /* PLAYBACK mode: plays the audio data, supplies events to the calling program*/
  94. AUDIO_OUTPUT_PLAYBACK,
  95. /* RETRIEVAL mode: supplies audio data and events to the calling program */
  96. AUDIO_OUTPUT_RETRIEVAL,
  97. /* SYNCHRONOUS mode: as RETRIEVAL but doesn't return until synthesis is completed */
  98. AUDIO_OUTPUT_SYNCHRONOUS,
  99. /* Synchronous playback */
  100. AUDIO_OUTPUT_SYNCH_PLAYBACK
  101. } espeak_AUDIO_OUTPUT;
  102. typedef enum {
  103. EE_OK=0,
  104. EE_INTERNAL_ERROR=-1,
  105. EE_BUFFER_FULL=1,
  106. EE_NOT_FOUND=2
  107. } espeak_ERROR;
  108. #ifdef __cplusplus
  109. extern "C"
  110. #endif
  111. ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path, int options);
  112. /* Must be called before any synthesis functions are called.
  113. output: the audio data can either be played by eSpeak or passed back by the SynthCallback function.
  114. buflength: The length in mS of sound buffers passed to the SynthCallback function.
  115. path: The directory which contains the espeak-data directory, or NULL for the default location.
  116. options: bit 0: 1=allow espeakEVENT_PHONEME events.
  117. Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR).
  118. */
  119. typedef int (t_espeak_callback)(short*, int, espeak_EVENT*);
  120. #ifdef __cplusplus
  121. extern "C"
  122. #endif
  123. ESPEAK_API void espeak_SetSynthCallback(t_espeak_callback* SynthCallback);
  124. /* Must be called before any synthesis functions are called.
  125. This specifies a function in the calling program which is called when a buffer of
  126. speech sound data has been produced.
  127. The callback function is of the form:
  128. int SynthCallback(short *wav, int numsamples, espeak_EVENT *events);
  129. wav: is the speech sound data which has been produced.
  130. NULL indicates that the synthesis has been completed.
  131. numsamples: is the number of entries in wav. This number may vary, may be less than
  132. the value implied by the buflength parameter given in espeak_Initialize, and may
  133. sometimes be zero (which does NOT indicate end of synthesis).
  134. events: an array of espeak_EVENT items which indicate word and sentence events, and
  135. also the occurance if <mark> and <audio> elements within the text. The list of
  136. events is terminated by an event of type = 0.
  137. Callback returns: 0=continue synthesis, 1=abort synthesis.
  138. */
  139. #ifdef __cplusplus
  140. extern "C"
  141. #endif
  142. ESPEAK_API void espeak_SetUriCallback(int (*UriCallback)(int, const char*, const char*));
  143. /* This function may be called before synthesis functions are used, in order to deal with
  144. <audio> tags. It specifies a callback function which is called when an <audio> element is
  145. encountered and allows the calling program to indicate whether the sound file which
  146. is specified in the <audio> element is available and is to be played.
  147. The callback function is of the form:
  148. int UriCallback(int type, const char *uri, const char *base);
  149. type: type of callback event. Currently only 1= <audio> element
  150. uri: the "src" attribute from the <audio> element
  151. base: the "xml:base" attribute (if any) from the <speak> element
  152. Return: 1=don't play the sound, but speak the text alternative.
  153. 0=place a PLAY event in the event list at the point where the <audio> element
  154. occurs. The calling program can then play the sound at that point.
  155. */
  156. /********************/
  157. /* Synthesis */
  158. /********************/
  159. #define espeakCHARS_AUTO 0
  160. #define espeakCHARS_UTF8 1
  161. #define espeakCHARS_8BIT 2
  162. #define espeakCHARS_WCHAR 3
  163. #define espeakSSML 0x10
  164. #define espeakPHONEMES 0x100
  165. #define espeakENDPAUSE 0x1000
  166. #define espeakKEEP_NAMEDATA 0x2000
  167. #ifdef __cplusplus
  168. extern "C"
  169. #endif
  170. ESPEAK_API espeak_ERROR espeak_Synth(const void *text,
  171. size_t size,
  172. unsigned int position,
  173. espeak_POSITION_TYPE position_type,
  174. unsigned int end_position,
  175. unsigned int flags,
  176. unsigned int* unique_identifier,
  177. void* user_data);
  178. /* Synthesize speech for the specified text. The speech sound data is passed to the calling
  179. program in buffers by means of the callback function specified by espeak_SetSynthCallback(). The command is asynchronous: it is internally buffered and returns as soon as possible. If espeak_Initialize was previously called with AUDIO_OUTPUT_PLAYBACK as argument, the sound data are played by eSpeak.
  180. text: The text to be spoken, terminated by a zero character. It may be either 8-bit characters,
  181. wide characters (wchar_t), or UTF8 encoding. Which of these is determined by the "flags"
  182. parameter.
  183. size: Equal to (or greatrer than) the size of the text data, in bytes. This is used in order
  184. to allocate internal storage space for the text. This value is not used for
  185. AUDIO_OUTPUT_SYNCHRONOUS mode.
  186. position: The position in the text where speaking starts. Zero indicates speak from the
  187. start of the text.
  188. position_type: Determines whether "position" is a number of characters, words, or sentences.
  189. Values:
  190. end_position: If set, this gives a character position at which speaking will stop. A value
  191. of zero indicates no end position.
  192. flags: These may be OR'd together:
  193. Type of character codes, one of:
  194. espeakCHARS_UTF8 UTF8 encoding
  195. espeakCHARS_8BIT The 8 bit ISO-8859 character set for the particular language.
  196. espeakCHARS_AUTO 8 bit or UTF8 (this is the default)
  197. espeakCHARS_WCHAR Wide characters (wchar_t)
  198. espeakSSML Elements within < > are treated as SSML elements, or if not recognised are ignored.
  199. espeakPHONEMES Text within [[ ]] is treated as phonemes codes (in espeak's Hirshenbaum encoding).
  200. espeakENDPAUSE If set then a sentence pause is added at the end of the text. If not set then
  201. this pause is suppressed.
  202. unique_identifier: message identifier; helpful for identifying later
  203. data supplied to the callback.
  204. user_data: pointer which will be passed to the callback function.
  205. Return: EE_OK: operation achieved
  206. EE_BUFFER_FULL: the command can not be buffered;
  207. you may try after a while to call the function again.
  208. EE_INTERNAL_ERROR.
  209. */
  210. #ifdef __cplusplus
  211. extern "C"
  212. #endif
  213. ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text,
  214. size_t size,
  215. const char *index_mark,
  216. unsigned int end_position,
  217. unsigned int flags,
  218. unsigned int* unique_identifier,
  219. void* user_data);
  220. /* Synthesize speech for the specified text. Similar to espeak_Synth() but the start position is
  221. specified by the name of a <mark> element in the text.
  222. index_mark: The "name" attribute of a <mark> element within the text which specified the
  223. point at which synthesis starts. UTF8 string.
  224. For the other parameters, see espeak_Synth()
  225. Return: EE_OK: operation achieved
  226. EE_BUFFER_FULL: the command can not be buffered;
  227. you may try after a while to call the function again.
  228. EE_INTERNAL_ERROR.
  229. */
  230. #ifdef __cplusplus
  231. extern "C"
  232. #endif
  233. ESPEAK_API espeak_ERROR espeak_Key(const char *key_name);
  234. /* Speak the name of a keyboard key.
  235. Currently this just speaks the "key_name" as given
  236. Return: EE_OK: operation achieved
  237. EE_BUFFER_FULL: the command can not be buffered;
  238. you may try after a while to call the function again.
  239. EE_INTERNAL_ERROR.
  240. */
  241. #ifdef __cplusplus
  242. extern "C"
  243. #endif
  244. ESPEAK_API espeak_ERROR espeak_Char(wchar_t character);
  245. /* Speak the name of the given character
  246. Return: EE_OK: operation achieved
  247. EE_BUFFER_FULL: the command can not be buffered;
  248. you may try after a while to call the function again.
  249. EE_INTERNAL_ERROR.
  250. */
  251. /* Note, there is no function to play a sound icon. This would be done by the calling program */
  252. /***********************/
  253. /* Speech Parameters */
  254. /***********************/
  255. typedef enum {
  256. espeakSILENCE=0, /* internal use */
  257. espeakRATE=1,
  258. espeakVOLUME=2,
  259. espeakPITCH=3,
  260. espeakRANGE=4,
  261. espeakPUNCTUATION=5,
  262. espeakCAPITALS=6,
  263. espeakWORDGAP=7,
  264. espeakOPTIONS=8, // reserved for misc. options. not yet used
  265. espeakINTONATION=9,
  266. espeakRESERVED1=10,
  267. espeakRESERVED2=11,
  268. espeakEMPHASIS, /* internal use */
  269. espeakLINELENGTH, /* internal use */
  270. espeakVOICETYPE, // internal, 1=mbrola
  271. N_SPEECH_PARAM /* last enum */
  272. } espeak_PARAMETER;
  273. typedef enum {
  274. espeakPUNCT_NONE=0,
  275. espeakPUNCT_ALL=1,
  276. espeakPUNCT_SOME=2
  277. } espeak_PUNCT_TYPE;
  278. #ifdef __cplusplus
  279. extern "C"
  280. #endif
  281. ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int value, int relative);
  282. /* Sets the value of the specified parameter.
  283. relative=0 Sets the absolute value of the parameter.
  284. relative=1 Sets a relative value of the parameter.
  285. parameter:
  286. espeakRATE: speaking speed in word per minute.
  287. espeakVOLUME: volume in range 0-100 0=silence
  288. espeakPITCH: base pitch, range 0-100. 50=normal
  289. espeakRANGE: pitch range, range 0-100. 0-monotone, 50=normal
  290. espeakPUNCTUATION: which punctuation characters to announce:
  291. value in espeak_PUNCT_TYPE (none, all, some),
  292. see espeak_GetParameter() to specify which characters are announced.
  293. espeakCAPITALS: announce capital letters by:
  294. 0=none,
  295. 1=sound icon,
  296. 2=spelling,
  297. 3 or higher, by raising pitch. This values gives the amount in Hz by which the pitch
  298. of a word raised to indicate it has a capital letter.
  299. espeakWORDGAP: pause between words, units of 10mS (at the default speed)
  300. Return: EE_OK: operation achieved
  301. EE_BUFFER_FULL: the command can not be buffered;
  302. you may try after a while to call the function again.
  303. EE_INTERNAL_ERROR.
  304. */
  305. #ifdef __cplusplus
  306. extern "C"
  307. #endif
  308. ESPEAK_API int espeak_GetParameter(espeak_PARAMETER parameter, int current);
  309. /* current=0 Returns the default value of the specified parameter.
  310. current=1 Returns the current value of the specified parameter, as set by SetParameter()
  311. */
  312. #ifdef __cplusplus
  313. extern "C"
  314. #endif
  315. ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist);
  316. /* Specified a list of punctuation characters whose names are to be spoken when the
  317. value of the Punctuation parameter is set to "some".
  318. punctlist: A list of character codes, terminated by a zero character.
  319. Return: EE_OK: operation achieved
  320. EE_BUFFER_FULL: the command can not be buffered;
  321. you may try after a while to call the function again.
  322. EE_INTERNAL_ERROR.
  323. */
  324. #ifdef __cplusplus
  325. extern "C"
  326. #endif
  327. ESPEAK_API void espeak_SetPhonemeTrace(int value, FILE *stream);
  328. /* Controls the output of phoneme symbols for the text
  329. value=0 No phoneme output (default)
  330. value=1 Output the translated phoneme symbols for the text
  331. value=2 as (1), but also output a trace of how the translation was done (matching rules and list entries)
  332. stream output stream for the phoneme symbols (and trace). If stream=NULL then it uses stdout.
  333. */
  334. #ifdef __cplusplus
  335. extern "C"
  336. #endif
  337. ESPEAK_API void espeak_CompileDictionary(const char *path, FILE *log);
  338. /* Compile pronunciation dictionary for a language which corresponds to the currently
  339. selected voice. The required voice should be selected before calling this function.
  340. path: The directory which contains the language's '_rules' and '_list' files.
  341. 'path' should end with a path separator character ('/').
  342. log: Stream for error reports and statistics information. If log=NULL then stderr will be used.
  343. */
  344. /***********************/
  345. /* Voice Selection */
  346. /***********************/
  347. // voice table
  348. typedef struct {
  349. char *name; // a given name for this voice. UTF8 string.
  350. char *languages; // list of pairs of (byte) priority + (string) language (and dialect qualifier)
  351. char *identifier; // the filename for this voice within espeak-data/voices
  352. unsigned char gender; // 0=none 1=male, 2=female,
  353. unsigned char age; // 0=not specified, or age in years
  354. unsigned char variant; // only used when passed as a parameter to espeak_SetVoiceByProperties
  355. unsigned char xx1; // for internal use
  356. int score; // for internal use
  357. void *spare; // for internal use
  358. } espeak_VOICE;
  359. /* Note: The espeak_VOICE structure is used for two purposes:
  360. 1. To return the details of the available voices.
  361. 2. As a parameter to espeak_SetVoiceByProperties() in order to specify selection criteria.
  362. In (1), the "languages" field consists of a list of (UTF8) language names for which this voice
  363. may be used, each language name in the list is terminated by a zero byte and is also preceded by
  364. a single byte which gives a "priority" number. The list of languages is terminated by an
  365. additional zero byte.
  366. A language name consists of a language code, optionally followed by one or more qualifier (dialect)
  367. names separated by hyphens (eg. "en-uk"). A voice might, for example, have languages "en-uk" and
  368. "en". Even without "en" listed, voice would still be selected for the "en" language (because
  369. "en-uk" is related) but at a lower priority.
  370. The priority byte indicates how the voice is preferred for the language. A low number indicates a
  371. more preferred voice, a higher number indicates a less preferred voice.
  372. In (2), the "languages" field consists simply of a single (UTF8) language name, with no preceding
  373. priority byte.
  374. */
  375. #ifdef __cplusplus
  376. extern "C"
  377. #endif
  378. ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec);
  379. /* Reads the voice files from espeak-data/voices and creates an array of espeak_VOICE pointers.
  380. The list is terminated by a NULL pointer
  381. If voice_spec is NULL then all voices are listed.
  382. If voice spec is give, then only the voices which are compatible with the voice_spec
  383. are listed, and they are listed in preference order.
  384. */
  385. #ifdef __cplusplus
  386. extern "C"
  387. #endif
  388. ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name);
  389. /* Searches for a voice with a matching "name" field. Language is not considered.
  390. "name" is a UTF8 string.
  391. Return: EE_OK: operation achieved
  392. EE_BUFFER_FULL: the command can not be buffered;
  393. you may try after a while to call the function again.
  394. EE_INTERNAL_ERROR.
  395. */
  396. #ifdef __cplusplus
  397. extern "C"
  398. #endif
  399. ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_spec);
  400. /* An espeak_VOICE structure is used to pass criteria to select a voice. Any of the following
  401. fields may be set:
  402. name NULL, or a voice name
  403. languages NULL, or a single language string (with optional dialect), eg. "en-uk", or "en"
  404. gender 0=not specified, 1=male, 2=female
  405. age 0=not specified, or an age in years
  406. variant After a list of candidates is produced, scored and sorted, "variant" is used to index
  407. that list and choose a voice.
  408. variant=0 takes the top voice (i.e. best match). variant=1 takes the next voice, etc
  409. */
  410. #ifdef __cplusplus
  411. extern "C"
  412. #endif
  413. ESPEAK_API espeak_VOICE *espeak_GetCurrentVoice(void);
  414. /* Returns the espeak_VOICE data for the currently selected voice.
  415. This is not affected by temporary voice changes caused by SSML elements such as <voice> and <s>
  416. */
  417. #ifdef __cplusplus
  418. extern "C"
  419. #endif
  420. ESPEAK_API espeak_ERROR espeak_Cancel(void);
  421. /* Stop immediately synthesis and audio output of the current text. When this
  422. function returns, the audio output is fully stopped and the synthesizer is ready to
  423. synthesize a new message.
  424. Return: EE_OK: operation achieved
  425. EE_INTERNAL_ERROR.
  426. */
  427. #ifdef __cplusplus
  428. extern "C"
  429. #endif
  430. ESPEAK_API int espeak_IsPlaying(void);
  431. /* Returns 1 if audio is played, 0 otherwise.
  432. */
  433. #ifdef __cplusplus
  434. extern "C"
  435. #endif
  436. ESPEAK_API espeak_ERROR espeak_Synchronize(void);
  437. /* This function returns when all data have been spoken.
  438. Return: EE_OK: operation achieved
  439. EE_INTERNAL_ERROR.
  440. */
  441. #ifdef __cplusplus
  442. extern "C"
  443. #endif
  444. ESPEAK_API espeak_ERROR espeak_Terminate(void);
  445. /* last function to be called.
  446. Return: EE_OK: operation achieved
  447. EE_INTERNAL_ERROR.
  448. */
  449. #ifdef __cplusplus
  450. extern "C"
  451. #endif
  452. ESPEAK_API const char *espeak_Info(void* ptr);
  453. /* Returns the version number string.
  454. The parameter is for future use, and should be set to NULL
  455. */
  456. #endif