Store current service state from engine library
[platform/core/uifw/tts.git] / include / ttse.h
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #ifndef __TTSE_H__
16 #define __TTSE_H__
17
18
19 #include <tizen.h>
20
21
22 /**
23 * @addtogroup CAPI_UIX_TTSE_MODULE
24 * @{
25 */
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 /**
34 * @brief Enumeration for error codes.
35 * @since_tizen 3.0
36 */
37 typedef enum {
38         TTSE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
39         TTSE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
40         TTSE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
41         TTSE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
42         TTSE_ERROR_NETWORK_DOWN = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */
43         TTSE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
44         TTSE_ERROR_INVALID_STATE = TIZEN_ERROR_TTS | 0x01, /**< Invalid state */
45         TTSE_ERROR_INVALID_VOICE = TIZEN_ERROR_TTS | 0x02, /**< Invalid voice */
46         TTSE_ERROR_OPERATION_FAILED = TIZEN_ERROR_TTS | 0x04, /**< Operation failed */
47         TTSE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06, /**< Not supported feature */
48         TTSE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not supported */
49 } ttse_error_e;
50
51
52 /**
53 * @brief Enumeration for audio type.
54 * @since_tizen 3.0
55 */
56 typedef enum {
57         TTSE_AUDIO_TYPE_RAW_S16 = 0, /**< Signed 16-bit audio type */
58         TTSE_AUDIO_TYPE_RAW_U8, /**< Unsigned 8-bit audio type */
59         TTSE_AUDIO_TYPE_MAX
60 } ttse_audio_type_e;
61
62
63 /**
64 * @brief Enumeration for result event type.
65 * @since_tizen 3.0
66 */
67 typedef enum {
68         TTSE_RESULT_EVENT_FAIL = -1, /**< Event when the voice synthesis is failed */
69         TTSE_RESULT_EVENT_START = 1, /**< Event when the sound data is first data by callback function */
70         TTSE_RESULT_EVENT_CONTINUE      = 2, /**< Event when the next sound data exist, not first and not last */
71         TTSE_RESULT_EVENT_FINISH = 3 /**< Event when the sound data is last data or sound data is only one result */
72 } ttse_result_event_e;
73
74 /**
75 * @brief Enumeration for TTS mode mask.
76 * @since_tizen 7.0
77 */
78 typedef enum {
79         TTSE_MODE_MASK_DEFAULT = 0x01, /**< Default mode */
80         TTSE_MODE_MASK_NOTIFICATION = 0x02, /**< Notification mode */
81         TTSE_MODE_MASK_SCREEN_READER = 0x04, /**< Screen reader mode */
82         TTSE_MODE_MASK_INTERRUPT = 0x08 /**< Interrupt mode */
83 } ttse_mode_mask_e;
84
85
86 /**
87 * @brief Definition for male voice type.
88 * @since_tizen 3.0
89 */
90 #define TTSE_VOICE_TYPE_MALE    1
91
92
93 /**
94 * @brief Definition for female voice type.
95 * @since_tizen 3.0
96 */
97 #define TTSE_VOICE_TYPE_FEMALE  2
98
99
100 /**
101 * @brief Definition for child's voice type.
102 * @since_tizen 3.0
103 */
104 #define TTSE_VOICE_TYPE_CHILD   3
105
106 /**
107 * @brief Called when TTS engine informs the engine service user about whole supported language and voice type list.
108 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
109 * @since_tizen 3.0
110 * @remarks This callback function is called by ttse_foreach_supported_voices_cb() to inform the whole supported voice list.
111 *          @a user_data must be transferred from ttse_foreach_supported_voices_cb().
112 * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code
113 *                     followed by ISO 639-1 for the two-letter language code.
114 *                     For example, "ko_KR" for Korean, "en_US" for American English
115 * @param[in] type The voice type
116 * @param[in] user_data The user data passed from ttse_foreach_supported_voices_cb()
117 * @return @c true to continue with the next iteration of the loop
118 *         @c false to break out of the loop
119 * @pre ttse_foreach_supported_voices_cb() will invoke this callback function.
120 * @see ttse_foreach_supported_voices_cb()
121 */
122 typedef bool (*ttse_supported_voice_cb)(const char* language, int type, void* user_data);
123
124
125 /**
126 * @brief Called when the engine service user initializes TTS engine.
127 * @since_tizen 3.0
128 * @remarks This callback function is mandatory and must be registered using ttse_main().
129 * @return @c 0 on success,
130 *         otherwise a negative error value
131 * @retval #TTSE_ERROR_NONE Successful
132 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
133 * @retval #TTSE_ERROR_INVALID_STATE Already initialized
134 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
135 * @retval #TTSE_ERROR_PERMISSION_DENIED Permission denied
136 * @see ttse_deinitialize_cb()
137 */
138 typedef int (*ttse_initialize_cb)(void);
139
140
141 /**
142 * @brief Called when the engine service user deinitializes TTS engine.
143 * @since_tizen 3.0
144 * @remarks This callback function is mandatory and must be registered using ttse_main().
145 *          NOTE that the engine may be terminated automatically.
146 *          When this callback function is invoked, the release of resources is necessary.
147 * @return @c 0 on success,
148 *         otherwise a negative error value
149 * @retval #TTSE_ERROR_NONE Successful
150 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
151 * @see ttse_initialize_cb()
152 */
153 typedef int (*ttse_deinitialize_cb)(void);
154
155
156 /**
157 * @brief Called when the engine service user gets the whole supported voice list.
158 * @since_tizen 3.0
159 * @remarks This callback function is mandatory and must be registered using ttse_main().
160 *          In this function, the engine service user's callback function 'ttse_supported_voice_cb()' is invoked repeatedly for getting all supported voices, and @a user_data must be transferred to 'ttse_supported_voice_cb()'.
161 *          If 'ttse_supported_voice_cb()' returns @c false, it should be stopped to call 'ttse_supported_voice_cb()'.
162 * @param[in] callback The callback function
163 * @param[in] user_data The user data which must be passed to ttse_supported_voice_cb()
164 * @return @c 0 on success,
165 *         otherwise a negative error value
166 * @retval #TTSE_ERROR_NONE Successful
167 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
168 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
169 * @post This callback function invokes ttse_supported_voice_cb() repeatedly for getting all supported voices.
170 * @see ttse_supported_voice_cb()
171 */
172 typedef int (*ttse_foreach_supported_voices_cb)(ttse_supported_voice_cb callback, void* user_data);
173
174
175 /**
176 * @brief Called when the engine service user checks whether the voice is valid or not in TTS engine.
177 * @since_tizen 3.0
178 * @remarks This callback function is mandatory and must be registered using ttse_main().
179 * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code
180 *                     followed by ISO 639-1 for the two-letter language code.
181 *                     For example, "ko_KR" for Korean, "en_US" for American English
182 * @param[in] type The voice type
183 * @param[out] is_valid A variable for checking whether the corresponding voice is valid or not.
184 *                      @c true to be valid,
185 *                      @c false to be invalid
186 * @return @c 0 on success,
187 *         otherwise a negative error value
188 * @retval #TTSE_ERROR_NONE Successful
189 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
190 * @see ttse_foreach_supported_voices_cb()
191 */
192 typedef int (*ttse_is_valid_voice_cb)(const char* language, int type, bool* is_valid);
193
194
195 /**
196 * @brief Called when the engine service user sets the default pitch of TTS engine.
197 * @since_tizen 3.0
198 * @remarks This callback function is mandatory and must be registered using ttse_main().
199 * @param[in] pitch The default pitch
200 * @return @c 0 on success,
201 *         otherwise a negative error value
202 * @retval #TTSE_ERROR_NONE Successful
203 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
204 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
205 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
206 */
207 typedef int (*ttse_set_pitch_cb)(int pitch);
208
209
210 /**
211 * @brief Called when the engine service user requests to load the corresponding voice type for the first time.
212 * @since_tizen 3.0
213 * @remarks This callback function is mandatory and must be registered using ttse_main().
214 * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code
215 *                     followed by ISO 639-1 for the two-letter language code.
216 *                     For example, "ko_KR" for Korean, "en_US" for American English
217 * @param[in] type The voice type
218 * @return @c 0 on success,
219 *         otherwise a negative error value
220 * @retval #TTSE_ERROR_NONE Successful
221 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
222 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
223 * @retval #TTSE_ERROR_OUT_OF_MEMORY Out of memory
224 * @retval #TTSE_ERROR_INVALID_VOICE Invalid voice
225 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
226 * @see ttse_unload_voice_cb()
227 */
228 typedef int (*ttse_load_voice_cb)(const char* language, int type);
229
230
231 /**
232 * @brief Called when the engine service user requests to unload the corresponding voice type or to stop using voice.
233 * @since_tizen 3.0
234 * @remarks This callback function is mandatory and must be registered using ttse_main().
235 * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code
236 *                     followed by ISO 639-1 for the two-letter language code.
237 *                     For example, "ko_KR" for Korean, "en_US" for American English
238 * @param[in] type The voice type
239 * @return @c 0 on success,
240 *         otherwise a negative error value
241 * @retval #TTSE_ERROR_NONE Successful
242 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
243 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
244 * @retval #TTSE_ERROR_INVALID_VOICE Invalid voice
245 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
246 * @see ttse_load_voice_cb()
247 */
248 typedef int (*ttse_unload_voice_cb)(const char* language, int type);
249
250
251 /**
252 * @brief Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine.
253 * @details This callback function is called when the engine service user requests for TTS engine to check the application's agreement about using the engine.
254 *          According to the need, the engine developer can provide some user interfaces to check the agreement.
255 * @since_tizen 3.0
256 * @remarks This callback function is mandatory and must be registered using ttse_main().
257 *          If the TTS engine developer wants not to check the agreement, the developer has need to return proper values as @a is_agreed in accordance with the intention. @c true if the developer regards that every application agreed the usage of the engine, @c false if the developer regards that every application disagreed.
258 *          NOTE that, however, there may be any legal issue unless the developer checks the agreement. Therefore, we suggest that the engine developers should provide a function to check the agreement.
259 * @param[in] appid The Application ID
260 * @param[out] is_agreed A variable for checking whether the application agreed to use TTS engine or not.
261 *                       @c true to agree,
262 *                       @c false to disagree
263 * @return @c 0 on success,
264 *         otherwise a negative error value
265 * @retval #TTSE_ERROR_NONE Successful
266 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
267 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
268 * @retval #TTSE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
269 */
270 typedef int (*ttse_check_app_agreed_cb)(const char* appid, bool* is_agreed);
271
272
273 /**
274 * @brief Called when the engine service user checks whether TTS engine needs the application's credential.
275 * @since_tizen 3.0
276 * @remarks This callback function is mandatory and must be registered using ttse_main().
277 * @return @c true if TTS engine needs the application's credential,
278 *         otherwise @c false
279 */
280 typedef bool (*ttse_need_app_credential_cb)(void);
281
282
283 /**
284 * @brief Called when the engine service user starts to synthesize a voice, asynchronously.
285 * @since_tizen 3.0
286 * @remarks This callback function is mandatory and must be registered using ttse_main().
287 *          In this callback function, TTS engine must transfer the synthesized result and @a user_data to the engine service user using ttse_send_result().
288 *          Also, if TTS engine needs the application's credential, it can set the credential granted to the application.
289 * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code
290 *                     followed by ISO 639-1 for the two-letter language code.
291 *                     For example, "ko_KR" for Korean, "en_US" for American English
292 * @param[in] type The voice type
293 * @param[in] text Texts
294 * @param[in] speed The speed of speaking
295 * @param[in] appid The Application ID
296 * @param[in] credential The credential granted to the application
297 * @param[in] user_data The user data which must be passed to ttse_send_result()
298 * @return @c 0 on success,
299 *         otherwise a negative error value
300 * @retval #TTSE_ERROR_NONE Successful
301 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
302 * @retval #TTSE_ERROR_INVALID_STATE Not initialized or already started synthesis
303 * @retval #TTSE_ERROR_INVALID_VOICE Invalid voice
304 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
305 * @retval #TTSE_ERROR_NETWORK_DOWN Out of network
306 * @retval #TTSE_ERROR_PERMISSION_DENIED Permission denied
307 * @post This function invokes ttse_send_result().
308 * @see ttse_send_result()
309 * @see ttse_cancel_synthesis_cb()
310 * @see ttse_need_app_credential_cb()
311 */
312 typedef int (*ttse_start_synthesis_cb)(const char* language, int type, const char* text, int speed, const char* appid, const char* credential, void* user_data);
313
314
315 /**
316 * @brief Called when the engine service user cancels to synthesize a voice.
317 * @since_tizen 3.0
318 * @remarks This callback function is mandatory and must be registered using ttse_main().
319 * @return @c 0 on success,
320 *         otherwise a negative error value
321 * @retval #TTSE_ERROR_NONE Successful
322 * @retval #TTSE_ERROR_INVALID_STATE Not initialized or not started synthesis
323 * @pre The ttse_start_synthesis_cb() should be performed
324 * @see ttse_start_synthesis_cb()
325 */
326 typedef int (*ttse_cancel_synthesis_cb)(void);
327
328
329 /**
330 * @brief Called when the engine service user requests the basic information of TTS engine.
331 * @since_tizen 3.0
332 * @remarks This callback function is mandatory and must be registered using ttse_main().
333 *          The allocated @a engine_uuid, @a engine_name, and @a engine_setting will be released internally.
334 *          In order to upload the engine at Tizen Appstore, both a service app and a ui app are necessary.
335 *          Therefore, @a engine_setting must be transferred to the engine service user.
336 * @param[out] engine_uuid UUID of engine
337 * @param[out] engine_name Name of engine
338 * @param[out] engine_setting The engine setting application(ui app)'s app ID
339 * @param[out] use_network The status for using network
340 * @return @c 0 on success,
341 *         otherwise a negative error code on failure
342 * @retval #TTSE_ERROR_NONE Successful
343 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
344 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
345 */
346 typedef int (*ttse_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
347
348
349 /**
350 * @brief Called when TTS engine receives the private data from the engine service user.
351 * @details This callback function is called when the engine service user sends the private data to TTS engine.
352 * @since_tizen 3.0
353 * @remarks This callback function is optional and is registered using ttse_set_private_data_set_cb().
354 * @param[in] key The key field of private data
355 * @param[in] data The data field of private data
356 * @return @c 0 on success,
357 *         otherwise a negative error value
358 * @retval #TTSE_ERROR_NONE Successful
359 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
360 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
361 * @retval #TTSE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
362 * @see ttse_private_data_requested_cb()
363 * @see ttse_set_private_data_set_cb()
364 */
365 typedef int (*ttse_private_data_set_cb)(const char* key, const char* data);
366
367
368 /**
369 * @brief Called when TTS engine provides the engine service user with the private data.
370 * @details This callback function is called when the engine service user gets the private data from TTS engine.
371 * @since_tizen 3.0
372 * @remarks This callback function is optional and is registered using ttse_set_private_data_requested_cb().
373 * @param[out] key The key field of private data
374 * @param[out] data The data field of private data
375 * @return @c 0 on success,
376 *         otherwise a negative error value
377 * @retval #TTSE_ERROR_NONE Successful
378 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
379 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
380 * @retval #TTSE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
381 * @see ttse_private_data_set_cb()
382 * @see ttse_set_private_data_requested_cb()
383 */
384 typedef int (*ttse_private_data_requested_cb)(const char* key, char** data);
385
386
387 /**
388 * @brief Called when activated modes are changed.
389 * @details When a client connects to TTS engine, the engine activates the TTS mode of the client.
390 *          For example, if two clients, one is default mode and other is screen reader mode, connect to TTS engine, then the
391 *          @a activated_mode has the same bit sequence as '#TTSE_MODE_MASK_DEFAULT | #TTSE_MODE_MASK_SCREEN_READER'.
392 *          The activated TTS modes are decided according to the connected clients, so when a client connects or disconnects to
393 *          the engine, the activated TTS modes may be changed.
394 *          This callback function is called when the activated TTS modes are changed.
395 * @since_tizen 7.0
396 * @remarks This callback function is optional and is registered using ttse_set_activated_mode_changed_cb().
397 * @param[in] activated_mode The activated TTS modes by connected clients, values of ttse_mode_mask_e combined with bitwise 'or'.
398 * @see ttse_set_activated_mode_changed_cb()
399 * @see ttse_get_activated_mode()
400 */
401 typedef void (*ttse_activated_mode_changed_cb)(int activated_mode);
402
403
404 /**
405 * @brief A structure for the TTS engine functions.
406 * @details This structure contains essential callback functions for operating TTS engine.
407 * @since_tizen 3.0
408 * @remarks These functions are mandatory for operating TTS engine. Therefore, all functions MUST be implemented.
409 */
410 typedef struct {
411         int version; /**< The version of the structure 'ttse_request_callback_s' */
412         ttse_get_info_cb                        get_info; /**< Called when the engine service user requests the basic information of TTS engine */
413
414         ttse_initialize_cb                      initialize; /**< Called when the engine service user initializes TTS engine */
415         ttse_deinitialize_cb                    deinitialize; /**< Called when the engine service user deinitializes TTS engine */
416
417         ttse_foreach_supported_voices_cb        foreach_voices; /**< Called when the engine service user gets the whole supported voice list */
418         ttse_is_valid_voice_cb                  is_valid_voice; /**< Called when the engine service user checks whether the voice is valid or not in TTS engine */
419         ttse_set_pitch_cb                       set_pitch; /**< Called when the engine service user sets the default pitch of TTS engine */
420
421         ttse_load_voice_cb                      load_voice; /**< Called when the engine service user requests to load the corresponding voice type for the first time */
422         ttse_unload_voice_cb                    unload_voice; /**< Called when the engine service user requests to unload the corresponding voice type or to stop using voice */
423
424         ttse_start_synthesis_cb                 start_synth; /**< Called when the engine service user starts to synthesize a voice, asynchronously */
425         ttse_cancel_synthesis_cb                cancel_synth; /**< Called when the engine service user cancels to synthesize a voice */
426
427         ttse_check_app_agreed_cb                check_app_agreed; /**< Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine */
428         ttse_need_app_credential_cb             need_app_credential; /**< Called when the engine service user checks whether TTS engine needs the application's credential */
429 } ttse_request_callback_s;
430
431
432 /**
433 * @brief Main function for Text-To-Speech (TTS) engine.
434 * @details This function is the main function for operating TTS engine.
435 * @since_tizen 3.0
436 * @remarks The service_app_main() should be used for working the engine after this function.
437 * @param[in] argc The argument count(original)
438 * @param[in] argv The argument(original)
439 * @param[in] callback The structure of engine request callback function
440 * @return This function returns zero on success,
441 *         or negative with error code on failure
442 * @retval #TTSE_ERROR_NONE Successful
443 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
444 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
445 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
446 * @see ttse_request_callback_s
447 * @code
448 #include <ttse.h>
449
450 // Required callback functions - MUST BE IMPLEMENTED
451 static int ttsengine_get_info_cb(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
452 static int ttsengine_initialize_cb(void);
453 static int ttsengine_deinitialize_cb(void);
454 static int ttsengine_is_valid_voice_cb(const char* language, int type, bool* is_valid);
455 static int ttsengine_foreach_supported_voices_cb(ttse_supported_voice_cb callback, void* user_data);
456 static int ttsengine_set_pitch_cb(int pitch);
457 static int ttsengine_load_voice_cb(const char* language, int type);
458 static int ttsengine_unload_voice_cb(const char* language, int type);
459 static int ttsengine_start_synthesis_cb(const char* language, int type, const char* text, int speed, void* user_data);
460 static int ttsengine_cancel_synthesis_cb(void);
461 static int ttsengine_check_app_agreed_cb(const char* appid, bool* is_agreed);
462 static bool ttsengine_need_app_credential_cb(void);
463
464 // Optional callback function
465 static int ttsengine_private_data_set_cb(const char* key, const char* data);
466
467 int main(int argc, char* argv[])
468 {
469         // 1. Create a structure 'ttse_request_callback_s'
470         ttse_request_callback_s engine_callback = { 0, };
471
472         engine_callback.size = sizeof(ttse_request_callback_s);
473         engine_callback.version = 1;
474         engine_callback.get_info = ttsengine_get_info_cb;
475         engine_callback.initialize = ttsengine_initialize_cb;
476         engine_callback.deinitialize = ttsengine_deinitialize_cb;
477         engine_callback.foreach_voices = ttsengine_foreach_supported_voices_cb;
478         engine_callback.is_valid_voice = ttsengine_is_valid_voice_cb;
479         engine_callback.set_pitch = ttsengine_set_pitch_cb;
480         engine_callback.load_voice = ttsengine_load_voice_cb;
481         engine_callback.unload_voice = ttsengine_unload_voice_cb;
482         engine_callback.start_synth = ttsengine_start_synthesis_cb;
483         engine_callback.cancel_synth = ttsengine_cancel_synthesis_cb;
484         engine_callback.check_app_agreed = ttsengine_check_app_agreed_cb;
485         engine_callback.need_app_credential = ttsengine_need_app_credential_cb;
486
487         // 2. Run 'ttse_main()'
488         if (0 != ttse_main(argc, argv, &engine_callback)) {
489                 return -1;
490         }
491
492         // Optional
493         ttse_set_private_data_set_cb(ttsengine_private_data_set_cb);
494
495         // 3. Set event callbacks for service app and Run 'service_app_main()'
496         char ad[50] = { 0, };
497
498         service_app_lifecycle_callback_s event_callback;
499         app_event_handler_h handlers[5] = { NULL, };
500
501         event_callback.create = service_app_create;
502         event_callback.terminate = service_app_terminate;
503         event_callback.app_control = service_app_control;
504
505         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
506         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
507         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
508         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
509
510         return service_app_main(argc, argv, &event_callback, ad);
511 }
512
513 * @endcode
514 */
515 int ttse_main(int argc, char** argv, ttse_request_callback_s *callback);
516
517
518 /**
519 * @brief Terminates the main function of TTS engine.
520 * @since_tizen 7.0
521 * @remarks This function invokes ttse_deinitialize_cb() in #ttse_request_callback_s which is registered by ttse_main().
522 *          And this function should be called before terminating the engine to ensure safe termination.
523 * @return @c 0 on success,
524 *         otherwise a negative error value
525 * @retval #TTSE_ERROR_NONE Successful
526 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
527 */
528 int ttse_terminate(void);
529
530
531 /**
532 * @brief Gets the speed range from Tizen platform.
533 * @since_tizen 3.0
534 * @remarks This API is used when TTS engine wants to get the speed range from Tizen platform.
535 * @param[out] min The minimum speed value
536 * @param[out] normal The normal speed value
537 * @param[out] max The maximum speed value
538 * @return @c 0 on success,
539 *         otherwise a negative error value
540 * @retval #TTSE_ERROR_NONE Successful
541 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
542 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
543 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
544 */
545 int ttse_get_speed_range(int* min, int* normal, int* max);
546
547
548 /**
549 * @brief Gets the pitch range from Tizen platform.
550 * @since_tizen 3.0
551 * @remarks This API is used when TTS engine wants to get the pitch range from Tizen platform.
552 * @param[out] min The minimum pitch value
553 * @param[out] normal The normal pitch value
554 * @param[out] max The maximum pitch value
555 * @return @c 0 on success,
556 *         otherwise a negative error value
557 * @retval #TTSE_ERROR_NONE Successful
558 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
559 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
560 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
561 */
562 int ttse_get_pitch_range(int* min, int* normal, int* max);
563
564
565 /**
566 * @brief Sends the synthesized result to the engine service user.
567 * @since_tizen 3.0
568 * @remarks This API is used in ttse_start_synthesis_cb(), when TTS engine sends the synthesized result to the engine service user.
569 *          The synthesized result and @a user_data must be transferred to the engine service user through this function.
570 * @param[in] event The result event
571 * @param[in] data Result data
572 * @param[in] data_size Result data size
573 * @param[in] audio_type The audio type
574 * @param[in] rate The sample rate
575 * @param[in] user_data The user data passed from ttse_start_synthesis_cb()
576 * @return @c 0 on success,
577 *         otherwise a negative error value
578 * @retval #TTSE_ERROR_NONE Successful
579 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
580 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
581 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
582 * @pre The ttse_main() function should be invoked before this function is called.
583 *          ttse_start_synthesis_cb() will invoke this function.
584 * @see ttse_start_synthesis_cb()
585 */
586 int ttse_send_result(ttse_result_event_e event, const void* data, unsigned int data_size,
587                         ttse_audio_type_e audio_type, int rate, void* user_data);
588
589
590 /**
591 * @brief Sends the error to the engine service user.
592 * @details The following error codes can be delivered.
593 *          #TTSE_ERROR_NONE,
594 *          #TTSE_ERROR_OUT_OF_MEMORY,
595 *          #TTSE_ERROR_IO_ERROR,
596 *          #TTSE_ERROR_INVALID_PARAMETER,
597 *          #TTSE_ERROR_NETWORK_DOWN,
598 *          #TTSE_ERROR_PERMISSION_DENIED,
599 *          #TTSE_ERROR_INVALID_STATE,
600 *          #TTSE_ERROR_INVALID_VOICE,
601 *          #TTSE_ERROR_OPERATION_FAILED,
602 *          #TTSE_ERROR_NOT_SUPPORTED_FEATURE,
603 *          #TTSE_ERROR_NOT_SUPPORTED.
604 * @since_tizen 3.0
605 * @param[in] error The error reason
606 * @param[in] msg The error message
607 * @return @c 0 on success,
608 *         otherwise a negative error value
609 * @retval #TTSE_ERROR_NONE Successful
610 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
611 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
612 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
613 * @pre The ttse_main() function should be invoked before this function is called.
614 */
615 int ttse_send_error(ttse_error_e error, const char* msg);
616
617
618 /**
619 * @brief Sets a callback function for setting the private data.
620 * @since_tizen 3.0
621 * @remarks The ttse_private_data_set_cb() function is called when the engine service user sends the private data.
622 * @param[in] callback_func ttse_private_data_set event callback function
623 * @return @c 0 on success,
624 *         otherwise a negative error value
625 * @retval #TTSE_ERROR_NONE Successful
626 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
627 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
628 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
629 * @pre The ttse_main() function should be invoked before this function is called.
630 * @see ttse_private_data_set_cb()
631 */
632 int ttse_set_private_data_set_cb(ttse_private_data_set_cb callback_func);
633
634
635 /**
636 * @brief Sets a callback function for requesting the private data.
637 * @since_tizen 3.0
638 * @remarks The ttse_private_data_requested_cb() function is called when the engine service user gets the private data from TTS engine.
639 * @param[in] callback_func ttse_private_data_requested event callback function
640 * @return @c 0 on success,
641 *         otherwise a negative error value
642 * @retval #TTSE_ERROR_NONE Successful
643 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
644 * @retval #TTSE_ERROR_NOT_SUPPORTED Not supported
645 * @retval #TTSE_ERROR_OPERATION_FAILED Operation failure
646 * @pre The ttse_main() function should be invoked before this function is called.
647 * @see ttse_private_data_requested_cb()
648 */
649 int ttse_set_private_data_requested_cb(ttse_private_data_requested_cb callback_func);
650
651
652 /**
653 * @brief Gets activated modes.
654 * @details When a client connects to TTS engine, the engine activates the TTS mode of the client.
655 *          For example, if two clients, one is default mode and other is screen reader mode, connect to TTS engine, then the
656 *          @a activated_mode has the same bit sequence as '#TTSE_MODE_MASK_DEFAULT | #TTSE_MODE_MASK_SCREEN_READER'.
657 *          Using this API, the engine can get the activated TTS modes information.
658 * @since_tizen 7.0
659 * @param[out] activated_mode The activated TTS mode by connected clients, values of ttse_mode_mask_e combined with bitwise 'or'.
660 * @return @c 0 on success,
661 *         otherwise a negative error value
662 * @retval #TTSE_ERROR_NONE Successful
663 * @retval #TTSE_ERROR_NOT_SUPPORTED TTS NOT supported
664 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
665 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
666 * @pre The ttse_main() function should be invoked before this function is called.
667 * @see ttse_set_activated_mode_changed_cb()
668 */
669 int ttse_get_activated_mode(int* activated_mode);
670
671
672 /**
673 * @brief Sets a callback function to be called when the activated TTS modes are changed.
674 * @since_tizen 7.0
675 * @remarks The ttse_activated_mode_changed_cb() function is called when the activated TTS modes are changed.
676 * @param[in] callback ttse_activated_mode_changed event callback function
677 * @return @c 0 on success,
678 *         otherwise a negative error value
679 * @retval #TTSE_ERROR_NONE Successful
680 * @retval #TTSE_ERROR_NOT_SUPPORTED TTS NOT supported
681 * @retval #TTSE_ERROR_INVALID_PARAMETER Invalid parameter
682 * @retval #TTSE_ERROR_INVALID_STATE Not initialized
683 * @pre The ttse_main() function should be invoked before this function is called.
684 * @see ttse_activated_mode_changed_cb()
685 * @see ttse_get_activated_mode()
686 */
687 int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback);
688
689
690 #ifdef __cplusplus
691 }
692 #endif
693
694
695 /**
696  * @}
697  */
698
699
700 #endif /* __TTSE_H__ */