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 speaking speed.
53 TTS_SPEED_AUTO, /**< Speed from settings */
54 TTS_SPEED_VERY_SLOW, /**< Very slow */
55 TTS_SPEED_SLOW, /**< Slow */
56 TTS_SPEED_NORMAL, /**< Normal */
57 TTS_SPEED_FAST, /**< Fast */
58 TTS_SPEED_VERY_FAST /**< Very fast */
62 * @brief Enumerations of voice type.
65 TTS_VOICE_TYPE_AUTO, /**< Voice type from settings or auto selection based language */
66 TTS_VOICE_TYPE_MALE, /**< Male */
67 TTS_VOICE_TYPE_FEMALE, /**< Female */
68 TTS_VOICE_TYPE_CHILD, /**< Child */
69 TTS_VOICE_TYPE_USER1, /**< Engine defined */
70 TTS_VOICE_TYPE_USER2, /**< Engine defined */
71 TTS_VOICE_TYPE_USER3 /**< Engine defined */
75 * @brief Enumerations of state.
78 TTS_STATE_CREATED = 0, /**< 'CREATED' state */
79 TTS_STATE_READY, /**< 'READY' state */
80 TTS_STATE_PLAYING, /**< 'PLAYING' state */
81 TTS_STATE_PAUSED /**< 'PAUSED' state*/
85 * @brief A structure of handle for identification
87 typedef struct tts_s *tts_h;
91 * @brief Called when the state of TTS is changed.
93 * @details If the daemon must stop player because of changing engine and
94 * the daemon must pause player because of other requests, this callback function is called.
96 * @param[in] tts The handle for TTS
97 * @param[in] previous A previous state
98 * @param[in] current A current state
99 * @param[in] user_data The user data passed from the callback registration function.
101 * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
103 * @see tts_set_state_changed_cb()
104 * @see tts_unset_state_changed_cb()
106 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
109 * @brief Called when utterance has started.
111 * @param[in] tts The handle for TTS
112 * @param[in] utt_id The utterance ID passed from the add text function
113 * @param[in] user_data The user data passed from the callback registration function
115 * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
117 * @see tts_add_text()
118 * @see tts_set_utterance_started_cb()
119 * @see tts_unset_utterance_started_cb()
121 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
124 * @brief Called when utterance is finished.
126 * @param[in] tts The handle for TTS
127 * @param[in] utt_id The utterance ID passed from the add text function
128 * @param[in] user_data The user data passed from from the callback registration function
130 * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
132 * @see tts_add_text()
133 * @see tts_set_utterance_completed_cb()
134 * @see tts_unset_utterance_completed_cb()
136 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
139 * @brief Called when error occurred.
141 * @param[in] tts The handle for TTS
142 * @param[in] utt_id The utterance ID passed from the add text function
143 * @param[in] reason The error code
144 * @param[in] user_data The user data passed from the callback registration function
146 * @pre An application registers this callback using tts_set_error_cb() to detect error.
151 * @see tts_set_error_cb()
152 * @see tts_unset_error_cb()
154 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
157 * @brief Called to retrieve the supported voice.
159 * @param[in] tts The handle for TTS
160 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
161 * followed by ISO 639-1 for the two-letter language code. \n
162 * For example, "ko_KR" for Korean, "en_US" for American English
163 * @param[in] voice_type A voice type
164 * @param[in] user_data The user data passed from the foreach function
166 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
167 * @pre tts_foreach_supported_voices() will invoke this callback.
169 * @see tts_foreach_supported_voices()
171 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, tts_voice_type_e voice_type, void* user_data);
175 * @brief Creates a handle for TTS.
177 * @param[out] tts The handle for TTS
179 * @return 0 on success, otherwise a negative error value
180 * @retval #TTS_ERROR_NONE Successful
181 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
185 int tts_create(tts_h* tts);
188 * @brief Destroys the handle and disconnects the daemon.
190 * @param[in] tts The handle for TTS
192 * @return 0 on success, otherwise a negative error value
193 * @retval #TTS_ERROR_NONE Successful
194 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
198 int tts_destroy(tts_h tts);
201 * @brief Connects the daemon asynchronously.
203 * @param[in] tts The handle for TTS
205 * @return 0 on success, otherwise a negative error value
206 * @retval #TTS_ERROR_NONE Successful
207 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
208 * @retval #TTS_ERROR_INVALID_STATE Invalid state
210 * @pre The state should be #TTS_STATE_CREATED.
211 * @post If this function is called, the TTS state will be #TTS_STATE_READY.
213 * @see tts_unprepare()
215 int tts_prepare(tts_h tts);
218 * @brief Disconnects the daemon.
220 * @param[in] tts The handle for TTS
222 * @return 0 on success, otherwise a negative error value
223 * @retval #TTS_ERROR_NONE Successful
224 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
225 * @retval #STT_ERROR_INVALID_STATE Invalid state
227 * @pre The state should be #TTS_STATE_READY.
228 * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
232 int tts_unprepare(tts_h tts);
235 * @brief Retrieves all supported voices of the current engine using callback function.
237 * @param[in] tts The handle for TTS
238 * @param[in] callback The callback function to invoke
239 * @param[in] user_data The user data to be passed to the callback function
241 * @return 0 on success, otherwise a negative error value
242 * @retval #TTS_ERROR_NONE Successful
243 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
244 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
246 * @pre The state should be #TTS_STATE_READY.
247 * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices.
249 * @see tts_get_default_voice()
251 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
254 * @brief Gets the default voice set by user.
256 * @remark If the function succeeds, @a language must be released with free() by you.
258 * @param[in] tts The handle for TTS
259 * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
260 * followed by ISO 639-1 for the two-letter language code. \n
261 * For example, "ko_KR" for Korean, "en_US" for American English.
262 * @param[out] voice_type The voice type
264 * @return 0 on success, otherwise a negative error value.
265 * @retval #TTS_ERROR_NONE Successful
266 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
267 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
268 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
270 * @pre The state should be #TTS_STATE_READY.
272 * @see tts_foreach_supported_voices()
274 int tts_get_default_voice(tts_h tts, char** language, tts_voice_type_e* voice_type);
277 * @brief Gets the maximum text count of a current engine.
279 * @param[in] tts The handle for TTS
280 * @param[out] count The maximum text count of the current engine
282 * @return 0 on success, otherwise a negative error value
283 * @retval #TTS_ERROR_NONE Successful
284 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
285 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
287 * @pre The state should be #TTS_STATE_READY.
289 * @see tts_add_text()
291 int tts_get_max_text_count(tts_h tts, int* count);
294 * @brief Gets the current state of tts.
296 * @param[in] tts The handle for TTS
297 * @param[out] state The current state of TTS
299 * @return 0 on success, otherwise a negative error value
300 * @retval #TTS_ERROR_NONE Successful
301 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
302 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
308 int tts_get_state(tts_h tts, tts_state_e* state);
311 * @brief Adds a text to the queue.
313 * @param[in] tts The handle for TTS
314 * @param[in] text A input text
315 * @param[in] language The language selected from the foreach function
316 * @param[in] voice_type The voice type selected from the foreach function
317 * @param[in] speed A speaking speed
318 * @param[out] utt_id The utterance ID passed to the callback function
320 * @return 0 on success, otherwise a negative error value
321 * @retval #TTS_ERROR_NONE Successful
322 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
323 * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type
324 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
325 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
327 * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
328 * @see tts_get_max_text_count()
330 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);
333 * @brief Starts synthesizing voice from text and plays synthesized audio data.
335 * @param[in] tts The handle for TTS
337 * @return 0 on success, otherwise a negative error value
338 * @retval #TTS_ERROR_NONE Successful
339 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
340 * @retval #TTS_ERROR_INVALID_STATE Invalid state
341 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
343 * @pre The current state should be #TTS_STATE_READY or #TTS_STATE_PAUSED.
344 * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
346 * @see tts_add_text()
349 * @see tts_utterance_started_cb()
350 * @see tts_utterance_completed_cb()
351 * @see tts_error_cb()
352 * @see tts_interrupted_cb()
354 int tts_play(tts_h tts);
357 * @brief Stops playing utterance and clears queue.
359 * @param[in] tts The handle for TTS
361 * @return 0 on success, otherwise a negative error value
362 * @retval #TTS_ERROR_NONE Successful
363 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
364 * @retval #TTS_ERROR_INVALID_STATE Invalid state
365 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
367 * @pre The TTS state should be #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
368 * @post If this function succeeds, the TTS state will be #TTS_STATE_READY.
369 * This function will remove all text via tts_add_text() and synthesized sound data.
374 int tts_stop(tts_h tts);
377 * @brief Pauses currently playing utterance.
379 * @param[in] tts The handle for TTS
381 * @return 0 on success, otherwise a negative error value
382 * @retval #TTS_ERROR_NONE Successful
383 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
384 * @retval #TTS_ERROR_INVALID_STATE Invalid state
385 * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
387 * @pre The TTS state should be #TTS_STATE_PLAYING.
388 * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED.
392 * @see tts_error_cb()
393 * @see tts_interrupted_cb()
395 int tts_pause(tts_h tts);
398 * @brief Registers a callback function to be called when TTS state changes.
400 * @param[in] tts The handle for TTS
401 * @param[in] callback The callback function to register
402 * @param[in] user_data The user data to be passed to the callback function
404 * @return 0 on success, otherwise a negative error value
405 * @retval #TTS_ERROR_NONE Successful
406 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
408 * @pre The state should be #TTS_STATE_CREATED.
410 * @see tts_state_changed_cb()
411 * @see tts_unset_state_changed_cb()
413 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
416 * @brief Unregisters the callback function.
418 * @param[in] tts The handle for TTS
420 * @return 0 on success, otherwise a negative error value
421 * @retval #TTS_ERROR_NONE Successful
422 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
424 * @pre The state should be #TTS_STATE_CREATED.
426 * @see tts_set_state_changed_cb()
428 int tts_unset_state_changed_cb(tts_h tts);
431 * @brief Registers a callback function for detecting utterance started.
433 * @param[in] tts The handle for TTS
434 * @param[in] callback The callback function to register
435 * @param[in] user_data The user data to be passed to the callback function
437 * @return 0 on success, otherwise a negative error value
438 * @retval #TTS_ERROR_NONE Successful
439 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
441 * @pre The state should be #TTS_STATE_CREATED.
443 * @see tts_utterance_started_cb()
444 * @see tts_unset_utterance_started_cb()
446 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
449 * @brief Unregisters the callback function.
451 * @param[in] tts The handle for TTS
453 * @return 0 on success, otherwise a negative error value
454 * @retval #TTS_ERROR_NONE Successful
455 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
457 * @pre The state should be #TTS_STATE_CREATED.
459 * @see tts_set_utterance_started_cb()
461 int tts_unset_utterance_started_cb(tts_h tts);
464 * @brief Registers a callback function for detecting utterance completed.
466 * @param[in] tts The handle for TTS
467 * @param[in] callback The callback function to register
468 * @param[in] user_data The user data to be passed to the callback function
470 * @return 0 on success, otherwise a negative error value
471 * @retval #TTS_ERROR_NONE Successful
472 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
474 * @pre The state should be #TTS_STATE_CREATED.
476 * @see tts_utterance_completed_cb()
477 * @see tts_unset_utterance_completed_cb()
479 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
482 * @brief Unregisters the callback function.
484 * @param[in] tts The handle for TTS
486 * @return 0 on success, otherwise a negative error value
487 * @retval #TTS_ERROR_NONE Successful
488 * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
490 * @pre The state should be #TTS_STATE_CREATED.
492 * @see tts_set_utterance_completed_cb()
494 int tts_unset_utterance_completed_cb(tts_h tts);
497 * @brief Registers a callback function for detecting error.
499 * @param[in] tts The handle for TTS
500 * @param[in] callback The callback function to register
501 * @param[in] user_data The user data to be passed to the callback function
503 * @return 0 on success, otherwise a negative error value
504 * @retval #TTS_ERROR_NONE Successful
505 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
507 * @pre The state should be #TTS_STATE_CREATED.
509 * @see tts_error_cb()
510 * @see tts_unset_error_cb()
512 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
515 * @brief Unregisters the callback function.
517 * @param[in] tts The handle for TTS
519 * @return 0 on success, otherwise a negative error value
520 * @retval #TTS_ERROR_NONE Successful
521 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
523 * @pre The state should be #TTS_STATE_CREATED.
525 * @see tts_set_error_cb()
527 int tts_unset_error_cb(tts_h tts);
538 #endif /* __TTS_H__ */