Add to set playing mode to decide where the synthesized pcm data will be played
[platform/core/uifw/tts.git] / client / tts.c
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 #include <app_manager.h>
15 #include <dirent.h>
16 #include <Ecore.h>
17 #include <system_info.h>
18 #include <vconf.h>
19 #include <package-manager.h>
20 #include <pthread.h>
21
22 #include "tts.h"
23 #include "tts_client.h"
24 #include "tts_config_mgr.h"
25 #include "tts_main.h"
26 #include "tts_core.h"
27 #include "tts_ipc.h"
28 #include "tts_dlog.h"
29
30 #include "tts_internal.h"
31
32 static int g_feature_enabled = -1;
33
34
35 static int __tts_get_feature_enabled()
36 {
37         RETV_IF(1 == g_feature_enabled, TTS_ERROR_NONE);
38         RETVM_IF(0 == g_feature_enabled, TTS_ERROR_NOT_SUPPORTED, "[ERROR] TTS feature NOT supported");
39
40         bool tts_supported = false;
41         if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
42                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
43                 return TTS_ERROR_NOT_SUPPORTED;
44         }
45
46         if (false == tts_supported) {
47                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
48                 g_feature_enabled = 0;
49                 return TTS_ERROR_NOT_SUPPORTED;
50         }
51
52         g_feature_enabled = 1;
53         return TTS_ERROR_NONE;
54 }
55
56 // TODO: move into tts_core to make common function
57 //LCOV_EXCL_START
58 static int __tts_convert_config_error_code(tts_config_error_e code)
59 {
60         if (code == TTS_CONFIG_ERROR_NONE)                      return TTS_ERROR_NONE;
61         if (code == TTS_CONFIG_ERROR_OUT_OF_MEMORY)             return TTS_ERROR_OUT_OF_MEMORY;
62         if (code == TTS_CONFIG_ERROR_IO_ERROR)                  return TTS_ERROR_IO_ERROR;
63         if (code == TTS_CONFIG_ERROR_INVALID_PARAMETER)         return TTS_ERROR_INVALID_PARAMETER;
64         if (code == TTS_CONFIG_ERROR_INVALID_STATE)             return TTS_ERROR_INVALID_STATE;
65         if (code == TTS_CONFIG_ERROR_INVALID_VOICE)             return TTS_ERROR_INVALID_VOICE;
66         if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND)          return TTS_ERROR_ENGINE_NOT_FOUND;
67         if (code == TTS_CONFIG_ERROR_OPERATION_FAILED)          return TTS_ERROR_OPERATION_FAILED;
68         if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE)     return TTS_ERROR_NOT_SUPPORTED_FEATURE;
69
70         return code;
71 }
72
73 static void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
74 {
75         SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
76                 before_lang, before_voice_type, language, voice_type);
77
78         GList* client_list = tts_client_get_client_list();
79         if (NULL == client_list) {
80                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
81                 return;
82         }
83
84         GList *iter = NULL;
85         if (g_list_length(client_list) > 0) {
86                 /* Get a first item */
87                 iter = g_list_first(client_list);
88
89                 while (NULL != iter) {
90                         tts_client_s *client = iter->data;
91                         if (tts_client_is_valid_client(client)) {
92                                 tts_core_notify_default_voice_changed(client, before_lang, before_voice_type, language, voice_type);
93
94                                 /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
95                                 if (0 != strncmp(before_lang, language, strlen(before_lang))) {
96                                         tts_client_set_repeat_text(client, NULL);
97                                 }
98                         } else {
99                                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid (%p)", client);
100                         }
101
102                         /* Next item */
103                         iter = g_list_next(iter);
104                 }
105         }
106
107         g_list_free(client_list);
108
109         return;
110 }
111 /*
112 static Eina_Bool __reconnect_by_engine_changed(void* data)
113 {
114         tts_h tts = (tts_h)data;
115
116         tts_client_s* client = tts_client_get(tts);
117         if (NULL == client) {
118                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid. tts(%p)", tts);
119                 return EINA_FALSE;
120         }
121
122         tts_state_e current_state = tts_client_get_current_state(client);
123         if (TTS_STATE_READY != current_state) {
124                 usleep(10000);
125                 return EINA_TRUE;
126         }
127
128         // TODO: change to tts_core function
129         int ret = tts_unprepare(tts);
130         if (0 != ret) {
131                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
132         }
133         ret = tts_prepare(tts);
134         if (0 != ret) {
135                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
136         }
137
138         return EINA_FALSE;
139 }
140 */
141 static void __tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
142 {
143         tts_h tts = (tts_h)user_data;
144
145         tts_client_s* client = tts_client_get(tts);
146         RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
147
148         if (NULL != engine_id)  SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
149         if (NULL != setting)    SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
150         if (NULL != language)   SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
151         SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
152
153         /* When the default engine is changed, please unload the old engine and load the new one. */
154 /*      int ret = -1;
155
156         tts_state_e current_state = tts_client_get_current_state(client);
157         if (TTS_STATE_PLAYING == current_state || TTS_STATE_PAUSED == current_state) {
158                 ret = tts_stop(tts);
159                 if (0 != ret) {
160                         SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
161                 }
162
163                 ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
164         } else if (TTS_STATE_READY == current_state) {
165                 // TODO: change to tts_core function
166                 ret = tts_unprepare(tts);
167                 if (0 != ret) {
168                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
169                 }
170                 ret = tts_prepare(tts);
171                 if (0 != ret) {
172                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
173                 }
174         }
175 */
176         /* call callback function */
177         tts_core_notify_engine_changed(client, engine_id, language, voice_type, need_credential);
178         return;
179 }
180 //LCOV_EXCL_STOP
181
182 static void __tts_config_screen_reader_changed_cb(bool value, void* user_data)
183 {
184         tts_h tts = (tts_h)user_data;
185
186         tts_client_s* client = tts_client_get(tts);
187         RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
188
189         SLOG(LOG_DEBUG, TAG_TTSC, "Screen reader is changed. current status (%d)", value);
190
191         /* call callback function */
192         tts_core_notify_screen_reader_changed(client, value);
193 }
194
195 static int __initialize_tts_config(unsigned int uid, tts_h new_tts)
196 {
197         int ret = tts_config_mgr_initialize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
198         if (TTS_CONFIG_ERROR_NONE != ret) {
199                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
200                 return __tts_convert_config_error_code(ret);
201         }
202
203         ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, new_tts);
204         if (TTS_CONFIG_ERROR_NONE != ret) {
205                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
206                 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
207                 return __tts_convert_config_error_code(ret);
208         }
209
210         ret = tts_config_mgr_set_screen_reader_callback(uid, __tts_config_screen_reader_changed_cb, new_tts);
211         if (TTS_CONFIG_ERROR_NONE != ret) {
212                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
213                 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
214                 return __tts_convert_config_error_code(ret);
215         }
216
217         return TTS_ERROR_NONE;
218 }
219
220 int tts_create(tts_h* tts)
221 {
222         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
223
224         SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
225
226         RETVM_IF(NULL == tts, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
227
228         bool is_first_client = false;
229         if (0 == tts_client_get_size()) {
230                 is_first_client = true;
231         }
232
233         tts_h new_tts = NULL;
234         if (0 != tts_client_new(&new_tts)) {
235                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
236                 return TTS_ERROR_OUT_OF_MEMORY;
237         }
238
239         tts_client_s* client = tts_client_get(new_tts);
240         if (NULL == client) {
241                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
242                 tts_client_destroy(new_tts);
243                 return TTS_ERROR_OPERATION_FAILED;
244         }
245
246         unsigned int uid = tts_client_get_uid(client);
247         SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%u)", tts, client, uid);
248
249         if (false == tts_ipc_is_method_set()) {
250                 int pid = getpid();
251                 char* appid = NULL;
252                 int ret = app_manager_get_app_id(pid, &appid);
253                 if (0 != ret || NULL == appid) {
254                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d)", ret, pid);
255                         tts_ipc_set_method(TTS_IPC_METHOD_DBUS);
256                 } else {
257                         SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_create : client appid(%s), pid(%d)", appid, pid);
258                         tts_ipc_set_method(TTS_IPC_METHOD_TIDL);
259                 }
260
261                 if (NULL != appid) {
262                         free(appid);
263                         appid = NULL;
264                 }
265         }
266
267         if (0 != tts_ipc_open_connection(uid)) {
268                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open ipc connection");
269                 tts_client_destroy(new_tts);
270                 return TTS_ERROR_OPERATION_FAILED;
271         }
272
273         int ret = __initialize_tts_config(uid, new_tts);
274         if (TTS_ERROR_NONE != ret) {
275                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
276                 tts_client_destroy(new_tts);
277                 return ret;
278         }
279
280         if (is_first_client) {
281                 // These function would be called only when first client is created.
282                 if (0 != tts_core_initialize()) {
283                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize core");
284                         tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
285                         tts_client_destroy(new_tts);
286                         return TTS_ERROR_OPERATION_FAILED;
287                 }
288         }
289
290         *tts = new_tts;
291         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
292         return TTS_ERROR_NONE;
293 }
294
295 static int destroy_tts_handle(tts_h tts)
296 {
297         SLOG(LOG_INFO, TAG_TTSC, "Destroy TTS handle");
298         tts_client_s* client = tts_client_get(tts);
299         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
300
301         unsigned int uid = tts_client_get_uid(client);
302         SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%u)", tts, client, uid);
303
304         /* check used callback */
305         if (0 != tts_client_get_use_callback(client)) {
306                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot destroy in Callback function");
307                 return TTS_ERROR_OPERATION_FAILED;
308         }
309
310         tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
311
312         // TODO: move into tts_client
313         if (client->hello_timer) {
314                 ecore_timer_del(client->hello_timer);
315                 client->hello_timer = NULL;
316         }
317
318         switch (tts_client_get_current_state(client)) {
319         case TTS_STATE_PAUSED:
320         case TTS_STATE_PLAYING:
321         case TTS_STATE_READY: {
322                 if (0 != tts_core_unprepare(client)) {
323                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare");
324                 }
325                 tts_client_set_current_state(client, TTS_STATE_CREATED);
326         }
327         case TTS_STATE_CREATED: {
328                 /* Unset registered callbacks */
329                 tts_client_unset_all_cb(client);
330
331                 int thread_count = ecore_thread_active_get();
332                 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Active thread count: %d", thread_count);
333                 for (int cnt = 0; 0 < thread_count; cnt++) {
334                         usleep(50000);
335                         if (30 == cnt) {
336                                 SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Thread is blocked, %d", thread_count);
337                                 break;
338                         }
339                         thread_count = ecore_thread_active_get();
340                 }
341
342                 if (0 != tts_ipc_close_connection(uid)) {
343                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
344                         return TTS_ERROR_OPERATION_FAILED;
345                 }
346
347                 /* Free resources */
348                 tts_client_destroy(tts);
349
350                 break;
351         }
352         default: {
353                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
354                 return TTS_ERROR_INVALID_PARAMETER;
355         }
356         }
357
358         unsigned int num_of_client = tts_client_get_size();
359         SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%u)", num_of_client);
360
361         if (0 == num_of_client) {
362                 if (0 != tts_core_deinitialize()) {
363                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to deinitialize core");
364                 }
365         }
366
367         return TTS_ERROR_NONE;
368 }
369
370 static void *destroy_tts_handle_on_main_thread(void* data)
371 {
372         SLOG(LOG_INFO, TAG_TTSC, "Destroy on main thread synchronously");
373         tts_h tts = (tts_h)data;
374
375         int ret = destroy_tts_handle(tts);
376         intptr_t p_ret = (intptr_t)ret;
377
378         return (void *)p_ret;
379 }
380
381 int tts_destroy(tts_h tts)
382 {
383         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
384         SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
385
386         intptr_t ret = (intptr_t)ecore_main_loop_thread_safe_call_sync(destroy_tts_handle_on_main_thread, (void *)tts);
387         SLOG(LOG_INFO, TAG_TTSC, "Return value: (%d/%s)", (int)ret, get_error_message((int)ret));
388
389         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
390         return (int)ret;
391 }
392
393 int tts_set_mode(tts_h tts, tts_mode_e mode)
394 {
395         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
396
397         SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
398
399         RETVM_IF(TTS_MODE_DEFAULT > mode || TTS_MODE_INTERRUPT < mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] mode is not valid : %d", mode);
400
401         tts_client_s* client = tts_client_get(tts);
402         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
403
404         tts_state_e current_state = tts_client_get_current_state(client);
405         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
406
407         tts_client_set_mode(client, mode);
408
409         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
410         return TTS_ERROR_NONE;
411 }
412
413 int tts_get_mode(tts_h tts, tts_mode_e* mode)
414 {
415         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
416
417         SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
418
419         RETVM_IF(NULL == mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter(mode) is NULL");
420
421         tts_client_s* client = tts_client_get(tts);
422         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
423
424         tts_state_e current_state = tts_client_get_current_state(client);
425         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
426
427         *mode = tts_client_get_mode(client);
428
429         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
430         return TTS_ERROR_NONE;
431 }
432
433 int tts_set_playing_mode(tts_h tts, tts_playing_mode_e mode)
434 {
435         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
436
437         SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS playing mode(%d)", mode);
438
439         RETVM_IF(TTS_PLAYING_MODE_BY_CLIENT > mode || TTS_PLAYING_MODE_BY_SERVICE < mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] mode is not valid : %d", mode);
440
441         tts_client_s* client = tts_client_get(tts);
442         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
443
444         tts_state_e current_state = tts_client_get_current_state(client);
445         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
446
447         tts_client_set_playing_mode(client, mode);
448
449         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
450         return TTS_ERROR_NONE;
451 }
452
453 int tts_set_credential(tts_h tts, const char* credential)
454 {
455         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
456
457         RETVM_IF(NULL == credential, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
458
459         tts_client_s* client = tts_client_get(tts);
460         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
461
462         tts_state_e current_state = tts_client_get_current_state(client);
463         RETVM_IF(TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
464
465         tts_client_set_credential_key(client, credential);
466
467         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
468         return TTS_ERROR_NONE;
469 }
470
471 int tts_set_server_tts(tts_h tts, const char* credential)
472 {
473         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
474
475         tts_client_s* client = tts_client_get(tts);
476         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
477
478         // TODO: fix state check, because set_private_data runs only ready state
479         tts_state_e current_state = tts_client_get_current_state(client);
480         RETVM_IF(TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
481
482         // TODO: fix name more clear and move into tts_client
483         client->internal = true;
484
485         char* key = NULL;
486         if (NULL != credential) {
487                 key = "EnableServerTTS";
488                 tts_client_set_credential_key(client, credential);
489                 if (NULL == tts_client_get_credential_key(client)) {
490                         SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
491                         return TTS_ERROR_OUT_OF_MEMORY;
492                 }
493         } else {
494                 key = "DisableServerTTS";
495         }
496
497         int pid = getpid();
498         char* appid = NULL;
499         int ret = app_manager_get_app_id(pid, &appid);
500         if (0 != ret || NULL == appid) {
501                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);;
502                 if (NULL != appid) {
503                         free(appid);
504                         appid = NULL;
505                 }
506                 return TTS_ERROR_OPERATION_FAILED;
507         }
508
509         ret = tts_core_set_private_data(client, key, appid);
510         if (0 != ret) {
511                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
512                 free(appid);
513                 appid = NULL;
514                 return ret;
515         }
516
517         free(appid);
518         appid = NULL;
519
520         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
521         return TTS_ERROR_NONE;
522 }
523
524 int tts_prepare(tts_h tts)
525 {
526         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
527
528         tts_client_s* client = tts_client_get(tts);
529         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
530
531         tts_state_e current_state = tts_client_get_current_state(client);
532         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
533
534         SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
535         int ret = tts_core_prepare(client);
536         if (0 != ret) {
537                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_prepare failed. (%s)", tts_core_covert_error_code(ret));
538                 return ret;
539         }
540
541         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
542         return TTS_ERROR_NONE;
543 }
544
545 int tts_prepare_sync(tts_h tts)
546 {
547         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
548
549         tts_client_s* client = tts_client_get(tts);
550         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
551
552         tts_state_e current_state = tts_client_get_current_state(client);
553         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
554
555         SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS synchronously");
556         int ret = tts_core_prepare_sync(client);
557         if (TTS_ERROR_NONE != ret) {
558                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_prepare_sync failed. (%s)", tts_core_covert_error_code(ret));
559                 return ret;
560         }
561
562         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
563         return TTS_ERROR_NONE;
564 }
565
566 int tts_unprepare(tts_h tts)
567 {
568         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
569
570         tts_client_s* client = tts_client_get(tts);
571         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
572
573         tts_state_e current_state = tts_client_get_current_state(client);
574         RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
575
576         SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
577         int ret = tts_core_unprepare(client);
578         if (0 != ret) {
579                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_unprepare is failed(%s)", tts_core_covert_error_code(ret));
580                 return ret;
581         }
582
583         tts_core_notify_state_changed(client, TTS_STATE_CREATED);
584
585         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
586         return TTS_ERROR_NONE;
587 }
588
589 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
590 {
591         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
592
593         SLOG(LOG_INFO, TAG_TTSC, "@@@ Foreach supported voices");
594
595         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
596
597         tts_client_s* client = tts_client_get(tts);
598         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
599
600         int ret = 0;
601         char* current_engine = NULL;
602         ret = tts_config_mgr_get_engine(&current_engine);
603         if (0 != ret || NULL == current_engine) {
604                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
605                 return __tts_convert_config_error_code(ret);
606         }
607
608         ret = tts_core_foreach_supported_voices(client, current_engine, callback, user_data);
609         free(current_engine);
610
611         if (0 != ret) {
612                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
613                 return ret;
614         }
615
616         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
617         return TTS_ERROR_NONE;
618 }
619
620 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
621 {
622         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
623
624         SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
625
626         RETVM_IF(NULL == lang || NULL == vctype, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid");
627
628         tts_client_s* client = tts_client_get(tts);
629         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
630
631         /* Request call remote method */
632         int ret = 0;
633         ret = tts_config_mgr_get_voice(lang, vctype);
634         if (0 != ret) {
635                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
636                 return __tts_convert_config_error_code(ret);
637         }
638
639         SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
640         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
641         return TTS_ERROR_NONE;
642 }
643
644 int tts_get_max_text_size(tts_h tts, unsigned int* size)
645 {
646         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
647
648         RETVM_IF(NULL == size, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get max text count : Input parameter is null");
649
650         tts_client_s* client = tts_client_get(tts);
651         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
652
653         tts_state_e current_state = tts_client_get_current_state(client);
654         RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
655
656         if (0 != tts_config_mgr_get_max_text_size(size)) {
657                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
658                 return TTS_ERROR_OPERATION_FAILED;
659         }
660
661         SLOG(LOG_INFO, TAG_TTSC, "Get max text size : %d byte", *size);
662         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
663         return TTS_ERROR_NONE;
664 }
665
666 int tts_get_state(tts_h tts, tts_state_e* state)
667 {
668         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
669
670         RETVM_IF(NULL == state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get state : Input parameter is null");
671
672         tts_client_s* client = tts_client_get(tts);
673         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
674
675         tts_state_e current_state = tts_client_get_current_state(client);
676         switch (current_state) {
677         case TTS_STATE_CREATED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Created'"); break;
678         case TTS_STATE_READY:   SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Ready'");   break;
679         case TTS_STATE_PLAYING: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Playing'"); break;
680         case TTS_STATE_PAUSED:  SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Paused'");  break;
681         default:
682                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
683                 return TTS_ERROR_INVALID_PARAMETER;
684         }
685
686         *state = current_state;
687         return TTS_ERROR_NONE;
688 }
689
690 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
691 {
692         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
693
694         RETVM_IF(NULL == min || NULL == normal || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
695
696         tts_client_s* client = tts_client_get(tts);
697         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
698
699         *min = TTS_SPEED_MIN;
700         *normal = TTS_SPEED_NORMAL;
701         *max = TTS_SPEED_MAX;
702
703         return TTS_ERROR_NONE;
704 }
705
706 int tts_get_error_message(tts_h tts, char** err_msg)
707 {
708         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
709
710         RETVM_IF(NULL == err_msg, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
711
712         tts_client_s* client = tts_client_get(tts);
713         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
714
715         const char* error_message = tts_client_get_error_message(client);
716         if (NULL != error_message) {
717                 *err_msg = strdup(error_message);
718                 SLOG(LOG_DEBUG, TAG_TTSC, "Error msg (%s)", error_message);
719         } else {
720                 *err_msg = NULL;
721                 SLOG(LOG_DEBUG, TAG_TTSC, "Error msg (NULL)");
722         }
723
724         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
725         return TTS_ERROR_NONE;
726 }
727
728 int tts_check_screen_reader_on(tts_h tts, bool* is_on)
729 {
730         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
731
732         RETVM_IF(NULL == is_on, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
733
734         tts_client_s* client = tts_client_get(tts);
735         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
736
737         if (false == tts_core_check_screen_reader(client)) {
738                 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is not available");
739                 *is_on = false;
740         } else {
741                 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Screen reader option is available");
742                 *is_on = true;
743         }
744
745         return TTS_ERROR_NONE;
746 }
747
748 int tts_get_service_state(tts_h tts, tts_service_state_e* service_state)
749 {
750         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
751
752         RETVM_IF(NULL == service_state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get service state : Input parameter is null");
753
754         tts_client_s* client = tts_client_get(tts);
755         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
756
757         tts_state_e current_state = tts_client_get_current_state(client);
758         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
759
760         int ret = tts_core_get_service_state(client, service_state);
761         if (TTS_ERROR_NONE != ret) {
762                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get service state. ret(%d/%s)", ret, get_error_message(ret));
763                 return ret;
764         }
765
766         return TTS_ERROR_NONE;
767 }
768
769 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
770 {
771         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
772
773         SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
774
775         RETVM_IF(TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed, TTS_ERROR_INVALID_PARAMETER, "[ERROR] speed value(%d) is invalid.", speed);
776         RETVM_IF(voice_type < 0, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Voice type should not be negative(%d)", voice_type);
777         RETVM_IF(NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
778         RETVM_IF(false == tts_core_is_valid_text(text), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input text is invalid");
779
780         tts_client_s* client = tts_client_get(tts);
781         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
782
783         tts_state_e current_state = tts_client_get_current_state(client);
784         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
785
786         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
787         RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
788
789         int ret = tts_core_add_text(client, text, language, voice_type, speed, utt_id);
790         if (TTS_ERROR_NONE != ret) {
791                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add text. ret(%s)", tts_core_covert_error_code(ret));
792                 return ret;
793         }
794
795         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
796         return TTS_ERROR_NONE;
797 }
798
799 //LCOV_EXCL_START
800 static void __tts_play_async(void *data)
801 {
802         tts_h tts = (tts_h)data;
803
804         tts_client_s* client = tts_client_get(tts);
805         RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
806
807         int ret = tts_core_play(client);
808         if (0 != ret) {
809                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", tts_core_covert_error_code(ret));
810                 tts_core_notify_error_async(client, ret, -1, NULL);
811                 return;
812         }
813
814         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
815         return;
816 }
817
818 int tts_play_async(tts_h tts)
819 {
820         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
821
822         SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play asynchronously tts");
823
824         tts_client_s* client = tts_client_get(tts);
825         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
826
827         tts_state_e current_state = tts_client_get_current_state(client);
828         RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
829
830         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
831         RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
832
833         ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
834
835         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
836         return TTS_ERROR_NONE;
837 }
838 //LCOV_EXCL_STOP
839
840 int tts_play(tts_h tts)
841 {
842         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
843
844         SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
845
846         tts_client_s* client = tts_client_get(tts);
847         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
848
849         tts_state_e current_state = tts_client_get_current_state(client);
850         RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
851
852         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
853         RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
854
855         int ret = tts_core_play(client);
856         if (TTS_ERROR_NONE != ret) {
857                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request play. ret(%s)", tts_core_covert_error_code(ret));
858                 return ret;
859         }
860
861         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
862         return TTS_ERROR_NONE;
863 }
864
865 //LCOV_EXCL_START
866 static void __tts_stop_async(void *data)
867 {
868         tts_h tts = (tts_h)data;
869
870         tts_client_s* client = tts_client_get(tts);
871         RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
872
873         int ret = tts_core_stop(client);
874         if (0 != ret) {
875                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", tts_core_covert_error_code(ret));
876                 tts_core_notify_error_async(client, ret, -1, NULL);
877                 return;
878         }
879
880         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
881         return;
882 }
883
884 int tts_stop_aync(tts_h tts)
885 {
886         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
887
888         SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop asynchronously tts");
889
890         tts_client_s* client = tts_client_get(tts);
891         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
892
893         tts_state_e current_state = tts_client_get_current_state(client);
894         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
895
896         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
897
898         ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
899
900         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
901         return TTS_ERROR_NONE;
902 }
903 //LCOV_EXCL_STOP
904
905 int tts_stop(tts_h tts)
906 {
907         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
908
909         SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
910
911         tts_client_s* client = tts_client_get(tts);
912         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
913
914         tts_state_e current_state = tts_client_get_current_state(client);
915         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
916
917         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
918
919         int ret = tts_core_stop(client);
920         if (TTS_ERROR_NONE != ret) {
921                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop. ret(%s)", tts_core_covert_error_code(ret));
922                 return ret;
923         }
924
925         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
926         return TTS_ERROR_NONE;
927 }
928
929 //LCOV_EXCL_START
930 static void __tts_pause_async(void *data)
931 {
932         tts_h tts = (tts_h)data;
933
934         tts_client_s* client = tts_client_get(tts);
935         RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
936
937         int ret = tts_core_pause(client);
938         if (0 != ret) {
939                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", tts_core_covert_error_code(ret));
940                 tts_core_notify_error_async(client, ret, -1, NULL);
941                 return;
942         }
943
944         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
945         return;
946 }
947
948 int tts_pause_async(tts_h tts)
949 {
950         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
951
952         SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause asynchronously tts");
953
954         tts_client_s* client = tts_client_get(tts);
955         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
956
957         tts_state_e current_state = tts_client_get_current_state(client);
958         RETVM_IF(TTS_STATE_PLAYING != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
959
960         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
961
962         ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
963
964         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
965         return TTS_ERROR_NONE;
966 }
967 //LCOV_EXCL_STOP
968 int tts_pause(tts_h tts)
969 {
970         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
971
972         SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
973
974         tts_client_s* client = tts_client_get(tts);
975         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
976
977         tts_state_e current_state = tts_client_get_current_state(client);
978         RETVM_IF(TTS_STATE_PLAYING != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
979
980         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
981
982         int ret = tts_core_pause(client);
983         if (TTS_ERROR_NONE != ret) {
984                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request pause. ret(%s)", tts_core_covert_error_code(ret));
985                 return ret;
986         }
987
988         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
989         return TTS_ERROR_NONE;
990 }
991
992 int tts_set_private_data(tts_h tts, const char* key, const char* data)
993 {
994         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
995
996         SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
997
998         RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
999
1000         tts_client_s* client = tts_client_get(tts);
1001         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1002
1003         tts_state_e current_state = tts_client_get_current_state(client);
1004         RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1005
1006         if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
1007                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
1008                 return TTS_ERROR_INVALID_PARAMETER;
1009         }
1010
1011         int ret = tts_core_set_private_data(client, key, data);
1012         if (TTS_ERROR_NONE != ret) {
1013                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request set private data. ret(%s)", tts_core_covert_error_code(ret));
1014                 return ret;
1015         }
1016
1017         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1018         return 0;
1019 }
1020
1021 int tts_get_private_data(tts_h tts, const char* key, char** data)
1022 {
1023         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1024
1025         SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
1026
1027         RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
1028
1029         tts_client_s* client = tts_client_get(tts);
1030         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1031
1032         tts_state_e current_state = tts_client_get_current_state(client);
1033         RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1034
1035         int ret = tts_core_get_private_data(client, key, data);
1036         if (TTS_ERROR_NONE != ret) {
1037                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request get private data. ret(%s)", tts_core_covert_error_code(ret));
1038                 return ret;
1039         }
1040
1041         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1042         return 0;
1043 }
1044
1045 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
1046 {
1047         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1048
1049         tts_client_s* client = tts_client_get(tts);
1050         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1051
1052         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set state changed cb : Input parameter is null");
1053
1054         tts_state_e current_state = tts_client_get_current_state(client);
1055         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1056
1057         tts_client_set_state_changed_cb(client, callback, user_data);
1058
1059         SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
1060         return 0;
1061 }
1062
1063 int tts_unset_state_changed_cb(tts_h tts)
1064 {
1065         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1066
1067         tts_client_s* client = tts_client_get(tts);
1068         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1069
1070         tts_state_e current_state = tts_client_get_current_state(client);
1071         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1072
1073         tts_client_set_state_changed_cb(client, NULL, NULL);
1074
1075         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
1076         return 0;
1077 }
1078
1079 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
1080 {
1081         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1082
1083         tts_client_s* client = tts_client_get(tts);
1084         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1085
1086         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt started cb : Input parameter is null");
1087
1088         tts_state_e current_state = tts_client_get_current_state(client);
1089         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1090
1091         tts_client_set_utterance_started_cb(client, callback, user_data);
1092
1093         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
1094
1095         return 0;
1096 }
1097
1098 int tts_unset_utterance_started_cb(tts_h tts)
1099 {
1100         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1101
1102         tts_client_s* client = tts_client_get(tts);
1103         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1104
1105         tts_state_e current_state = tts_client_get_current_state(client);
1106         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1107
1108         tts_client_set_utterance_started_cb(client, NULL, NULL);
1109
1110         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
1111
1112         return 0;
1113 }
1114
1115 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
1116 {
1117         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1118
1119         tts_client_s* client = tts_client_get(tts);
1120         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1121
1122         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt completed cb : Input parameter is null");
1123
1124         tts_state_e current_state = tts_client_get_current_state(client);
1125         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1126
1127         tts_client_set_utterance_completed_cb(client, callback, user_data);
1128
1129         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
1130
1131         return 0;
1132 }
1133
1134 int tts_unset_utterance_completed_cb(tts_h tts)
1135 {
1136         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1137
1138         tts_client_s* client = tts_client_get(tts);
1139         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1140
1141         tts_state_e current_state = tts_client_get_current_state(client);
1142         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1143
1144         tts_client_set_utterance_completed_cb(client, NULL, NULL);
1145
1146         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
1147         return 0;
1148 }
1149
1150 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
1151 {
1152         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1153
1154         tts_client_s* client = tts_client_get(tts);
1155         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1156
1157         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set error cb : Input parameter is null");
1158
1159         tts_state_e current_state = tts_client_get_current_state(client);
1160         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1161
1162         tts_client_set_error_cb(client, callback, user_data);
1163
1164         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
1165
1166         return 0;
1167 }
1168
1169 int tts_unset_error_cb(tts_h tts)
1170 {
1171         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1172
1173         tts_client_s* client = tts_client_get(tts);
1174         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1175
1176         tts_state_e current_state = tts_client_get_current_state(client);
1177         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1178
1179         tts_client_set_error_cb(client, NULL, NULL);
1180
1181         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
1182
1183         return 0;
1184 }
1185
1186 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
1187 {
1188         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1189
1190         tts_client_s* client = tts_client_get(tts);
1191         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1192
1193         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set default voice changed cb : Input parameter is null");
1194
1195         tts_state_e current_state = tts_client_get_current_state(client);
1196         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1197
1198         tts_client_set_default_voice_changed_cb(client, callback, user_data);
1199
1200         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
1201
1202         return 0;
1203 }
1204
1205 int tts_unset_default_voice_changed_cb(tts_h tts)
1206 {
1207         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1208
1209         tts_client_s* client = tts_client_get(tts);
1210         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1211
1212         tts_state_e current_state = tts_client_get_current_state(client);
1213         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1214
1215         tts_client_set_default_voice_changed_cb(client, NULL, NULL);
1216
1217         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
1218
1219         return 0;
1220 }
1221
1222 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
1223 {
1224         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1225
1226         tts_client_s* client = tts_client_get(tts);
1227         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1228
1229         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set engine changed cb : Input parameter is null");
1230
1231         tts_state_e current_state = tts_client_get_current_state(client);
1232         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1233
1234         tts_client_set_engine_changed_cb(client, callback, user_data);
1235
1236         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
1237
1238         return 0;
1239 }
1240
1241 int tts_unset_engine_changed_cb(tts_h tts)
1242 {
1243         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1244
1245         tts_client_s* client = tts_client_get(tts);
1246         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1247
1248         tts_state_e current_state = tts_client_get_current_state(client);
1249         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1250
1251         tts_client_set_engine_changed_cb(client, NULL, NULL);
1252
1253         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
1254
1255         return 0;
1256 }
1257
1258 int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb callback, void* user_data)
1259 {
1260         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1261
1262         tts_client_s* client = tts_client_get(tts);
1263         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1264
1265         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set screen reader changed cb : Input parameter is null");
1266
1267         tts_state_e current_state = tts_client_get_current_state(client);
1268         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1269
1270         tts_client_set_screen_reader_changed_cb(client, callback, user_data);
1271
1272         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set screen reader changed cb");
1273
1274         return 0;
1275 }
1276
1277 int tts_unset_screen_reader_changed_cb(tts_h tts)
1278 {
1279         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1280
1281         tts_client_s* client = tts_client_get(tts);
1282         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1283
1284         tts_state_e current_state = tts_client_get_current_state(client);
1285         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1286
1287         tts_client_set_screen_reader_changed_cb(client, NULL, NULL);
1288
1289         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset screen reader changed cb");
1290
1291         return 0;
1292 }
1293
1294 int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
1295 {
1296         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1297
1298         SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
1299
1300         tts_client_s* client = tts_client_get(tts);
1301         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1302
1303         tts_state_e current_state = tts_client_get_current_state(client);
1304         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1305
1306         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1307
1308         int ret = tts_core_add_pcm(client, event, data, data_size, audio_type, rate);
1309         if (TTS_ERROR_NONE != ret) {
1310                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add_pcm. ret(%s)", tts_core_covert_error_code(ret));
1311                 return ret;
1312         }
1313
1314         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1315         return TTS_ERROR_NONE;
1316 }
1317
1318 int tts_play_pcm(tts_h tts)
1319 {
1320         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1321
1322         SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
1323
1324         tts_client_s* client = tts_client_get(tts);
1325         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1326
1327         tts_state_e current_state = tts_client_get_current_state(client);
1328         RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1329
1330         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1331
1332         int ret = tts_core_play_pcm(client);
1333         if (TTS_ERROR_NONE != ret) {
1334                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request play_pcm. ret(%s)", tts_core_covert_error_code(ret));
1335                 return ret;
1336         }
1337
1338         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1339         return TTS_ERROR_NONE;
1340 }
1341
1342 int tts_stop_pcm(tts_h tts)
1343 {
1344         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1345
1346         SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
1347
1348         tts_client_s* client = tts_client_get(tts);
1349         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1350
1351         tts_state_e current_state = tts_client_get_current_state(client);
1352         RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1353
1354         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1355
1356         int ret = tts_core_stop_pcm(client);
1357         if (TTS_ERROR_NONE != ret) {
1358                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop_pcm. ret(%s)", tts_core_covert_error_code(ret));
1359                 return ret;
1360         }
1361
1362         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1363         return TTS_ERROR_NONE;
1364 }
1365
1366 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
1367 {
1368         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1369
1370         SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
1371
1372         RETVM_IF(NULL == text_repeat || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null.");
1373
1374         tts_client_s* client = tts_client_get(tts);
1375         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1376
1377         tts_state_e current_state = tts_client_get_current_state(client);
1378         RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1379
1380         RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1381
1382         if (true == client->credential_needed && NULL == client->credential) {
1383                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1384                 return TTS_ERROR_PERMISSION_DENIED;
1385         }
1386
1387         *text_repeat = NULL;
1388         *utt_id = -1;
1389
1390         int ret = tts_core_repeat(client, text_repeat, utt_id);
1391         if (TTS_ERROR_NONE != ret) {
1392                 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop. ret(%s)", tts_core_covert_error_code(ret));
1393                 return ret;
1394         }
1395
1396         SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1397         return TTS_ERROR_NONE;
1398 }
1399
1400 int tts_set_service_state_changed_cb(tts_h tts, tts_service_state_changed_cb callback, void* user_data)
1401 {
1402         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1403
1404         tts_client_s* client = tts_client_get(tts);
1405         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1406         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set service state changed cb : Input parameter is null");
1407
1408         tts_state_e current_state = tts_client_get_current_state(client);
1409         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1410
1411         tts_client_set_service_state_changed_cb(client, callback, user_data);
1412
1413         SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set service state changed cb");
1414         return TTS_ERROR_NONE;
1415 }
1416
1417 int tts_unset_service_state_changed_cb(tts_h tts)
1418 {
1419         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1420
1421         tts_client_s* client = tts_client_get(tts);
1422         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1423
1424         tts_state_e current_state = tts_client_get_current_state(client);
1425         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1426
1427         tts_client_set_service_state_changed_cb(client, NULL, NULL);
1428
1429         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset service state changed cb");
1430         return TTS_ERROR_NONE;
1431 }
1432
1433 int tts_set_synthesized_pcm_cb(tts_h tts, tts_synthesized_pcm_cb callback, void* user_data)
1434 {
1435         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1436
1437         tts_client_s* client = tts_client_get(tts);
1438         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1439         RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set synthesized pcm cb : Input parameter is null");
1440
1441         tts_state_e current_state = tts_client_get_current_state(client);
1442         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1443
1444         tts_client_set_synthesized_pcm_cb(client, callback, user_data);
1445
1446         SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set synthesized pcm cb");
1447         return TTS_ERROR_NONE;
1448 }
1449
1450 int tts_unset_synthesized_pcm_cb(tts_h tts)
1451 {
1452         RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1453
1454         tts_client_s* client = tts_client_get(tts);
1455         RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1456
1457         tts_state_e current_state = tts_client_get_current_state(client);
1458         RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1459
1460         tts_client_set_synthesized_pcm_cb(client, NULL, NULL);
1461
1462         SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset synthesized pcm cb");
1463         return TTS_ERROR_NONE;
1464 }