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