Refactor feature check and handle creation code
[platform/core/uifw/tts.git] / include / tts.h
1 /*
2  * Copyright (c) 2011-2016 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
22 #include <tizen.h>
23
24
25 /**
26 * @file tts.h
27 */
28
29
30 /**
31 * @addtogroup CAPI_UIX_TTS_MODULE
32 * @{
33 */
34
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 /**
42  * @brief Enumeration for error code.
43  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
44 */
45 typedef enum {
46         TTS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
47         TTS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
48         TTS_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
49         TTS_ERROR_INVALID_PARAMETER     = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
50         TTS_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */
51         TTS_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
52         TTS_ERROR_PERMISSION_DENIED     = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
53         TTS_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< TTS NOT supported */
54         TTS_ERROR_INVALID_STATE = TIZEN_ERROR_TTS | 0x01, /**< Invalid state */
55         TTS_ERROR_INVALID_VOICE = TIZEN_ERROR_TTS | 0x02, /**< Invalid voice */
56         TTS_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_TTS | 0x03, /**< No available engine */
57         TTS_ERROR_OPERATION_FAILED = TIZEN_ERROR_TTS | 0x04, /**< Operation failed */
58         TTS_ERROR_AUDIO_POLICY_BLOCKED = TIZEN_ERROR_TTS | 0x05, /**< Audio policy blocked */
59         TTS_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06, /**< Not supported feature of current engine @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */
60         TTS_ERROR_SERVICE_RESET = TIZEN_ERROR_TTS | 0x07, /**< Service reset @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */
61         TTS_ERROR_SCREEN_READER_OFF = TIZEN_ERROR_TTS | 0x08 /**< Screen reader is off (Since 6.5) */
62 } tts_error_e;
63
64
65 /**
66  * @brief Enumeration for TTS mode.
67  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
68 */
69 typedef enum {
70         TTS_MODE_DEFAULT = 0, /**< Default mode for normal application */
71         TTS_MODE_NOTIFICATION = 1, /**< Notification mode */
72         TTS_MODE_SCREEN_READER = 2 /**< Accessibility mode */
73 } tts_mode_e;
74
75
76 /**
77  * @brief Enumeration for state.
78  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
79 */
80 typedef enum {
81         TTS_STATE_CREATED = 0, /**< 'CREATED' state */
82         TTS_STATE_READY = 1, /**< 'READY' state */
83         TTS_STATE_PLAYING = 2, /**< 'PLAYING' state */
84         TTS_STATE_PAUSED = 3 /**< 'PAUSED' state*/
85 } tts_state_e;
86
87
88 /**
89  * @brief Definition for automatic speaking speed.
90  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
91 */
92 #define TTS_SPEED_AUTO          0
93
94
95 /**
96  * @brief Definition for automatic voice type.
97  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
98 */
99 #define TTS_VOICE_TYPE_AUTO     0
100
101
102 /**
103  * @brief Definition for male voice type.
104  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
105 */
106 #define TTS_VOICE_TYPE_MALE     1
107
108
109 /**
110  * @brief Definition for female voice type.
111  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
112 */
113 #define TTS_VOICE_TYPE_FEMALE   2
114
115
116 /**
117  * @brief Definition for child voice type.
118  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
119 */
120 #define TTS_VOICE_TYPE_CHILD    3
121
122
123 /**
124  * @brief The TTS handle.
125  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
126 */
127 typedef struct tts_s *tts_h;
128
129
130 /**
131  * @brief Called when the state of TTS is changed.
132  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
133  * @details If the daemon must stop player because of changing engine and
134  *          the daemon must pause player because of other requests, this callback function is called.
135  * @param[in] tts The TTS handle
136  * @param[in] previous The previous state
137  * @param[in] current The current state
138  * @param[in] user_data The user data passed from the callback registration function
139  * @pre An application registers this callback using tts_set_state_changed_cb() to detect changing state.
140  * @see tts_set_state_changed_cb()
141  * @see tts_unset_state_changed_cb()
142 */
143 typedef void (*tts_state_changed_cb)(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data);
144
145
146 /**
147  * @brief Called when utterance has started.
148  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
149  * @param[in] tts The TTS handle
150  * @param[in] utt_id The utterance ID passed from the add text function
151  * @param[in] user_data The user data passed from the callback registration function
152  * @pre An application registers this callback using tts_set_utterance_started_cb() to detect utterance started.
153  * @see tts_add_text()
154  * @see tts_set_utterance_started_cb()
155  * @see tts_unset_utterance_started_cb()
156 */
157 typedef void (*tts_utterance_started_cb)(tts_h tts, int utt_id, void* user_data);
158
159
160 /**
161  * @brief Called when utterance is finished.
162  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
163  * @param[in] tts The TTS handle
164  * @param[in] utt_id The utterance ID passed from the add text function
165  * @param[in] user_data The user data passed from the callback registration function
166  * @pre An application registers this callback using tts_set_utterance_completed_cb() to detect utterance completed.
167  * @see tts_add_text()
168  * @see tts_set_utterance_completed_cb()
169  * @see tts_unset_utterance_completed_cb()
170 */
171 typedef void (*tts_utterance_completed_cb)(tts_h tts, int utt_id, void *user_data);
172
173
174 /**
175  * @brief Called when an error occurs.
176  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
177  * @param[in] tts The TTS handle
178  * @param[in] utt_id The utterance ID passed from the add text function
179  * @param[in] reason The error code
180  * @param[in] user_data The user data passed from the callback registration function
181  * @pre An application registers this callback using tts_set_error_cb() to detect error.
182  * @see tts_play()
183  * @see tts_pause()
184  * @see tts_stop()
185  * @see tts_set_error_cb()
186  * @see tts_unset_error_cb()
187 */
188 typedef void (*tts_error_cb)(tts_h tts, int utt_id, tts_error_e reason, void* user_data);
189
190
191 /**
192  * @brief Called to retrieve the supported voice.
193  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
194  * @param[in] tts The TTS handle
195  * @param[in] language Language specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code (for example, "ko_KR" for Korean, "en_US" for American English)
196  * @param[in] voice_type A voice type (e.g. #TTS_VOICE_TYPE_MALE, #TTS_VOICE_TYPE_FEMALE)
197  * @param[in] user_data The user data passed from the foreach function
198  * @return @c true to continue with the next iteration of the loop,
199  *         @c false to break out of the loop
200  * @pre tts_foreach_supported_voices() will invoke this callback function.
201  * @see tts_foreach_supported_voices()
202 */
203 typedef bool(*tts_supported_voice_cb)(tts_h tts, const char* language, int voice_type, void* user_data);
204
205
206 /**
207  * @brief Called when the default voice is changed.
208  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
209  * @param[in] tts The TTS handle
210  * @param[in] previous_language The previous language
211  * @param[in] previous_voice_type The previous voice type
212  * @param[in] current_language The current language
213  * @param[in] current_voice_type The current voice type
214  * @param[in] user_data The user data passed from the callback registration function
215  * @see tts_set_default_voice_changed_cb()
216 */
217 typedef void (*tts_default_voice_changed_cb)(tts_h tts, const char* previous_language, int previous_voice_type,
218                                 const char* current_language, int current_voice_type, void* user_data);
219
220
221 /**
222  * @brief Called when the engine is changed.
223  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
224  * @param[in] tts The TTS handle
225  * @param[in] engine_id Engine ID
226  * @param[in] language The default language specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code (for example, "ko_KR" for Korean, "en_US" for American English)
227  * @param[in] voice_type The default voice type
228  * @param[in] need_credential The necessity of credential
229  * @param[in] user_data The user data passed from the callback registration function
230  * @see tts_set_engine_changed_cb()
231 */
232 typedef void (*tts_engine_changed_cb)(tts_h tts, const char* engine_id, const char* language, int voice_type, bool need_credential, void* user_data);
233
234
235 /**
236  * @brief Called when the option of screen reader is changed.
237  * @since_tizen 6.5
238  * @param[in] tts The TTS handle
239  * @param[in] is_on The status of screen reader. If @a is_on is @c true, screen reader is turned on. If not, it is turned off.
240  * @param[in] user_data The user data passed from the callback registration function
241  * @see tts_set_screen_reader_changed_cb()
242 */
243 typedef void (*tts_screen_reader_changed_cb)(tts_h tts, bool is_on, void* user_data);
244
245 /**
246  * @brief Creates a handle for TTS.
247  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
248  * @remarks If the function succeeds, @a tts handle must be released with tts_destroy().
249  * @param[out] tts The TTS handle
250  * @return @c 0 on success,
251  *         otherwise a negative error value
252  * @retval #TTS_ERROR_NONE Successful
253  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
254  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
255  * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
256  * @retval #TTS_ERROR_ENGINE_NOT_FOUND Engine not found
257  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
258  * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
259  * @see tts_destroy()
260 */
261 int tts_create(tts_h* tts);
262
263
264 /**
265  * @brief Destroys the handle and disconnects the daemon.
266  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
267  * @param[in] tts The TTS handle
268  * @return @c 0 on success,
269  *         otherwise a negative error value
270  * @retval #TTS_ERROR_NONE Successful
271  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
272  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
273  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
274  * @see tts_create()
275 */
276 int tts_destroy(tts_h tts);
277
278
279 /**
280  * @brief Sets the TTS mode.
281  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
282  * @param[in] tts The TTS handle
283  * @param[in] mode The mode
284  * @return @c 0 on success,
285  *         otherwise a negative error value
286  * @retval #TTS_ERROR_NONE Successful
287  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
288  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
289  * @retval #TTS_ERROR_INVALID_STATE Invalid state
290  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
291  * @pre The state should be #TTS_STATE_CREATED.
292  * @see tts_get_mode()
293 */
294 int tts_set_mode(tts_h tts, tts_mode_e mode);
295
296
297 /**
298  * @brief Gets the TTS mode.
299  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
300  * @param[in] tts The TTS handle
301  * @param[out] mode The mode
302  * @return @c 0 on success,
303  *         otherwise a negative error value
304  * @retval #TTS_ERROR_NONE Successful
305  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
306  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
307  * @retval #TTS_ERROR_INVALID_STATE Invalid state
308  * @pre The state should be #TTS_STATE_CREATED.
309  * @see tts_set_mode()
310 */
311 int tts_get_mode(tts_h tts, tts_mode_e* mode);
312
313
314 /**
315  * @brief Sets the app credential.
316  * @details Using this API, the application can set a credential.
317  *          The credential is a key to verify the authorization about using the engine.
318  *          If the application sets the credential, it will be able to use functions of the engine entirely.
319  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
320  * @remarks The necessity of the credential depends on the engine. In case of the engine which is basically embedded in Tizen, the credential is not necessary so far.
321  *          However, if the user wants to apply the 3rd party's engine, the credential may be necessary. In that case, please follow the policy provided by the corresponding engine.
322  * @param[in] tts The TTS handle
323  * @param[in] credential The app credential
324  * @return @c 0 on success,
325  *         otherwise a negative error value
326  * @retval #TTS_ERROR_NONE Success
327  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
328  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
329  * @retval #TTS_ERROR_INVALID_STATE Invalid state
330  * @pre The state should be #TTS_STATE_CREATED or #TTS_STATE_READY.
331  * @see tts_play()
332 */
333 int tts_set_credential(tts_h tts, const char* credential);
334
335
336 /**
337  * @brief Connects the daemon asynchronously.
338  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
339  * @param[in] tts The TTS handle
340  * @return @c 0 on success,
341  *         otherwise a negative error value
342  * @retval #TTS_ERROR_NONE Successful
343  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
344  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
345  * @retval #TTS_ERROR_INVALID_STATE Invalid state
346  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
347  * @pre The state should be #TTS_STATE_CREATED.
348  * @post If this function is successful, the TTS state will be #TTS_STATE_READY.
349  *       If this function is failed, the error callback is called. (e.g. #TTS_ERROR_ENGINE_NOT_FOUND)
350  * @see tts_unprepare()
351 */
352 int tts_prepare(tts_h tts);
353
354
355 /**
356  * @brief Disconnects the daemon.
357  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
358  * @param[in] tts The TTS handle
359  * @return @c 0 on success,
360  *         otherwise a negative error value
361  * @retval #TTS_ERROR_NONE Successful
362  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
363  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
364  * @retval #TTS_ERROR_INVALID_STATE Invalid state
365  * @pre The state should be #TTS_STATE_READY.
366  * @post If this function is called, the TTS state will be #TTS_STATE_CREATED.
367  * @see tts_prepare()
368 */
369 int tts_unprepare(tts_h tts);
370
371
372 /**
373  * @brief Connects the daemon synchronously.
374  * @since_tizen 7.0
375  * @param[in] tts The TTS handle
376  * @return @c 0 on success,
377  *         otherwise a negative error value
378  * @retval #TTS_ERROR_NONE Successful
379  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
380  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
381  * @retval #TTS_ERROR_INVALID_STATE Invalid state
382  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
383  * @pre The state should be #TTS_STATE_CREATED.
384  * @post If this function is successful, the TTS state will be #TTS_STATE_READY.
385  * @see tts_unprepare()
386 */
387 int tts_prepare_sync(tts_h tts);
388
389
390 /**
391  * @brief Retrieves all supported voices of the current engine using callback function.
392  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
393  * @param[in] tts The TTS handle
394  * @param[in] callback The callback function to invoke
395  * @param[in] user_data The user data to be passed to the callback function
396  * @return @c 0 on success,
397  *         otherwise a negative error value
398  * @retval #TTS_ERROR_NONE Successful
399  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
400  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
401  * @retval #TTS_ERROR_ENGINE_NOT_FOUND Engine not found
402  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
403  * @post This function invokes tts_supported_voice_cb() repeatedly for getting voices.
404  * @see tts_get_default_voice()
405 */
406 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data);
407
408
409 /**
410  * @brief Gets the default voice set by the user.
411  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
412  * @remarks If the function succeeds, @a language must be released with free().
413  * @param[in] tts The TTS handle
414  * @param[out] language Language specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code (for example, "ko_KR" for Korean, "en_US" for American English)
415  * @param[out] voice_type The voice type
416  * @return @c 0 on success,
417  *         otherwise a negative error value
418  * @retval #TTS_ERROR_NONE Successful
419  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
420  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
421  * @retval #TTS_ERROR_ENGINE_NOT_FOUND Engine not found
422  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
423  * @see tts_foreach_supported_voices()
424 */
425 int tts_get_default_voice(tts_h tts, char** language, int* voice_type);
426
427
428 /**
429  * @brief Sets the private data to tts engine.
430  * @details The private data is the setting parameter for applying keys provided by the engine.
431  *          Using this API, the application can set the private data and use the corresponding key of the engine.
432  *          For example, if the engine provides 'girl's voice' as a voice type, the application can set the private data as the following.
433  *          int ret = tts_set_private_data(tts_h, "voice_type", "GIRL");
434  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
435  * @remarks If the engine is replaced with the other engine, the key may be ignored.
436  * @param[in] tts The TTS handle
437  * @param[in] key The field name of private data
438  * @param[in] data The data for set
439  * @return @c 0 on success,
440  *         otherwise a negative error value
441  * @retval #TTS_ERROR_NONE Successful
442  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
443  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
444  * @retval #TTS_ERROR_INVALID_STATE Invalid state
445  * @retval #TTS_ERROR_ENGINE_NOT_FOUND Engine not found
446  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
447  * @pre The state should be #TTS_STATE_READY.
448  * @see tts_get_private_data()
449 */
450 int tts_set_private_data(tts_h tts, const char* key, const char* data);
451
452
453 /**
454  * @brief Gets the private data from tts engine.
455  * @details The private data is the information provided by the engine.
456  *          Using this API, the application can get the private data which corresponds to the key from the engine.
457  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
458  * @remarks The @a data must be released using free() when it is no longer required.
459  *          If the engine is replaced with the other engine, the key may be ignored.
460  * @param[in] tts The TTS handle
461  * @param[in] key The field name of private data
462  * @param[out] data The data field of private data
463  * @return @c 0 on success,
464  *         otherwise a negative error value
465  * @retval #TTS_ERROR_NONE Successful
466  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
467  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
468  * @retval #TTS_ERROR_INVALID_STATE Invalid state
469  * @retval #TTS_ERROR_ENGINE_NOT_FOUND Engine not found
470  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
471  * @pre The state should be #TTS_STATE_READY.
472  * @see tts_set_private_data()
473 */
474 int tts_get_private_data(tts_h tts, const char* key, char** data);
475
476
477 /**
478  * @brief Gets the maximum byte size for text.
479  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
480  * @param[in] tts The TTS handle
481  * @param[out] size The maximum byte size for text
482  * @return @c 0 on success,
483  *         otherwise a negative error value
484  * @retval #TTS_ERROR_NONE Successful
485  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
486  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
487  * @retval #TTS_ERROR_INVALID_STATE Invalid state
488  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
489  * @pre The state should be #TTS_STATE_READY.
490  * @see tts_add_text()
491 */
492 int tts_get_max_text_size(tts_h tts, unsigned int* size);
493
494
495 /**
496  * @brief Gets the current state of TTS.
497  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
498  * @param[in] tts The TTS handle
499  * @param[out] state The current state of TTS
500  * @return @c 0 on success,
501  *         otherwise a negative error value
502  * @retval #TTS_ERROR_NONE Successful
503  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
504  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
505  * @see tts_play()
506  * @see tts_stop()
507  * @see tts_pause()
508 */
509 int tts_get_state(tts_h tts, tts_state_e* state);
510
511
512 /**
513  * @brief Gets the speed range.
514  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
515  * @param[in] tts The TTS handle
516  * @param[out] min The minimum speed value
517  * @param[out] normal The normal speed value
518  * @param[out] max The maximum speed value
519  * @return @c 0 on success,
520  *         otherwise a negative error value
521  * @retval #TTS_ERROR_NONE Successful
522  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
523  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
524  * @retval #TTS_ERROR_INVALID_STATE Invalid state
525  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
526  * @pre The state should be #TTS_STATE_CREATED.
527  * @see tts_add_text()
528 */
529 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max);
530
531
532 /**
533  * @brief Gets the current error message.
534  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
535  * @remarks This function should be called from a tts error callback. Calling in any other context will result in an Operation failed error.
536  *          A successful call will allocate @a err_msg, which must be released by calling free() when it is no longer required.
537  * @param[in] tts The TTS handle
538  * @param[out] err_msg The current error message
539  * @return @c 0 on success,
540  *         otherwise a negative error value
541  * @retval #TTS_ERROR_NONE Successful
542  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
543  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
544  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
545  * @see tts_set_error_cb()
546  * @see tts_unset_error_cb()
547 */
548 int tts_get_error_message(tts_h tts, char** err_msg);
549
550
551 /**
552  * @brief Checks whether screen reader is turned on or not.
553  * @since_tizen 6.5
554  * @remarks If TTS mode is #TTS_MODE_SCREEN_READER, you should call this function to check whether screen reader is turned on or not, before calling 'tts_prepare()'.
555  *          If TTS mode is #TTS_MODE_SCREEN_READER and @a is_on is @c false, all other functions will return #TTS_ERROR_SCREEN_READER_OFF.
556  *          The @a is_on must be released using free() when it is no longer required.
557  * @param[in] tts The TTS handle
558  * @param[out] is_on The current status of screen reader
559  * @return @c 0 on success,
560  *         otherwise a negative error value
561  * @retval #TTS_ERROR_NONE Successful
562  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
563  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
564  * @see tts_set_screen_reader_changed_cb()
565  * @see tts_unset_screen_reader_changed_cb()
566 */
567 int tts_check_screen_reader_on(tts_h tts, bool* is_on);
568
569
570 /**
571  * @brief Adds a text to the queue.
572  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
573  * @remarks Locale(e.g. setlocale()) MUST be set for utf8 text validation check.
574  * @param[in] tts The TTS handle
575  * @param[in] text An input text based utf8
576  * @param[in] language The language selected from the tts_foreach_supported_voices() (e.g. 'NULL'(Automatic), 'en_US')
577  * @param[in] voice_type The voice type selected from the tts_foreach_supported_voices() (e.g. #TTS_VOICE_TYPE_AUTO, #TTS_VOICE_TYPE_FEMALE)
578  * @param[in] speed A speaking speed (e.g. #TTS_SPEED_AUTO or the value from tts_get_speed_range())
579  * @param[out] utt_id The utterance ID passed to the callback function
580  * @return @c 0 on success,
581  *         otherwise a negative error value
582  * @retval #TTS_ERROR_NONE Successful
583  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
584  * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
585  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
586  * @retval #TTS_ERROR_INVALID_STATE Invalid state
587  * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type
588  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
589  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
590  * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
591  * @see tts_get_max_text_size()
592  * @see tts_set_credential()
593 */
594 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id);
595
596
597 /**
598  * @brief Starts synthesizing voice from the text and plays the synthesized audio data.
599  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
600  * @param[in] tts The TTS handle
601  * @return @c 0 on success,
602  *         otherwise a negative error value
603  * @retval #TTS_ERROR_NONE Successful
604  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
605  * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
606  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
607  * @retval #TTS_ERROR_OUT_OF_NETWORK Out of network
608  * @retval #TTS_ERROR_INVALID_STATE Invalid state
609  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
610  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
611  * @pre The current state should be #TTS_STATE_READY or #TTS_STATE_PAUSED.
612  * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
613  * @see tts_add_text()
614  * @see tts_pause()
615  * @see tts_stop()
616  * @see tts_utterance_started_cb()
617  * @see tts_utterance_completed_cb()
618  * @see tts_error_cb()
619  * @see tts_set_credential()
620 */
621 int tts_play(tts_h tts);
622
623
624 /**
625  * @brief Stops playing the utterance and clears the queue.
626  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
627  * @param[in] tts The TTS handle
628  * @return @c 0 on success,
629  *         otherwise a negative error value
630  * @retval #TTS_ERROR_NONE Successful
631  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
632  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
633  * @retval #TTS_ERROR_INVALID_STATE Invalid state
634  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
635  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
636  * @pre The TTS state should be #TTS_STATE_READY or #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
637  * @post If this function succeeds, the TTS state will be #TTS_STATE_READY.
638  *       This function will remove all text via tts_add_text() and synthesized sound data.
639  * @see tts_play()
640  * @see tts_pause()
641 */
642 int tts_stop(tts_h tts);
643
644
645 /**
646  * @brief Pauses the currently playing utterance.
647  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
648  * @param[in] tts The TTS handle
649  * @return @c 0 on success,
650  *         otherwise a negative error value
651  * @retval #TTS_ERROR_NONE Successful
652  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
653  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
654  * @retval #TTS_ERROR_INVALID_STATE Invalid state
655  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
656  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
657  * @pre The TTS state should be #TTS_STATE_PLAYING.
658  * @post If this function succeeds, the TTS state will be #TTS_STATE_PAUSED.
659  * @see tts_play()
660  * @see tts_stop()
661  * @see tts_error_cb()
662 */
663 int tts_pause(tts_h tts);
664
665 /**
666  * @brief Repeats the last added text.
667  * @since_tizen 5.0
668  * @remarks This function repeats the last added text once again.
669  *          If there is no previously added text, this function will not work.
670  *          If the language is changed, the last added text is removed from the service.
671  *          Before calling this function, please call 'tts_stop()' in order to stop playing the previous one.
672  *          If this function succeeds, @a text_repeat must be released with free().
673  * @param[in] tts The TTS handle
674  * @param[out] text_repeat Texts to be played repeatedly
675  * @param[out] utt_id The utterance ID passed to the callback function
676  *
677  * @return @c 0 on success,
678  *         otherwise a negative error value
679  * @retval #TTS_ERROR_NONE Successful
680  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
681  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
682  * @retval #TTS_ERROR_INVALID_STATE Invalid state
683  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
684  * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
685  * @pre The state should be #TTS_STATE_READY.
686  * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING.
687  * @see tts_add_text()
688  * @see tts_stop()
689  */
690 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id);
691
692 /**
693  * @brief Registers a callback function to be called when the TTS state changes.
694  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
695  * @param[in] tts The TTS handle
696  * @param[in] callback The callback function to register
697  * @param[in] user_data The user data to be passed to the callback function
698  * @return @c 0 on success,
699  *         otherwise a negative error value
700  * @retval #TTS_ERROR_NONE Successful
701  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
702  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
703  * @retval #TTS_ERROR_INVALID_STATE Invalid state
704  * @pre The state should be #TTS_STATE_CREATED.
705  * @see tts_state_changed_cb()
706  * @see tts_unset_state_changed_cb()
707 */
708 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data);
709
710
711 /**
712  * @brief Unregisters the callback function.
713  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
714  * @param[in] tts The TTS handle
715  * @return @c 0 on success,
716  *         otherwise a negative error value
717  * @retval #TTS_ERROR_NONE Successful
718  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
719  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
720  * @retval #TTS_ERROR_INVALID_STATE Invalid state
721  * @pre The state should be #TTS_STATE_CREATED.
722  * @see tts_set_state_changed_cb()
723 */
724 int tts_unset_state_changed_cb(tts_h tts);
725
726
727 /**
728  * @brief Registers a callback function to detect utterance start.
729  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
730  * @param[in] tts The TTS handle
731  * @param[in] callback The callback function to register
732  * @param[in] user_data The user data to be passed to the callback function
733  * @return @c 0 on success,
734  *         otherwise a negative error value
735  * @retval #TTS_ERROR_NONE Successful
736  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
737  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
738  * @retval #TTS_ERROR_INVALID_STATE Invalid state
739  * @pre The state should be #TTS_STATE_CREATED.
740  * @see tts_utterance_started_cb()
741  * @see tts_unset_utterance_started_cb()
742 */
743 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data);
744
745
746 /**
747  * @brief Unregisters the callback function.
748  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
749  * @param[in] tts The TTS handle
750  * @return @c 0 on success,
751  *         otherwise a negative error value
752  * @retval #TTS_ERROR_NONE Successful
753  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
754  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
755  * @retval #TTS_ERROR_INVALID_STATE Invalid state
756  * @pre The state should be #TTS_STATE_CREATED.
757  * @see tts_set_utterance_started_cb()
758 */
759 int tts_unset_utterance_started_cb(tts_h tts);
760
761
762 /**
763  * @brief Registers a callback function to detect utterance completion.
764  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
765  * @param[in] tts The TTS handle
766  * @param[in] callback The callback function to register
767  * @param[in] user_data The user data to be passed to the callback function
768  * @return @c 0 on success,
769  *         otherwise a negative error value
770  * @retval #TTS_ERROR_NONE Successful
771  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
772  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
773  * @retval #TTS_ERROR_INVALID_STATE Invalid state
774  * @pre The state should be #TTS_STATE_CREATED.
775  * @see tts_utterance_completed_cb()
776  * @see tts_unset_utterance_completed_cb()
777 */
778 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data);
779
780
781 /**
782  * @brief Unregisters the callback function.
783  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
784  * @param[in] tts The TTS handle
785  * @return @c 0 on success,
786  *         otherwise a negative error value
787  * @retval #TTS_ERROR_NONE Successful
788  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
789  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
790  * @retval #TTS_ERROR_INVALID_STATE Invalid state
791  * @pre The state should be #TTS_STATE_CREATED.
792  * @see tts_set_utterance_completed_cb()
793 */
794 int tts_unset_utterance_completed_cb(tts_h tts);
795
796
797 /**
798  * @brief Registers a callback function to detect errors.
799  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
800  * @param[in] tts The TTS handle
801  * @param[in] callback The callback function to register
802  * @param[in] user_data The user data to be passed to the callback function
803  * @return @c 0 on success,
804  *         otherwise a negative error value
805  * @retval #TTS_ERROR_NONE Successful
806  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
807  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
808  * @retval #TTS_ERROR_INVALID_STATE Invalid state
809  * @pre The state should be #TTS_STATE_CREATED.
810  * @see tts_error_cb()
811  * @see tts_unset_error_cb()
812 */
813 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data);
814
815
816 /**
817  * @brief Unregisters the callback function.
818  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
819  * @param[in] tts The TTS handle
820  * @return @c 0 on success,
821  *         otherwise a negative error value
822  * @retval #TTS_ERROR_NONE Successful
823  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
824  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
825  * @retval #TTS_ERROR_INVALID_STATE Invalid state
826  * @pre The state should be #TTS_STATE_CREATED.
827  * @see tts_set_error_cb()
828 */
829 int tts_unset_error_cb(tts_h tts);
830
831
832 /**
833  * @brief Registers a callback function to detect default voice change.
834  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
835  * @param[in] tts The TTS handle
836  * @param[in] callback The callback function to register
837  * @param[in] user_data The user data to be passed to the callback function
838  * @return @c 0 on success,
839  *         otherwise a negative error value
840  * @retval #TTS_ERROR_NONE Successful
841  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
842  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
843  * @retval #TTS_ERROR_INVALID_STATE Invalid state
844  * @pre The state should be #TTS_STATE_CREATED.
845  * @see tts_default_voice_changed_cb()
846  * @see tts_unset_default_voice_changed_cb()
847 */
848 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data);
849
850
851 /**
852  * @brief Unregisters the callback function.
853  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
854  * @param[in] tts The TTS handle
855  * @return @c 0 on success,
856  *         otherwise a negative error value
857  * @retval #TTS_ERROR_NONE Successful
858  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
859  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
860  * @retval #TTS_ERROR_INVALID_STATE Invalid state
861  * @pre The state should be #TTS_STATE_CREATED.
862  * @see tts_set_default_voice_changed_cb()
863 */
864 int tts_unset_default_voice_changed_cb(tts_h tts);
865
866
867  /**
868  * @brief Registers a callback function to detect the engine change.
869  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
870  * @param[in] tts The TTS handle
871  * @param[in] callback The callback function to register
872  * @param[in] user_data The user data to be passed to the callback function
873  * @return @c 0 on success,
874  *         otherwise a negative error value
875  * @retval #TTS_ERROR_NONE Successful
876  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
877  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
878  * @retval #TTS_ERROR_INVALID_STATE Invalid state
879  * @pre The state should be #TTS_STATE_CREATED.
880  * @see tts_engine_changed_cb()
881  * @see tts_unset_engine_changed_cb()
882 */
883 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data);
884
885
886 /**
887  * @brief Unregisters the callback function.
888  * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
889  * @param[in] tts The TTS handle
890  * @return @c 0 on success,
891  *         otherwise a negative error value
892  * @retval #TTS_ERROR_NONE Successful
893  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
894  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
895  * @retval #TTS_ERROR_INVALID_STATE Invalid state
896  * @pre The state should be #TTS_STATE_CREATED.
897  * @see tts_set_engine_changed_cb()
898 */
899 int tts_unset_engine_changed_cb(tts_h tts);
900
901
902 /**
903  * @brief Registers a callback function to detect the option of screen reader is changed or not.
904  * @since_tizen 6.5
905  * @remarks If TTS mode is #TTS_MODE_SCREEN_READER, you should set the callback to check the option of screen reader is changed or not.
906  * @param[in] tts The TTS handle
907  * @param[in] callback The callback function to register
908  * @param[in] user_data The user data to be passed to the callback function
909  * @return @c 0 on success,
910  *         otherwise a negative error value
911  * @retval #TTS_ERROR_NONE Successful
912  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
913  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
914  * @retval #TTS_ERROR_INVALID_STATE Invalid state
915  * @pre The state should be #TTS_STATE_CREATED.
916  * @see tts_screen_reader_changed_cb()
917  * @see tts_unset_screen_reader_changed_cb()
918 */
919 int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb callback, void* user_data);
920
921
922 /**
923  * @brief Unregisters the callback function to detect the option of screen reader is changed or not.
924  * @since_tizen 6.5
925  * @param[in] tts The TTS handle
926  * @return @c 0 on success,
927  *         otherwise a negative error value
928  * @retval #TTS_ERROR_NONE Successful
929  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
930  * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
931  * @retval #TTS_ERROR_INVALID_STATE Invalid state
932  * @pre The state should be #TTS_STATE_CREATED.
933  * @see tts_set_screen_reader_changed_cb()
934 */
935 int tts_unset_screen_reader_changed_cb(tts_h tts);
936
937 #ifdef __cplusplus
938 }
939 #endif
940
941
942 /**
943  * @}
944  */
945
946
947 #endif  /* __TTS_H__ */