2 * Copyright (c) 2012, 2013 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.
25 * @addtogroup CAPI_UIX_TTS_MODULE
34 * @brief Enumerations of error codes.
37 TTS_ERROR_NONE = 0, /**< Successful */
38 TTS_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */
39 TTS_ERROR_IO_ERROR = -EIO, /**< I/O error */
40 TTS_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
41 TTS_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */
42 TTS_ERROR_INVALID_STATE = -0x0100000 | 0x21, /**< Invalid state */
43 TTS_ERROR_INVALID_VOICE = -0x0100000 | 0x22, /**< Invalid voice */
44 TTS_ERROR_ENGINE_NOT_FOUND = -0x0100000 | 0x23, /**< No available engine */
45 TTS_ERROR_TIMED_OUT = -0x0100000 | 0x24, /**< No answer from the daemon */
46 TTS_ERROR_OPERATION_FAILED = -0x0100000 | 0x25 /**< Operation failed */
50 * @brief Enumerations of tts mode.
53 TTS_MODE_DEFAULT = 0, /**< Default mode for normal application */
54 TTS_MODE_NOTIFICATION, /**< Notification mode */
55 TTS_MODE_SCREEN_READER /**< Screen reader mode */
59 * @brief Enumerations of speaking speed.
62 TTS_SPEED_AUTO, /**< Speed from settings */
63 TTS_SPEED_VERY_SLOW, /**< Very slow */
64 TTS_SPEED_SLOW, /**< Slow */
65 TTS_SPEED_NORMAL, /**< Normal */
66 TTS_SPEED_FAST, /**< Fast */
67 TTS_SPEED_VERY_FAST /**< Very fast */
71 * @brief Enumerations of voice type.
74 TTS_VOICE_TYPE_AUTO, /**< Voice type from settings or auto selection based language */
75 TTS_VOICE_TYPE_MALE, /**< Male */
76 TTS_VOICE_TYPE_FEMALE, /**< Female */
77 TTS_VOICE_TYPE_CHILD, /**< Child */
78 TTS_VOICE_TYPE_USER1, /**< Engine defined */
79 TTS_VOICE_TYPE_USER2, /**< Engine defined */
80 TTS_VOICE_TYPE_USER3 /**< Engine defined */
84 * @brief Enumerations of state.
87 TTS_STATE_CREATED = 0, /**< 'CREATED' state */
88 TTS_STATE_READY, /**< 'READY' state */
89 TTS_STATE_PLAYING, /**< 'PLAYING' state */
90 TTS_STATE_PAUSED /**< 'PAUSED' state*/
94 * @brief A structure of handle for identification
96 typedef struct tts_s *tts_h;
100 * @brief Called when the state of TTS is changed.
102 * @details If the daemon must stop player because of changing engine and
103 * the daemon must pause player because of other requests, this callback function is called.
105 * @param[in] tts The handle for TTS
106 * @param[in] previous A previous state
107 * @param[in] current A current state
108 * @param[in] user_data The user data passed from the callback registration function.
110 * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
112 * @see tts_set_state_changed_cb()
113 * @see tts_unset_state_changed_cb()
115 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
118 * @brief Called when utterance has started.
120 * @param[in] tts The handle for TTS
121 * @param[in] utt_id The utterance ID passed from the add text function
122 * @param[in] user_data The user data passed from the callback registration function
124 * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
126 * @see tts_add_text()
127 * @see tts_set_utterance_started_cb()
128 * @see tts_unset_utterance_started_cb()
130 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
133 * @brief Called when utterance is finished.
135 * @param[in] tts The handle for TTS
136 * @param[in] utt_id The utterance ID passed from the add text function
137 * @param[in] user_data The user data passed from from the callback registration function
139 * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
141 * @see tts_add_text()
142 * @see tts_set_utterance_completed_cb()
143 * @see tts_unset_utterance_completed_cb()
145 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
148 * @brief Called when error occurred.
150 * @param[in] tts The handle for TTS
151 * @param[in] utt_id The utterance ID passed from the add text function
152 * @param[in] reason The error code
153 * @param[in] user_data The user data passed from the callback registration function
155 * @pre An application registers this callback using tts_set_error_cb() to detect error.
160 * @see tts_set_error_cb()
161 * @see tts_unset_error_cb()
163 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
166 * @brief Called to retrieve the supported voice.
168 * @param[in] tts The handle for TTS
169 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
170 * followed by ISO 639-1 for the two-letter language code. \n
171 * For example, "ko_KR" for Korean, "en_US" for American English
172 * @param[in] voice_type A voice type
173 * @param[in] user_data The user data passed from the foreach function
175 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
176 * @pre tts_foreach_supported_voices() will invoke this callback.
178 * @see tts_foreach_supported_voices()
180 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, tts_voice_type_e voice_type, void* user_data);
184 * @brief Creates a handle for TTS.
186 * @param[out] tts The handle for TTS
188 * @return 0 on success, otherwise a negative error value
189 * @retval #TTS_ERROR_NONE Successful
190 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
194 int tts_create(tts_h* tts);
197 * @brief Destroys the handle and disconnects the daemon.
199 * @param[in] tts The handle for TTS
201 * @return 0 on success, otherwise a negative error value
202 * @retval #TTS_ERROR_NONE Successful
203 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
207 int tts_destroy(tts_h tts);
210 * @brief Set tts mode.
212 * @param[in] tts The handle for TTS
213 * @param[in] mode The mode
215 * @return 0 on success, otherwise a negative error value
216 * @retval #TTS_ERROR_NONE Successful
217 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
218 * @retval #TTS_ERROR_INVALID_STATE Invalid state
220 * @pre The state should be #TTS_STATE_CREATED.
222 * @see tts_get_mode()
224 int tts_set_mode(tts_h tts, tts_mode_e mode);
227 * @brief Get tts mode.
229 * @param[in] tts The handle for TTS
230 * @param[out] mode The mode
232 * @return 0 on success, otherwise a negative error value
233 * @retval #TTS_ERROR_NONE Successful
234 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
235 * @retval #TTS_ERROR_INVALID_STATE Invalid state
237 * @pre The state should be #TTS_STATE_CREATED.
239 * @see tts_set_mode()
241 int tts_get_mode(tts_h tts, tts_mode_e* mode);
244 * @brief Connects the daemon asynchronously.
246 * @param[in] tts The handle for TTS
248 * @return 0 on success, otherwise a negative error value
249 * @retval #TTS_ERROR_NONE Successful
250 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
251 * @retval #TTS_ERROR_INVALID_STATE Invalid state
253 * @pre The state should be #TTS_STATE_CREATED.
254 * @post If this function is called, the TTS state will be #TTS_STATE_READY.
256 * @see tts_unprepare()
258 int tts_prepare(tts_h tts);
261 * @brief Disconnects the daemon.
263 * @param[in] tts The handle for TTS
265 * @return 0 on success, otherwise a negative error value
266 * @retval #TTS_ERROR_NONE Successful
267 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
268 * @retval #STT_ERROR_INVALID_STATE Invalid state
270 * @pre The state should be #TTS_STATE_READY.
271 * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
275 int tts_unprepare(tts_h tts);
278 * @brief Retrieves all supported voices of the current engine using callback function.
280 * @param[in] tts The handle for TTS
281 * @param[in] callback The callback function to invoke
282 * @param[in] user_data The user data to be passed to the callback function
284 * @return 0 on success, otherwise a negative error value
285 * @retval #TTS_ERROR_NONE Successful
286 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
287 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
289 * @pre The state should be #TTS_STATE_READY.
290 * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices.
292 * @see tts_get_default_voice()
294 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
297 * @brief Gets the default voice set by user.
299 * @remark If the function succeeds, @a language must be released with free() by you.
301 * @param[in] tts The handle for TTS
302 * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
303 * followed by ISO 639-1 for the two-letter language code. \n
304 * For example, "ko_KR" for Korean, "en_US" for American English.
305 * @param[out] voice_type The voice type
307 * @return 0 on success, otherwise a negative error value.
308 * @retval #TTS_ERROR_NONE Successful
309 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
310 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
311 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
313 * @pre The state should be #TTS_STATE_READY.
315 * @see tts_foreach_supported_voices()
317 int tts_get_default_voice(tts_h tts, char** language, tts_voice_type_e* voice_type);
320 * @brief Gets the maximum text count of a current engine.
322 * @param[in] tts The handle for TTS
323 * @param[out] count The maximum text count of the current engine
325 * @return 0 on success, otherwise a negative error value
326 * @retval #TTS_ERROR_NONE Successful
327 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
328 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
330 * @pre The state should be #TTS_STATE_READY.
332 * @see tts_add_text()
334 int tts_get_max_text_count(tts_h tts, int* count);
337 * @brief Gets the current state of tts.
339 * @param[in] tts The handle for TTS
340 * @param[out] state The current state of TTS
342 * @return 0 on success, otherwise a negative error value
343 * @retval #TTS_ERROR_NONE Successful
344 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
345 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
351 int tts_get_state(tts_h tts, tts_state_e* state);
354 * @brief Adds a text to the queue.
356 * @param[in] tts The handle for TTS
357 * @param[in] text A input text
358 * @param[in] language The language selected from the foreach function
359 * @param[in] voice_type The voice type selected from the foreach function
360 * @param[in] speed A speaking speed
361 * @param[out] utt_id The utterance ID passed to the callback function
363 * @return 0 on success, otherwise a negative error value
364 * @retval #TTS_ERROR_NONE Successful
365 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
366 * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type
367 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
368 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
370 * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
371 * @see tts_get_max_text_count()
373 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);
376 * @brief Starts synthesizing voice from text and plays synthesized audio data.
378 * @param[in] tts The handle for TTS
380 * @return 0 on success, otherwise a negative error value
381 * @retval #TTS_ERROR_NONE Successful
382 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
383 * @retval #TTS_ERROR_INVALID_STATE Invalid state
384 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
386 * @pre The current state should be #TTS_STATE_READY or #TTS_STATE_PAUSED.
387 * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
389 * @see tts_add_text()
392 * @see tts_utterance_started_cb()
393 * @see tts_utterance_completed_cb()
394 * @see tts_error_cb()
395 * @see tts_interrupted_cb()
397 int tts_play(tts_h tts);
400 * @brief Stops playing utterance and clears queue.
402 * @param[in] tts The handle for TTS
404 * @return 0 on success, otherwise a negative error value
405 * @retval #TTS_ERROR_NONE Successful
406 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
407 * @retval #TTS_ERROR_INVALID_STATE Invalid state
408 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
410 * @pre The TTS state should be #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
411 * @post If this function succeeds, the TTS state will be #TTS_STATE_READY.
412 * This function will remove all text via tts_add_text() and synthesized sound data.
417 int tts_stop(tts_h tts);
420 * @brief Pauses currently playing utterance.
422 * @param[in] tts The handle for TTS
424 * @return 0 on success, otherwise a negative error value
425 * @retval #TTS_ERROR_NONE Successful
426 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
427 * @retval #TTS_ERROR_INVALID_STATE Invalid state
428 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
430 * @pre The TTS state should be #TTS_STATE_PLAYING.
431 * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED.
435 * @see tts_error_cb()
436 * @see tts_interrupted_cb()
438 int tts_pause(tts_h tts);
441 * @brief Registers a callback function to be called when TTS state changes.
443 * @param[in] tts The handle for TTS
444 * @param[in] callback The callback function to register
445 * @param[in] user_data The user data to be passed to the callback function
447 * @return 0 on success, otherwise a negative error value
448 * @retval #TTS_ERROR_NONE Successful
449 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
451 * @pre The state should be #TTS_STATE_CREATED.
453 * @see tts_state_changed_cb()
454 * @see tts_unset_state_changed_cb()
456 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
459 * @brief Unregisters the callback function.
461 * @param[in] tts The handle for TTS
463 * @return 0 on success, otherwise a negative error value
464 * @retval #TTS_ERROR_NONE Successful
465 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
467 * @pre The state should be #TTS_STATE_CREATED.
469 * @see tts_set_state_changed_cb()
471 int tts_unset_state_changed_cb(tts_h tts);
474 * @brief Registers a callback function for detecting utterance started.
476 * @param[in] tts The handle for TTS
477 * @param[in] callback The callback function to register
478 * @param[in] user_data The user data to be passed to the callback function
480 * @return 0 on success, otherwise a negative error value
481 * @retval #TTS_ERROR_NONE Successful
482 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
484 * @pre The state should be #TTS_STATE_CREATED.
486 * @see tts_utterance_started_cb()
487 * @see tts_unset_utterance_started_cb()
489 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
492 * @brief Unregisters the callback function.
494 * @param[in] tts The handle for TTS
496 * @return 0 on success, otherwise a negative error value
497 * @retval #TTS_ERROR_NONE Successful
498 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
500 * @pre The state should be #TTS_STATE_CREATED.
502 * @see tts_set_utterance_started_cb()
504 int tts_unset_utterance_started_cb(tts_h tts);
507 * @brief Registers a callback function for detecting utterance completed.
509 * @param[in] tts The handle for TTS
510 * @param[in] callback The callback function to register
511 * @param[in] user_data The user data to be passed to the callback function
513 * @return 0 on success, otherwise a negative error value
514 * @retval #TTS_ERROR_NONE Successful
515 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
517 * @pre The state should be #TTS_STATE_CREATED.
519 * @see tts_utterance_completed_cb()
520 * @see tts_unset_utterance_completed_cb()
522 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
525 * @brief Unregisters the callback function.
527 * @param[in] tts The handle for TTS
529 * @return 0 on success, otherwise a negative error value
530 * @retval #TTS_ERROR_NONE Successful
531 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
533 * @pre The state should be #TTS_STATE_CREATED.
535 * @see tts_set_utterance_completed_cb()
537 int tts_unset_utterance_completed_cb(tts_h tts);
540 * @brief Registers a callback function for detecting error.
542 * @param[in] tts The handle for TTS
543 * @param[in] callback The callback function to register
544 * @param[in] user_data The user data to be passed to the callback function
546 * @return 0 on success, otherwise a negative error value
547 * @retval #TTS_ERROR_NONE Successful
548 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
550 * @pre The state should be #TTS_STATE_CREATED.
552 * @see tts_error_cb()
553 * @see tts_unset_error_cb()
555 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
558 * @brief Unregisters the callback function.
560 * @param[in] tts The handle for TTS
562 * @return 0 on success, otherwise a negative error value
563 * @retval #TTS_ERROR_NONE Successful
564 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
566 * @pre The state should be #TTS_STATE_CREATED.
568 * @see tts_set_error_cb()
570 int tts_unset_error_cb(tts_h tts);
581 #endif /* __TTS_H__ */