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.
14 #include <app_manager.h>
17 #include <system_info.h>
19 #include <package-manager.h>
23 #include "tts_client.h"
24 #include "tts_config_mgr.h"
30 #include "tts_internal.h"
32 static int g_feature_enabled = -1;
35 static int __tts_get_feature_enabled()
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");
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;
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;
52 g_feature_enabled = 1;
53 return TTS_ERROR_NONE;
56 // TODO: move into tts_core to make common function
58 static int __tts_convert_config_error_code(tts_config_error_e code)
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;
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)
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);
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");
85 if (g_list_length(client_list) > 0) {
86 /* Get a first item */
87 iter = g_list_first(client_list);
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);
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);
99 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid (%p)", client);
103 iter = g_list_next(iter);
107 g_list_free(client_list);
112 static Eina_Bool __reconnect_by_engine_changed(void* data)
114 tts_h tts = (tts_h)data;
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);
122 tts_state_e current_state = tts_client_get_current_state(client);
123 if (TTS_STATE_READY != current_state) {
128 // TODO: change to tts_core function
129 int ret = tts_unprepare(tts);
131 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
133 ret = tts_prepare(tts);
135 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
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)
143 tts_h tts = (tts_h)user_data;
145 tts_client_s* client = tts_client_get(tts);
146 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
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");
153 /* When the default engine is changed, please unload the old engine and load the new one. */
156 tts_state_e current_state = tts_client_get_current_state(client);
157 if (TTS_STATE_PLAYING == current_state || TTS_STATE_PAUSED == current_state) {
160 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
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);
168 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
170 ret = tts_prepare(tts);
172 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
176 /* call callback function */
177 tts_core_notify_engine_changed(client, engine_id, language, voice_type, need_credential);
182 static void __tts_config_screen_reader_changed_cb(bool value, void* user_data)
184 tts_h tts = (tts_h)user_data;
186 tts_client_s* client = tts_client_get(tts);
187 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
189 SLOG(LOG_DEBUG, TAG_TTSC, "Screen reader is changed. current status (%d)", value);
191 /* call callback function */
192 tts_core_notify_screen_reader_changed(client, value);
195 static int __initialize_tts_config(unsigned int uid, tts_h new_tts)
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);
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);
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);
217 return TTS_ERROR_NONE;
220 int tts_create(tts_h* tts)
222 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
224 SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
226 RETVM_IF(NULL == tts, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
228 bool is_first_client = false;
229 if (0 == tts_client_get_size()) {
230 is_first_client = true;
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;
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;
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);
249 if (false == tts_ipc_is_method_set()) {
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);
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);
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;
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);
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;
291 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
292 return TTS_ERROR_NONE;
295 static int destroy_tts_handle(tts_h tts)
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);
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);
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;
310 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
312 // TODO: move into tts_client
313 if (client->hello_timer) {
314 ecore_timer_del(client->hello_timer);
315 client->hello_timer = NULL;
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");
325 tts_client_set_current_state(client, TTS_STATE_CREATED);
327 case TTS_STATE_CREATED: {
328 /* Unset registered callbacks */
329 tts_client_unset_all_cb(client);
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++) {
336 SLOG(LOG_WARN, TAG_TTSC, "[WARNNING] Thread is blocked, %d", thread_count);
339 thread_count = ecore_thread_active_get();
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;
348 tts_client_destroy(tts);
353 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
354 return TTS_ERROR_INVALID_PARAMETER;
358 unsigned int num_of_client = tts_client_get_size();
359 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%u)", num_of_client);
361 if (0 == num_of_client) {
362 if (0 != tts_core_deinitialize()) {
363 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to deinitialize core");
367 return TTS_ERROR_NONE;
370 static void *destroy_tts_handle_on_main_thread(void* data)
372 SLOG(LOG_INFO, TAG_TTSC, "Destroy on main thread synchronously");
373 tts_h tts = (tts_h)data;
375 int ret = destroy_tts_handle(tts);
376 intptr_t p_ret = (intptr_t)ret;
378 return (void *)p_ret;
381 int tts_destroy(tts_h tts)
383 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
384 SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
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));
389 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
393 int tts_set_mode(tts_h tts, tts_mode_e mode)
395 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
397 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
399 RETVM_IF(TTS_MODE_DEFAULT > mode || TTS_MODE_INTERRUPT < mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] mode is not valid : %d", mode);
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);
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);
407 tts_client_set_mode(client, mode);
409 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
410 return TTS_ERROR_NONE;
413 int tts_get_mode(tts_h tts, tts_mode_e* mode)
415 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
417 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
419 RETVM_IF(NULL == mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter(mode) is NULL");
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);
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);
427 *mode = tts_client_get_mode(client);
429 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
430 return TTS_ERROR_NONE;
433 int tts_set_playing_mode(tts_h tts, tts_playing_mode_e mode)
435 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
437 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS playing mode(%d)", mode);
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);
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);
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);
447 tts_client_set_playing_mode(client, mode);
449 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
450 return TTS_ERROR_NONE;
453 int tts_set_credential(tts_h tts, const char* credential)
455 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
457 RETVM_IF(NULL == credential, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
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);
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);
465 tts_client_set_credential_key(client, credential);
467 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
468 return TTS_ERROR_NONE;
471 int tts_set_server_tts(tts_h tts, const char* credential)
473 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
482 // TODO: fix name more clear and move into tts_client
483 client->internal = true;
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;
494 key = "DisableServerTTS";
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);;
506 return TTS_ERROR_OPERATION_FAILED;
509 ret = tts_core_set_private_data(client, key, appid);
511 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
520 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
521 return TTS_ERROR_NONE;
524 int tts_prepare(tts_h tts)
526 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
534 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
535 int ret = tts_core_prepare(client);
537 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_prepare failed. (%s)", tts_core_covert_error_code(ret));
541 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
542 return TTS_ERROR_NONE;
545 int tts_prepare_sync(tts_h tts)
547 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
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));
562 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
563 return TTS_ERROR_NONE;
566 int tts_unprepare(tts_h tts)
568 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
576 SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
577 int ret = tts_core_unprepare(client);
579 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_unprepare is failed(%s)", tts_core_covert_error_code(ret));
583 tts_core_notify_state_changed(client, TTS_STATE_CREATED);
585 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
586 return TTS_ERROR_NONE;
589 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
591 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
593 SLOG(LOG_INFO, TAG_TTSC, "@@@ Foreach supported voices");
595 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
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);
601 char* current_engine = NULL;
602 ret = tts_config_mgr_get_engine(¤t_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);
608 ret = tts_core_foreach_supported_voices(client, current_engine, callback, user_data);
609 free(current_engine);
612 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
616 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
617 return TTS_ERROR_NONE;
620 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
622 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
624 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
626 RETVM_IF(NULL == lang || NULL == vctype, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid");
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);
631 /* Request call remote method */
633 ret = tts_config_mgr_get_voice(lang, vctype);
635 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
636 return __tts_convert_config_error_code(ret);
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;
644 int tts_get_max_text_size(tts_h tts, unsigned int* size)
646 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
648 RETVM_IF(NULL == size, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get max text count : Input parameter is null");
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);
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);
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;
661 SLOG(LOG_INFO, TAG_TTSC, "Get max text size : %d byte", *size);
662 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
663 return TTS_ERROR_NONE;
666 int tts_get_state(tts_h tts, tts_state_e* state)
668 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
670 RETVM_IF(NULL == state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get state : Input parameter is null");
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);
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;
682 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
683 return TTS_ERROR_INVALID_PARAMETER;
686 *state = current_state;
687 return TTS_ERROR_NONE;
690 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
692 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
694 RETVM_IF(NULL == min || NULL == normal || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
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);
699 *min = TTS_SPEED_MIN;
700 *normal = TTS_SPEED_NORMAL;
701 *max = TTS_SPEED_MAX;
703 return TTS_ERROR_NONE;
706 int tts_get_error_message(tts_h tts, char** err_msg)
708 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
710 RETVM_IF(NULL == err_msg, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
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);
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);
721 SLOG(LOG_DEBUG, TAG_TTSC, "Error msg (NULL)");
724 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
725 return TTS_ERROR_NONE;
728 int tts_check_screen_reader_on(tts_h tts, bool* is_on)
730 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
732 RETVM_IF(NULL == is_on, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
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);
737 if (false == tts_core_check_screen_reader(client)) {
738 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is not available");
741 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Screen reader option is available");
745 return TTS_ERROR_NONE;
748 int tts_get_service_state(tts_h tts, tts_service_state_e* service_state)
750 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
752 RETVM_IF(NULL == service_state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get service state : Input parameter is null");
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);
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);
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));
766 return TTS_ERROR_NONE;
769 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
771 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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");
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);
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);
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");
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));
795 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
796 return TTS_ERROR_NONE;
800 static void __tts_play_async(void *data)
802 tts_h tts = (tts_h)data;
804 tts_client_s* client = tts_client_get(tts);
805 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
807 int ret = tts_core_play(client);
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);
814 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
818 int tts_play_async(tts_h tts)
820 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
822 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play asynchronously tts");
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);
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);
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");
833 ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
835 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
836 return TTS_ERROR_NONE;
840 int tts_play(tts_h tts)
842 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
844 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
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);
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);
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");
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));
861 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
862 return TTS_ERROR_NONE;
866 static void __tts_stop_async(void *data)
868 tts_h tts = (tts_h)data;
870 tts_client_s* client = tts_client_get(tts);
871 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
873 int ret = tts_core_stop(client);
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);
880 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
884 int tts_stop_aync(tts_h tts)
886 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
888 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop asynchronously tts");
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);
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);
896 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
898 ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
900 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
901 return TTS_ERROR_NONE;
905 int tts_stop(tts_h tts)
907 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
909 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
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);
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);
917 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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));
925 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
926 return TTS_ERROR_NONE;
930 static void __tts_pause_async(void *data)
932 tts_h tts = (tts_h)data;
934 tts_client_s* client = tts_client_get(tts);
935 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
937 int ret = tts_core_pause(client);
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);
944 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
948 int tts_pause_async(tts_h tts)
950 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
952 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause asynchronously tts");
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);
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);
960 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
962 ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
964 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
965 return TTS_ERROR_NONE;
968 int tts_pause(tts_h tts)
970 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
972 SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
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);
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);
980 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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));
988 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
989 return TTS_ERROR_NONE;
992 int tts_set_private_data(tts_h tts, const char* key, const char* data)
994 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
996 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
998 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
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);
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);
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;
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));
1017 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1021 int tts_get_private_data(tts_h tts, const char* key, char** data)
1023 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1025 SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
1027 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
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);
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);
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));
1041 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1045 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
1047 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1052 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set state changed cb : Input parameter is null");
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);
1057 tts_client_set_state_changed_cb(client, callback, user_data);
1059 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
1063 int tts_unset_state_changed_cb(tts_h tts)
1065 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1073 tts_client_set_state_changed_cb(client, NULL, NULL);
1075 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
1079 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
1081 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1086 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt started cb : Input parameter is null");
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);
1091 tts_client_set_utterance_started_cb(client, callback, user_data);
1093 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
1098 int tts_unset_utterance_started_cb(tts_h tts)
1100 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1108 tts_client_set_utterance_started_cb(client, NULL, NULL);
1110 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
1115 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
1117 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1122 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt completed cb : Input parameter is null");
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);
1127 tts_client_set_utterance_completed_cb(client, callback, user_data);
1129 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
1134 int tts_unset_utterance_completed_cb(tts_h tts)
1136 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1144 tts_client_set_utterance_completed_cb(client, NULL, NULL);
1146 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
1150 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
1152 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1157 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set error cb : Input parameter is null");
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);
1162 tts_client_set_error_cb(client, callback, user_data);
1164 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
1169 int tts_unset_error_cb(tts_h tts)
1171 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1179 tts_client_set_error_cb(client, NULL, NULL);
1181 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
1186 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
1188 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1193 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set default voice changed cb : Input parameter is null");
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);
1198 tts_client_set_default_voice_changed_cb(client, callback, user_data);
1200 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
1205 int tts_unset_default_voice_changed_cb(tts_h tts)
1207 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1215 tts_client_set_default_voice_changed_cb(client, NULL, NULL);
1217 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
1222 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
1224 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1229 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set engine changed cb : Input parameter is null");
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);
1234 tts_client_set_engine_changed_cb(client, callback, user_data);
1236 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
1241 int tts_unset_engine_changed_cb(tts_h tts)
1243 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1251 tts_client_set_engine_changed_cb(client, NULL, NULL);
1253 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
1258 int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb callback, void* user_data)
1260 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
1265 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set screen reader changed cb : Input parameter is null");
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);
1270 tts_client_set_screen_reader_changed_cb(client, callback, user_data);
1272 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set screen reader changed cb");
1277 int tts_unset_screen_reader_changed_cb(tts_h tts)
1279 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1287 tts_client_set_screen_reader_changed_cb(client, NULL, NULL);
1289 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset screen reader changed cb");
1294 int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
1296 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1298 SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
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);
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);
1306 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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));
1314 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1315 return TTS_ERROR_NONE;
1318 int tts_play_pcm(tts_h tts)
1320 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1322 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
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);
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);
1330 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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));
1338 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1339 return TTS_ERROR_NONE;
1342 int tts_stop_pcm(tts_h tts)
1344 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1346 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
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);
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);
1354 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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));
1362 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1363 return TTS_ERROR_NONE;
1366 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
1368 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1370 SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
1372 RETVM_IF(NULL == text_repeat || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null.");
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);
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);
1380 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
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;
1387 *text_repeat = NULL;
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));
1396 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1397 return TTS_ERROR_NONE;
1400 int tts_set_service_state_changed_cb(tts_h tts, tts_service_state_changed_cb callback, void* user_data)
1402 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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");
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);
1411 tts_client_set_service_state_changed_cb(client, callback, user_data);
1413 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set service state changed cb");
1414 return TTS_ERROR_NONE;
1417 int tts_unset_service_state_changed_cb(tts_h tts)
1419 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1427 tts_client_set_service_state_changed_cb(client, NULL, NULL);
1429 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset service state changed cb");
1430 return TTS_ERROR_NONE;
1433 int tts_set_synthesized_pcm_cb(tts_h tts, tts_synthesized_pcm_cb callback, void* user_data)
1435 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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");
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);
1444 tts_client_set_synthesized_pcm_cb(client, callback, user_data);
1446 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set synthesized pcm cb");
1447 return TTS_ERROR_NONE;
1450 int tts_unset_synthesized_pcm_cb(tts_h tts)
1452 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
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);
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);
1460 tts_client_set_synthesized_pcm_cb(client, NULL, NULL);
1462 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset synthesized pcm cb");
1463 return TTS_ERROR_NONE;