2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #ifndef __TIZEN_UIX_TTS_H__
19 #define __TIZEN_UIX_TTS_H__
28 * @addtogroup CAPI_UIX_TTS_MODULE
33 * @brief Enumerations of error codes.
36 TTS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
37 TTS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
38 TTS_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
39 TTS_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
40 TTS_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */
41 TTS_ERROR_INVALID_STATE = TIZEN_ERROR_UIX_CLASS | 0x21, /**< Invalid state */
42 TTS_ERROR_INVALID_VOICE = TIZEN_ERROR_UIX_CLASS | 0x22, /**< Invalid voice */
43 TTS_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_UIX_CLASS | 0x23, /**< No available TTS-engine */
44 TTS_ERROR_TIMED_OUT = TIZEN_ERROR_UIX_CLASS | 0x24, /**< No answer from TTS daemon */
45 TTS_ERROR_OPERATION_FAILED = TIZEN_ERROR_UIX_CLASS | 0x25, /**< TTS daemon failed */
49 * @brief Enumerations of speaking speed.
52 TTS_SPEED_AUTO, /**< Speed from settings */
53 TTS_SPEED_VERY_SLOW, /**< Very slow */
54 TTS_SPEED_SLOW, /**< Slow */
55 TTS_SPEED_NORMAL, /**< Normal */
56 TTS_SPEED_FAST, /**< Fast */
57 TTS_SPEED_VERY_FAST /**< Very fast */
61 * @brief Enumerations of voice type.
64 TTS_VOICE_TYPE_AUTO, /**< Voice type from settings or auto selection based language */
65 TTS_VOICE_TYPE_MALE, /**< Male */
66 TTS_VOICE_TYPE_FEMALE, /**< Female */
67 TTS_VOICE_TYPE_CHILD, /**< Child */
68 TTS_VOICE_TYPE_USER1, /**< Engine defined */
69 TTS_VOICE_TYPE_USER2, /**< Engine defined */
70 TTS_VOICE_TYPE_USER3 /**< Engine defined */
74 * @brief Enumerations of state.
77 TTS_STATE_CREATED = 0, /**< 'CREATED' state */
78 TTS_STATE_READY, /**< 'READY' state */
79 TTS_STATE_PLAYING, /**< 'PLAYING' state */
80 TTS_STATE_PAUSED /**< 'PAUSED' state*/
84 * @brief A structure of handle for identification
86 typedef struct tts_s *tts_h;
89 * @brief Called when the state of TTS is changed.
91 * @details If the daemon must stop player because of changing engine and
92 * the daemon must pause player because of other requests, this callback function is called.
94 * @param[in] tts The handle for TTS
95 * @param[in] previous A previous state
96 * @param[in] current A current state
97 * @param[in] user_data The user data passed from the callback registration function.
99 * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
101 * @see tts_set_state_changed_cb()
102 * @see tts_unset_state_changed_cb()
104 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
107 * @brief Called when utterance has started.
109 * @param[in] tts The handle for TTS
110 * @param[in] utt_id The utterance ID passed from the add text function
111 * @param[in] user_data The user data passed from the callback registration function
113 * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
115 * @see tts_add_text()
116 * @see tts_set_utterance_started_cb()
117 * @see tts_unset_utterance_started_cb()
119 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
122 * @brief Called when utterance is finished.
124 * @param[in] tts The handle for TTS
125 * @param[in] utt_id The utterance ID passed from the add text function
126 * @param[in] user_data The user data passed from from the callback registration function
128 * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
130 * @see tts_add_text()
131 * @see tts_set_utterance_completed_cb()
132 * @see tts_unset_utterance_completed_cb()
134 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
137 * @brief Called when error occurred.
139 * @param[in] tts The handle for TTS
140 * @param[in] utt_id The utterance ID passed from the add text function
141 * @param[in] reason The error code
142 * @param[in] user_data The user data passed from the callback registration function
144 * @pre An application registers this callback using tts_set_error_cb() to detect error.
149 * @see tts_set_error_cb()
150 * @see tts_unset_error_cb()
152 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
155 * @brief Called to retrieve the supported voice.
157 * @param[in] tts The handle for TTS
158 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
159 * followed by ISO 639-1 for the two-letter language code. \n
160 * For example, "ko_KR" for Korean, "en_US" for American English
161 * @param[in] voice_type A voice type
162 * @param[in] user_data The user data passed from the foreach function
164 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
165 * @pre tts_foreach_supported_voices() will invoke this callback.
167 * @see tts_foreach_supported_voices()
169 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, tts_voice_type_e voice_type, void* user_data);
173 * @brief Creates a handle for TTS.
175 * @param[out] tts The handle for TTS
177 * @return 0 on success, otherwise a negative error value
178 * @retval #TTS_ERROR_NONE Successful
179 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
183 int tts_create(tts_h* tts);
186 * @brief Destroys the handle and disconnects the daemon.
188 * @param[in] tts The handle for TTS
190 * @return 0 on success, otherwise a negative error value
191 * @retval #TTS_ERROR_NONE Successful
192 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
196 int tts_destroy(tts_h tts);
199 * @brief Connects the daemon asynchronously.
201 * @param[in] tts The handle for TTS
203 * @return 0 on success, otherwise a negative error value
204 * @retval #TTS_ERROR_NONE Successful
205 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
206 * @retval #TTS_ERROR_INVALID_STATE Invalid state
208 * @pre The state should be #TTS_STATE_CREATED.
209 * @post If this function is called, the TTS state will be #TTS_STATE_READY.
211 * @see tts_unprepare()
213 int tts_prepare(tts_h tts);
216 * @brief Disconnects the daemon.
218 * @param[in] tts The handle for TTS
220 * @return 0 on success, otherwise a negative error value
221 * @retval #TTS_ERROR_NONE Successful
222 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
223 * @retval #STT_ERROR_INVALID_STATE Invalid state
225 * @pre The state should be #TTS_STATE_READY.
226 * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
230 int tts_unprepare(tts_h tts);
233 * @brief Retrieves all supported voices of the current engine using callback function.
235 * @param[in] tts The handle for TTS
236 * @param[in] callback The callback function to invoke
237 * @param[in] user_data The user data to be passed to the callback function
239 * @return 0 on success, otherwise a negative error value
240 * @retval #TTS_ERROR_NONE Successful
241 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
242 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
244 * @pre The state should be #TTS_STATE_READY.
245 * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices.
247 * @see tts_get_default_voice()
249 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
252 * @brief Gets the default voice set by user.
254 * @remark If the function succeeds, @a language must be released with free() by you.
256 * @param[in] tts The handle for TTS
257 * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
258 * followed by ISO 639-1 for the two-letter language code. \n
259 * For example, "ko_KR" for Korean, "en_US" for American English.
260 * @param[out] voice_type The voice type
262 * @return 0 on success, otherwise a negative error value.
263 * @retval #TTS_ERROR_NONE Successful
264 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
265 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
266 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
268 * @pre The state should be #TTS_STATE_READY.
270 * @see tts_foreach_supported_voices()
272 int tts_get_default_voice(tts_h tts, char** language, tts_voice_type_e* voice_type);
275 * @brief Gets the maximum text count of a current engine.
277 * @param[in] tts The handle for TTS
278 * @param[out] count The maximum text count of the current engine
280 * @return 0 on success, otherwise a negative error value
281 * @retval #TTS_ERROR_NONE Successful
282 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
283 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
285 * @pre The state should be #TTS_STATE_READY.
287 * @see tts_add_text()
289 int tts_get_max_text_count(tts_h tts, int* count);
292 * @brief Gets the current state of tts.
294 * @param[in] tts The handle for TTS
295 * @param[out] state The current state of TTS
297 * @return 0 on success, otherwise a negative error value
298 * @retval #TTS_ERROR_NONE Successful
299 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
300 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
306 int tts_get_state(tts_h tts, tts_state_e* state);
309 * @brief Adds a text to the queue.
311 * @param[in] tts The handle for TTS
312 * @param[in] text A input text
313 * @param[in] language The language selected from the foreach function
314 * @param[in] voice_type The voice type selected from the foreach function
315 * @param[in] speed A speaking speed
316 * @param[out] utt_id The utterance ID passed to the callback function
318 * @return 0 on success, otherwise a negative error value
319 * @retval #TTS_ERROR_NONE Successful
320 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
321 * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type
322 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
323 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
325 * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
326 * @see tts_get_max_text_count()
328 int tts_add_text(tts_h tts, const char* text, const char* language, tts_voice_type_e voice_type, tts_speed_e speed, int* utt_id);
331 * @brief Starts synthesizing voice from text and plays synthesized audio data.
333 * @param[in] tts The handle for TTS
335 * @return 0 on success, otherwise a negative error value
336 * @retval #TTS_ERROR_NONE Successful
337 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
338 * @retval #TTS_ERROR_INVALID_STATE Invalid state
339 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
341 * @pre The current state should be #TTS_STATE_READY or #TTS_STATE_PAUSED.
342 * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
344 * @see tts_add_text()
347 * @see tts_utterance_started_cb()
348 * @see tts_utterance_completed_cb()
349 * @see tts_error_cb()
350 * @see tts_interrupted_cb()
352 int tts_play(tts_h tts);
355 * @brief Stops playing utterance and clears queue.
357 * @param[in] tts The handle for TTS
359 * @return 0 on success, otherwise a negative error value
360 * @retval #TTS_ERROR_NONE Successful
361 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
362 * @retval #TTS_ERROR_INVALID_STATE Invalid state
363 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
365 * @pre The TTS state should be #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
366 * @post If this function succeeds, the TTS state will be #TTS_STATE_READY.
367 * This function will remove all text via tts_add_text() and synthesized sound data.
372 int tts_stop(tts_h tts);
375 * @brief Pauses currently playing utterance.
377 * @param[in] tts The handle for TTS
379 * @return 0 on success, otherwise a negative error value
380 * @retval #TTS_ERROR_NONE Successful
381 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
382 * @retval #TTS_ERROR_INVALID_STATE Invalid state
383 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
385 * @pre The TTS state should be #TTS_STATE_PLAYING.
386 * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED.
390 * @see tts_error_cb()
391 * @see tts_interrupted_cb()
393 int tts_pause(tts_h tts);
396 * @brief Registers a callback function to be called when TTS state changes.
398 * @param[in] tts The handle for TTS
399 * @param[in] callback The callback function to register
400 * @param[in] user_data The user data to be passed to the callback function
402 * @return 0 on success, otherwise a negative error value
403 * @retval #TTS_ERROR_NONE Successful
404 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
406 * @pre The state should be #TTS_STATE_CREATED.
408 * @see tts_state_changed_cb()
409 * @see tts_unset_state_changed_cb()
411 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
414 * @brief Unregisters the callback function.
416 * @param[in] tts The handle for TTS
418 * @return 0 on success, otherwise a negative error value
419 * @retval #TTS_ERROR_NONE Successful
420 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
422 * @pre The state should be #TTS_STATE_CREATED.
424 * @see tts_set_state_changed_cb()
426 int tts_unset_state_changed_cb(tts_h tts);
429 * @brief Registers a callback function for detecting utterance started.
431 * @param[in] tts The handle for TTS
432 * @param[in] callback The callback function to register
433 * @param[in] user_data The user data to be passed to the callback function
435 * @return 0 on success, otherwise a negative error value
436 * @retval #TTS_ERROR_NONE Successful
437 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
439 * @pre The state should be #TTS_STATE_CREATED.
441 * @see tts_utterance_started_cb()
442 * @see tts_unset_utterance_started_cb()
444 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
447 * @brief Unregisters the callback function.
449 * @param[in] tts The handle for TTS
451 * @return 0 on success, otherwise a negative error value
452 * @retval #TTS_ERROR_NONE Successful
453 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
455 * @pre The state should be #TTS_STATE_CREATED.
457 * @see tts_set_utterance_started_cb()
459 int tts_unset_utterance_started_cb(tts_h tts);
462 * @brief Registers a callback function for detecting utterance completed.
464 * @param[in] tts The handle for TTS
465 * @param[in] callback The callback function to register
466 * @param[in] user_data The user data to be passed to the callback function
468 * @return 0 on success, otherwise a negative error value
469 * @retval #TTS_ERROR_NONE Successful
470 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
472 * @pre The state should be #TTS_STATE_CREATED.
474 * @see tts_utterance_completed_cb()
475 * @see tts_unset_utterance_completed_cb()
477 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
480 * @brief Unregisters the callback function.
482 * @param[in] tts The handle for TTS
484 * @return 0 on success, otherwise a negative error value
485 * @retval #TTS_ERROR_NONE Successful
486 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
488 * @pre The state should be #TTS_STATE_CREATED.
490 * @see tts_set_utterance_completed_cb()
492 int tts_unset_utterance_completed_cb(tts_h tts);
495 * @brief Registers a callback function for detecting error.
497 * @param[in] tts The handle for TTS
498 * @param[in] callback The callback function to register
499 * @param[in] user_data The user data to be passed to the callback function
501 * @return 0 on success, otherwise a negative error value
502 * @retval #TTS_ERROR_NONE Successful
503 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
505 * @pre The state should be #TTS_STATE_CREATED.
507 * @see tts_error_cb()
508 * @see tts_unset_error_cb()
510 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
513 * @brief Unregisters the callback function.
515 * @param[in] tts The handle for TTS
517 * @return 0 on success, otherwise a negative error value
518 * @retval #TTS_ERROR_NONE Successful
519 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
521 * @pre The state should be #TTS_STATE_CREATED.
523 * @see tts_set_error_cb()
525 int tts_unset_error_cb(tts_h tts);
535 #endif /* __TIZEN_UIX_TTS_H__ */