Fix prevent issue and change license file
[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 speaking speed.
51 */
52 typedef enum {
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 */
59 } tts_speed_e;
60
61 /** 
62 * @brief Enumerations of voice type.
63 */
64 typedef enum {
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 */
72 } tts_voice_type_e;
73
74 /** 
75 * @brief Enumerations of state.
76 */
77 typedef enum {
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*/
82 }tts_state_e;
83
84 /** 
85 * @brief A structure of handle for identification
86 */
87 typedef struct tts_s *tts_h;
88
89
90 /**
91 * @brief Called when the state of TTS is changed. 
92 *
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.
95 *
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.
100 *
101 * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
102 *
103 * @see tts_set_state_changed_cb()
104 * @see tts_unset_state_changed_cb()
105 */
106 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
107
108 /**
109 * @brief Called when utterance has started.
110 *
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
114 *
115 * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
116 *
117 * @see tts_add_text()
118 * @see tts_set_utterance_started_cb()
119 * @see tts_unset_utterance_started_cb()
120 */
121 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
122
123 /**
124 * @brief Called when utterance is finished.
125 *
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
129 *
130 * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
131 *
132 * @see tts_add_text()
133 * @see tts_set_utterance_completed_cb()
134 * @see tts_unset_utterance_completed_cb()
135 */
136 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
137
138 /**
139 * @brief Called when error occurred. 
140 *
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
145 *
146 * @pre An application registers this callback using tts_set_error_cb() to detect error.
147 *
148 * @see tts_play()
149 * @see tts_pause()
150 * @see tts_stop()
151 * @see tts_set_error_cb()
152 * @see tts_unset_error_cb()
153 */
154 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
155
156 /**
157 * @brief Called to retrieve the supported voice.
158 *
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
165 *
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. 
168 *
169 * @see tts_foreach_supported_voices()
170 */
171 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, tts_voice_type_e voice_type, void* user_data);
172
173
174 /**
175 * @brief Creates a handle for TTS. 
176 *
177 * @param[out] tts The handle for TTS
178 *
179 * @return 0 on success, otherwise a negative error value
180 * @retval #TTS_ERROR_NONE Successful
181 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
182 *
183 * @see tts_destroy()
184 */
185 int tts_create(tts_h* tts);
186
187 /**
188 * @brief Destroys the handle and disconnects the daemon. 
189 *
190 * @param[in] tts The handle for TTS
191 *
192 * @return 0 on success, otherwise a negative error value
193 * @retval #TTS_ERROR_NONE Successful
194 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
195 *
196 * @see tts_create()
197 */
198 int tts_destroy(tts_h tts);
199
200 /**
201 * @brief Connects the daemon asynchronously. 
202 *
203 * @param[in] tts The handle for TTS
204 *
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
209 *
210 * @pre The state should be #TTS_STATE_CREATED.
211 * @post If this function is called, the TTS state will be #TTS_STATE_READY.
212 *
213 * @see tts_unprepare()
214 */
215 int tts_prepare(tts_h tts);
216
217 /**
218 * @brief Disconnects the daemon.
219 *
220 * @param[in] tts The handle for TTS
221 *
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
226 *
227 * @pre The state should be #TTS_STATE_READY.
228 * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
229 *
230 * @see tts_prepare()
231 */
232 int tts_unprepare(tts_h tts);
233
234 /**
235 * @brief Retrieves all supported voices of the current engine using callback function.
236 *
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
240 *
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
245 *
246 * @pre The state should be #TTS_STATE_READY.
247 * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices. 
248 *
249 * @see tts_get_default_voice()
250 */
251 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
252
253 /**
254 * @brief Gets the default voice set by user.
255 *
256 * @remark If the function succeeds, @a language must be released with free() by you.
257 *
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
263 *
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
269 *
270 * @pre The state should be #TTS_STATE_READY.
271 *
272 * @see tts_foreach_supported_voices()
273 */
274 int tts_get_default_voice(tts_h tts, char** language, tts_voice_type_e* voice_type);
275
276 /**
277 * @brief Gets the maximum text count of a current engine.
278 *
279 * @param[in] tts The handle for TTS
280 * @param[out] count The maximum text count of the current engine
281 *
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
286 *
287 * @pre The state should be #TTS_STATE_READY.
288 *
289 * @see tts_add_text()
290 */
291 int tts_get_max_text_count(tts_h tts, int* count);
292
293 /**
294 * @brief Gets the current state of tts.
295 *
296 * @param[in] tts The handle for TTS
297 * @param[out] state The current state of TTS
298 *
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
303 *
304 * @see tts_play()
305 * @see tts_stop()
306 * @see tts_pause()
307 */
308 int tts_get_state(tts_h tts, tts_state_e* state);
309
310 /**
311 * @brief Adds a text to the queue.
312 *
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
319 *
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
326 *
327 * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
328 * @see tts_get_max_text_count()
329 */
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);
331
332 /**
333 * @brief Starts synthesizing voice from text and plays synthesized audio data.
334 *
335 * @param[in] tts The handle for TTS
336 *
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
342 *
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.
345 *
346 * @see tts_add_text()
347 * @see tts_pause()
348 * @see tts_stop()
349 * @see tts_utterance_started_cb()
350 * @see tts_utterance_completed_cb()
351 * @see tts_error_cb()
352 * @see tts_interrupted_cb()
353 */
354 int tts_play(tts_h tts);
355
356 /**
357 * @brief Stops playing utterance and clears queue.
358 *
359 * @param[in] tts The handle for TTS
360 *
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
366 *
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.
370 *
371 * @see tts_play()
372 * @see tts_pause()
373 */
374 int tts_stop(tts_h tts);
375
376 /**
377 * @brief Pauses currently playing utterance.
378 *
379 * @param[in] tts The handle for TTS
380 *
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
386 *
387 * @pre The TTS state should be #TTS_STATE_PLAYING.
388 * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED. 
389 *
390 * @see tts_play()
391 * @see tts_stop()
392 * @see tts_error_cb()
393 * @see tts_interrupted_cb()
394 */
395 int tts_pause(tts_h tts);
396
397 /**
398 * @brief Registers a callback function to be called when TTS state changes.
399 *
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
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 *
408 * @pre The state should be #TTS_STATE_CREATED.
409 *
410 * @see tts_state_changed_cb()
411 * @see tts_unset_state_changed_cb()
412 */
413 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
414
415 /**
416 * @brief Unregisters the callback function.
417 *
418 * @param[in] tts The handle for TTS
419 *
420 * @return 0 on success, otherwise a negative error value
421 * @retval #TTS_ERROR_NONE Successful
422 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
423 *
424 * @pre The state should be #TTS_STATE_CREATED.
425 *
426 * @see tts_set_state_changed_cb()
427 */
428 int tts_unset_state_changed_cb(tts_h tts);
429
430 /**
431 * @brief Registers a callback function for detecting utterance started.
432 *
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
436 *
437 * @return 0 on success, otherwise a negative error value
438 * @retval #TTS_ERROR_NONE Successful
439 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
440 *
441 * @pre The state should be #TTS_STATE_CREATED.
442 *
443 * @see tts_utterance_started_cb()
444 * @see tts_unset_utterance_started_cb()
445 */
446 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
447
448 /**
449 * @brief Unregisters the callback function.
450 *
451 * @param[in] tts The handle for TTS
452 *
453 * @return 0 on success, otherwise a negative error value
454 * @retval #TTS_ERROR_NONE Successful
455 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
456 *
457 * @pre The state should be #TTS_STATE_CREATED.
458 *
459 * @see tts_set_utterance_started_cb()
460 */
461 int tts_unset_utterance_started_cb(tts_h tts);
462
463 /**
464 * @brief Registers a callback function for detecting utterance completed.
465 *
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
469 *
470 * @return 0 on success, otherwise a negative error value
471 * @retval #TTS_ERROR_NONE Successful
472 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
473 *
474 * @pre The state should be #TTS_STATE_CREATED.
475 *
476 * @see tts_utterance_completed_cb()
477 * @see tts_unset_utterance_completed_cb()
478 */
479 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
480
481 /**
482 * @brief Unregisters the callback function.
483 *
484 * @param[in] tts The handle for TTS
485 *
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
489 *
490 * @pre The state should be #TTS_STATE_CREATED.
491 *
492 * @see tts_set_utterance_completed_cb()
493 */
494 int tts_unset_utterance_completed_cb(tts_h tts);
495
496 /**
497 * @brief Registers a callback function for detecting error.
498 *
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
502 *
503 * @return 0 on success, otherwise a negative error value
504 * @retval #TTS_ERROR_NONE Successful
505 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
506 *
507 * @pre The state should be #TTS_STATE_CREATED.
508 *
509 * @see tts_error_cb()
510 * @see tts_unset_error_cb()
511 */
512 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
513
514 /**
515 * @brief Unregisters the callback function.
516 *
517 * @param[in] tts The handle for TTS
518 *
519 * @return 0 on success, otherwise a negative error value
520 * @retval #TTS_ERROR_NONE Successful
521 * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
522 *
523 * @pre The state should be #TTS_STATE_CREATED.
524 *
525 * @see tts_set_error_cb()
526 */
527 int tts_unset_error_cb(tts_h tts);
528
529
530 #ifdef __cplusplus
531 }
532 #endif
533
534 /**
535 * @}
536 */
537
538 #endif  /* __TTS_H__ */