Merge with smack branch
[platform/core/uifw/tts.git] / client / tts.h
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
17
18 #ifndef __TTS_H__
19 #define __TTS_H__
20
21 #include <errno.h>
22 #include <stdbool.h>
23
24 /**
25 * @addtogroup CAPI_UIX_TTS_MODULE
26 * @{
27 */
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /** 
34 * @brief Enumerations of error codes.
35 */
36 typedef enum {
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  */
47 } tts_error_e;
48
49 /** 
50 * @brief Enumerations of tts mode.
51 */
52 typedef enum {
53         TTS_MODE_DEFAULT = 0,           /**< Default mode for normal application */
54         TTS_MODE_NOTIFICATION,          /**< Notification mode */
55         TTS_MODE_SCREEN_READER          /**< Screen reader mode */
56 }tts_mode_e;
57
58 /** 
59 * @brief Enumerations of speaking speed.
60 */
61 typedef enum {
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 */
68 }tts_speed_e;
69
70 /** 
71 * @brief Enumerations of voice type.
72 */
73 typedef enum {
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 */
81 }tts_voice_type_e;
82
83 /** 
84 * @brief Enumerations of state.
85 */
86 typedef enum {
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*/
91 }tts_state_e;
92
93 /** 
94 * @brief A structure of handle for identification
95 */
96 typedef struct tts_s *tts_h;
97
98
99 /**
100 * @brief Called when the state of TTS is changed. 
101 *
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.
104 *
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.
109 *
110 * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
111 *
112 * @see tts_set_state_changed_cb()
113 * @see tts_unset_state_changed_cb()
114 */
115 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
116
117 /**
118 * @brief Called when utterance has started.
119 *
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
123 *
124 * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
125 *
126 * @see tts_add_text()
127 * @see tts_set_utterance_started_cb()
128 * @see tts_unset_utterance_started_cb()
129 */
130 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
131
132 /**
133 * @brief Called when utterance is finished.
134 *
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
138 *
139 * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
140 *
141 * @see tts_add_text()
142 * @see tts_set_utterance_completed_cb()
143 * @see tts_unset_utterance_completed_cb()
144 */
145 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
146
147 /**
148 * @brief Called when error occurred. 
149 *
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
154 *
155 * @pre An application registers this callback using tts_set_error_cb() to detect error.
156 *
157 * @see tts_play()
158 * @see tts_pause()
159 * @see tts_stop()
160 * @see tts_set_error_cb()
161 * @see tts_unset_error_cb()
162 */
163 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
164
165 /**
166 * @brief Called to retrieve the supported voice.
167 *
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
174 *
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. 
177 *
178 * @see tts_foreach_supported_voices()
179 */
180 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, tts_voice_type_e voice_type, void* user_data);
181
182
183 /**
184 * @brief Creates a handle for TTS. 
185 *
186 * @param[out] tts The handle for TTS
187 *
188 * @return 0 on success, otherwise a negative error value
189 * @retval #TTS_ERROR_NONE Successful
190 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
191 *
192 * @see tts_destroy()
193 */
194 int tts_create(tts_h* tts);
195
196 /**
197 * @brief Destroys the handle and disconnects the daemon. 
198 *
199 * @param[in] tts The handle for TTS
200 *
201 * @return 0 on success, otherwise a negative error value
202 * @retval #TTS_ERROR_NONE Successful
203 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
204 *
205 * @see tts_create()
206 */
207 int tts_destroy(tts_h tts);
208
209 /**
210 * @brief Set tts mode. 
211 *
212 * @param[in] tts The handle for TTS
213 * @param[in] mode The mode
214 *
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
219 *
220 * @pre The state should be #TTS_STATE_CREATED.
221 *
222 * @see tts_get_mode()
223 */
224 int tts_set_mode(tts_h tts, tts_mode_e mode);
225
226 /**
227 * @brief Get tts mode. 
228 *
229 * @param[in] tts The handle for TTS
230 * @param[out] mode The mode
231 *
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
236 *
237 * @pre The state should be #TTS_STATE_CREATED.
238 *
239 * @see tts_set_mode()
240 */
241 int tts_get_mode(tts_h tts, tts_mode_e* mode);
242
243 /**
244 * @brief Connects the daemon asynchronously. 
245 *
246 * @param[in] tts The handle for TTS
247 *
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
252 *
253 * @pre The state should be #TTS_STATE_CREATED.
254 * @post If this function is called, the TTS state will be #TTS_STATE_READY.
255 *
256 * @see tts_unprepare()
257 */
258 int tts_prepare(tts_h tts);
259
260 /**
261 * @brief Disconnects the daemon.
262 *
263 * @param[in] tts The handle for TTS
264 *
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
269 *
270 * @pre The state should be #TTS_STATE_READY.
271 * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
272 *
273 * @see tts_prepare()
274 */
275 int tts_unprepare(tts_h tts);
276
277 /**
278 * @brief Retrieves all supported voices of the current engine using callback function.
279 *
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
283 *
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
288 *
289 * @pre The state should be #TTS_STATE_READY.
290 * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices. 
291 *
292 * @see tts_get_default_voice()
293 */
294 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
295
296 /**
297 * @brief Gets the default voice set by user.
298 *
299 * @remark If the function succeeds, @a language must be released with free() by you.
300 *
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
306 *
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
312 *
313 * @pre The state should be #TTS_STATE_READY.
314 *
315 * @see tts_foreach_supported_voices()
316 */
317 int tts_get_default_voice(tts_h tts, char** language, tts_voice_type_e* voice_type);
318
319 /**
320 * @brief Gets the maximum text count of a current engine.
321 *
322 * @param[in] tts The handle for TTS
323 * @param[out] count The maximum text count of the current engine
324 *
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
329 *
330 * @pre The state should be #TTS_STATE_READY.
331 *
332 * @see tts_add_text()
333 */
334 int tts_get_max_text_count(tts_h tts, int* count);
335
336 /**
337 * @brief Gets the current state of tts.
338 *
339 * @param[in] tts The handle for TTS
340 * @param[out] state The current state of TTS
341 *
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
346 *
347 * @see tts_play()
348 * @see tts_stop()
349 * @see tts_pause()
350 */
351 int tts_get_state(tts_h tts, tts_state_e* state);
352
353 /**
354 * @brief Adds a text to the queue.
355 *
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
362 *
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
369 *
370 * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
371 * @see tts_get_max_text_count()
372 */
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);
374
375 /**
376 * @brief Starts synthesizing voice from text and plays synthesized audio data.
377 *
378 * @param[in] tts The handle for TTS
379 *
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
385 *
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.
388 *
389 * @see tts_add_text()
390 * @see tts_pause()
391 * @see tts_stop()
392 * @see tts_utterance_started_cb()
393 * @see tts_utterance_completed_cb()
394 * @see tts_error_cb()
395 * @see tts_interrupted_cb()
396 */
397 int tts_play(tts_h tts);
398
399 /**
400 * @brief Stops playing utterance and clears queue.
401 *
402 * @param[in] tts The handle for TTS
403 *
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
409 *
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.
413 *
414 * @see tts_play()
415 * @see tts_pause()
416 */
417 int tts_stop(tts_h tts);
418
419 /**
420 * @brief Pauses currently playing utterance.
421 *
422 * @param[in] tts The handle for TTS
423 *
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
429 *
430 * @pre The TTS state should be #TTS_STATE_PLAYING.
431 * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED. 
432 *
433 * @see tts_play()
434 * @see tts_stop()
435 * @see tts_error_cb()
436 * @see tts_interrupted_cb()
437 */
438 int tts_pause(tts_h tts);
439
440 /**
441 * @brief Registers a callback function to be called when TTS state changes.
442 *
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
446 *
447 * @return 0 on success, otherwise a negative error value
448 * @retval #TTS_ERROR_NONE Successful
449 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
450 *
451 * @pre The state should be #TTS_STATE_CREATED.
452 *
453 * @see tts_state_changed_cb()
454 * @see tts_unset_state_changed_cb()
455 */
456 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
457
458 /**
459 * @brief Unregisters the callback function.
460 *
461 * @param[in] tts The handle for TTS
462 *
463 * @return 0 on success, otherwise a negative error value
464 * @retval #TTS_ERROR_NONE Successful
465 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
466 *
467 * @pre The state should be #TTS_STATE_CREATED.
468 *
469 * @see tts_set_state_changed_cb()
470 */
471 int tts_unset_state_changed_cb(tts_h tts);
472
473 /**
474 * @brief Registers a callback function for detecting utterance started.
475 *
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
479 *
480 * @return 0 on success, otherwise a negative error value
481 * @retval #TTS_ERROR_NONE Successful
482 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
483 *
484 * @pre The state should be #TTS_STATE_CREATED.
485 *
486 * @see tts_utterance_started_cb()
487 * @see tts_unset_utterance_started_cb()
488 */
489 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
490
491 /**
492 * @brief Unregisters the callback function.
493 *
494 * @param[in] tts The handle for TTS
495 *
496 * @return 0 on success, otherwise a negative error value
497 * @retval #TTS_ERROR_NONE Successful
498 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
499 *
500 * @pre The state should be #TTS_STATE_CREATED.
501 *
502 * @see tts_set_utterance_started_cb()
503 */
504 int tts_unset_utterance_started_cb(tts_h tts);
505
506 /**
507 * @brief Registers a callback function for detecting utterance completed.
508 *
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
512 *
513 * @return 0 on success, otherwise a negative error value
514 * @retval #TTS_ERROR_NONE Successful
515 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
516 *
517 * @pre The state should be #TTS_STATE_CREATED.
518 *
519 * @see tts_utterance_completed_cb()
520 * @see tts_unset_utterance_completed_cb()
521 */
522 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
523
524 /**
525 * @brief Unregisters the callback function.
526 *
527 * @param[in] tts The handle for TTS
528 *
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
532 *
533 * @pre The state should be #TTS_STATE_CREATED.
534 *
535 * @see tts_set_utterance_completed_cb()
536 */
537 int tts_unset_utterance_completed_cb(tts_h tts);
538
539 /**
540 * @brief Registers a callback function for detecting error.
541 *
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
545 *
546 * @return 0 on success, otherwise a negative error value
547 * @retval #TTS_ERROR_NONE Successful
548 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
549 *
550 * @pre The state should be #TTS_STATE_CREATED.
551 *
552 * @see tts_error_cb()
553 * @see tts_unset_error_cb()
554 */
555 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
556
557 /**
558 * @brief Unregisters the callback function.
559 *
560 * @param[in] tts The handle for TTS
561 *
562 * @return 0 on success, otherwise a negative error value
563 * @retval #TTS_ERROR_NONE Successful
564 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
565 *
566 * @pre The state should be #TTS_STATE_CREATED.
567 *
568 * @see tts_set_error_cb()
569 */
570 int tts_unset_error_cb(tts_h tts);
571
572
573 #ifdef __cplusplus
574 }
575 #endif
576
577 /**
578 * @}
579 */
580
581 #endif  /* __TTS_H__ */