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>
19 #include <sys/types.h>
21 #include <system_info.h>
23 #include <package-manager.h>
26 #include "tts_client.h"
27 #include "tts_config_mgr.h"
31 #include "tts_internal.h"
33 static bool g_screen_reader;
35 static int g_feature_enabled = -1;
37 static bool g_err_callback_status = false;
39 static int g_max_text_size = -1;
41 static Ecore_Timer* g_check_state_timer = NULL;
45 static char* g_language = NULL;
47 static int g_voice_type = -1;
49 static int g_speed = -1;
51 /* for checking engine update */
52 static pkgmgr_client* g_pkgmgr = NULL;
53 static char* g_engine_name = NULL;
54 static int g_engine_update_status = 0;
56 /* Function definition */
57 static Eina_Bool __tts_notify_state_changed(void *data);
58 static Eina_Bool __tts_notify_error(void *data);
59 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg);
67 static int __tts_get_feature_enabled()
69 if (0 == g_feature_enabled) {
70 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
71 return TTS_ERROR_NOT_SUPPORTED;
72 } else if (-1 == g_feature_enabled) {
73 bool tts_supported = false;
74 if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
75 if (false == tts_supported) {
76 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
77 g_feature_enabled = 0;
78 return TTS_ERROR_NOT_SUPPORTED;
81 g_feature_enabled = 1;
83 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
84 return TTS_ERROR_NOT_SUPPORTED;
91 static const char* __tts_get_error_code(tts_error_e err)
94 case TTS_ERROR_NONE: return "TTS_ERROR_NONE";
95 case TTS_ERROR_OUT_OF_MEMORY: return "TTS_ERROR_OUT_OF_MEMORY";
96 case TTS_ERROR_IO_ERROR: return "TTS_ERROR_IO_ERROR";
97 case TTS_ERROR_INVALID_PARAMETER: return "TTS_ERROR_INVALID_PARAMETER";
98 case TTS_ERROR_OUT_OF_NETWORK: return "TTS_ERROR_OUT_OF_NETWORK";
99 case TTS_ERROR_TIMED_OUT: return "TTS_ERROR_TIMED_OUT";
100 case TTS_ERROR_PERMISSION_DENIED: return "TTS_ERROR_PERMISSION_DENIED";
101 case TTS_ERROR_NOT_SUPPORTED: return "TTS_ERROR_NOT_SUPPORTED";
102 case TTS_ERROR_INVALID_STATE: return "TTS_ERROR_INVALID_STATE";
103 case TTS_ERROR_INVALID_VOICE: return "TTS_ERROR_INVALID_VOICE";
104 case TTS_ERROR_ENGINE_NOT_FOUND: return "TTS_ERROR_ENGINE_NOT_FOUND";
105 case TTS_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED";
106 case TTS_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
107 case TTS_ERROR_NOT_SUPPORTED_FEATURE: return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
108 case TTS_ERROR_SERVICE_RESET: return "TTS_ERROR_SERVICE_RESET";
110 return "Invalid error code";
115 static int __tts_convert_config_error_code(tts_config_error_e code)
117 if (code == TTS_CONFIG_ERROR_NONE) return TTS_ERROR_NONE;
118 if (code == TTS_CONFIG_ERROR_OUT_OF_MEMORY) return TTS_ERROR_OUT_OF_MEMORY;
119 if (code == TTS_CONFIG_ERROR_IO_ERROR) return TTS_ERROR_IO_ERROR;
120 if (code == TTS_CONFIG_ERROR_INVALID_PARAMETER) return TTS_ERROR_INVALID_PARAMETER;
121 if (code == TTS_CONFIG_ERROR_INVALID_STATE) return TTS_ERROR_INVALID_STATE;
122 if (code == TTS_CONFIG_ERROR_INVALID_VOICE) return TTS_ERROR_INVALID_VOICE;
123 if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND) return TTS_ERROR_ENGINE_NOT_FOUND;
124 if (code == TTS_CONFIG_ERROR_OPERATION_FAILED) return TTS_ERROR_OPERATION_FAILED;
125 if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE) return TTS_ERROR_NOT_SUPPORTED_FEATURE;
131 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)
133 SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
134 before_lang, before_voice_type, language, voice_type);
136 GList* client_list = NULL;
137 client_list = tts_client_get_client_list();
140 tts_client_s *data = NULL;
142 if (g_list_length(client_list) > 0) {
143 /* Get a first item */
144 iter = g_list_first(client_list);
146 while (NULL != iter) {
148 if (NULL != data->default_voice_changed_cb) {
149 SLOG(LOG_DEBUG, TAG_TTSC, "Call default voice changed callback : uid(%d)", data->uid);
150 data->default_voice_changed_cb(data->tts, before_lang, before_voice_type,
151 language, voice_type, data->default_voice_changed_user_data);
154 /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
155 if (0 != strncmp(before_lang, language, strlen(before_lang))) {
156 if (NULL != data->text_repeat) {
157 free(data->text_repeat);
158 data->text_repeat = NULL;
163 iter = g_list_next(iter);
170 static Eina_Bool __reconnect_by_engine_changed(void* data)
172 tts_h tts = (tts_h)data;
174 tts_client_s* client = tts_client_get(tts);
175 if (NULL == client) {
176 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
180 if (TTS_STATE_READY != client->current_state) {
185 int ret = tts_unprepare(tts);
187 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
189 ret = tts_prepare(tts);
191 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
197 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)
199 tts_h tts = (tts_h)user_data;
201 tts_client_s* client = tts_client_get(tts);
202 if (NULL == client) {
203 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
207 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
208 if (NULL != setting) SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
209 if (NULL != language) SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
210 SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
212 /* When the default engine is changed, please unload the old engine and load the new one. */
215 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
218 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
221 ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
222 } else if (TTS_STATE_READY == client->current_state) {
223 ret = tts_unprepare(tts);
225 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
227 ret = tts_prepare(tts);
229 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
233 /* call callback function */
234 if (NULL != client->engine_changed_cb) {
235 client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
237 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function for changed engine");
243 void __tts_unset_all_callbacks(tts_h tts)
245 SLOG(LOG_INFO, TAG_TTSC, "@@@ unset all callbacks");
247 tts_unset_state_changed_cb(tts);
248 tts_unset_utterance_started_cb(tts);
249 tts_unset_utterance_completed_cb(tts);
250 tts_unset_error_cb(tts);
251 tts_unset_default_voice_changed_cb(tts);
252 tts_unset_engine_changed_cb(tts);
254 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
257 static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
259 SLOG(LOG_INFO, TAG_TTSC, "[INFO] pkgmgr status cb is invoked. pkgname(%s), type(%s), key(%s), val(%s)", pkgname, type, key, val);
261 if (0 != strncmp(g_engine_name, pkgname, strlen(g_engine_name))) {
262 SLOG(LOG_DEBUG, TAG_TTSC, "[WARN] this is not tts engine");
265 if (key && 0 == strncmp(key, "start", strlen(key))) {
266 if (val && (0 == strncmp(val, "update", strlen(val) || 0 == strncmp(val, "uninstall", strlen(val))))) {
267 SLOG(LOG_INFO, TAG_TTSC, "[INFO] start to install.");
268 g_engine_update_status = 1;
270 } else if (key && 0 == strncmp(key, "end", strlen(key))) {
271 SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish to install");
272 g_engine_update_status = 0;
279 static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
281 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] create pkgmgr thread");
284 g_pkgmgr = pkgmgr_client_new(PC_LISTENING);
285 if (NULL == g_pkgmgr) {
286 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create pkgmgr handle");
288 if (pkgmgr_client_listen_status(g_pkgmgr, __pkgmgr_status_cb, NULL) < 0) {
289 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to listen pkgmgr status. remove and recreate client");
290 pkgmgr_client_free(g_pkgmgr);
294 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Succeed to register pkgmgr cb");
303 static void __finish_pkgmgr_thread(void* data, Ecore_Thread* thread)
305 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Finish pkgmgr thread");
308 static void __pkgmgr_thread(void* data)
310 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] call pkgmgr_thread");
312 ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, NULL, NULL);
317 int tts_create(tts_h* tts)
319 if (0 != __tts_get_feature_enabled()) {
320 return TTS_ERROR_NOT_SUPPORTED;
323 SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
327 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
328 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
329 return TTS_ERROR_INVALID_PARAMETER;
332 if (0 == tts_client_get_size()) {
333 if (0 != tts_dbus_open_connection()) {
334 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection");
335 return TTS_ERROR_OPERATION_FAILED;
339 if (0 != tts_client_new(tts)) {
340 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
341 return TTS_ERROR_OUT_OF_MEMORY;
344 tts_client_s* client = tts_client_get(*tts);
345 if (NULL == client) {
346 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
347 return TTS_ERROR_OPERATION_FAILED;
350 int ret = tts_config_mgr_initialize(client->uid);
352 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
353 tts_client_destroy(*tts);
354 return __tts_convert_config_error_code(ret);
357 ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
359 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
360 tts_client_destroy(*tts);
361 return __tts_convert_config_error_code(ret);
364 ecore_main_loop_thread_safe_call_async(__pkgmgr_thread, NULL);
366 SLOG(LOG_INFO, TAG_TTSC, "[INFO] call ecore thread for creating pkgmgr thread");
368 g_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
369 if (NULL == g_engine_name) {
370 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name");
372 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Engine name(%s)", g_engine_name);
375 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
376 SLOG(LOG_DEBUG, TAG_TTSC, " ");
378 return TTS_ERROR_NONE;
381 int tts_destroy(tts_h tts)
383 if (0 != __tts_get_feature_enabled()) {
384 return TTS_ERROR_NOT_SUPPORTED;
387 SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
390 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
391 return TTS_ERROR_INVALID_PARAMETER;
394 tts_client_s* client = tts_client_get(tts);
397 if (NULL == client) {
398 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
399 return TTS_ERROR_INVALID_PARAMETER;
402 /* check used callback */
403 if (0 != tts_client_get_use_callback(client)) {
404 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot destroy in Callback function");
405 return TTS_ERROR_OPERATION_FAILED;
409 pkgmgr_client_remove_listen_status(g_pkgmgr);
410 pkgmgr_client_free(g_pkgmgr);
414 tts_config_mgr_finalize(client->uid);
418 int screen_reader = -1;
421 switch (client->current_state) {
422 case TTS_STATE_PAUSED:
423 case TTS_STATE_PLAYING:
424 case TTS_STATE_READY:
425 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
427 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
429 SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
430 g_screen_reader = (bool)screen_reader;
432 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
434 ret = tts_dbus_request_finalize(client->uid);
437 if (TTS_ERROR_TIMED_OUT != ret) {
438 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
441 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize");
444 if (TTS_RETRY_COUNT == count) {
445 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
453 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
456 client->before_state = client->current_state;
457 client->current_state = TTS_STATE_CREATED;
459 case TTS_STATE_CREATED:
460 if (NULL != client->conn_timer) {
461 SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted");
462 ecore_timer_del(client->conn_timer);
463 client->conn_timer = NULL;
465 /* Unset registered callbacks */
466 __tts_unset_all_callbacks(tts);
469 tts_client_destroy(tts);
476 if (0 == tts_client_get_size()) {
477 if (0 != tts_dbus_close_connection()) {
478 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
482 if (NULL != g_language) {
487 /* Delete state timer before destroying handle */
488 if (NULL != g_check_state_timer) {
489 ecore_timer_del(g_check_state_timer);
490 g_check_state_timer = NULL;
495 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
497 return TTS_ERROR_NONE;
501 void __tts_screen_reader_changed_cb(bool value)
503 g_screen_reader = value;
507 int tts_set_mode(tts_h tts, tts_mode_e mode)
509 if (0 != __tts_get_feature_enabled()) {
510 return TTS_ERROR_NOT_SUPPORTED;
513 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
515 tts_client_s* client = tts_client_get(tts);
518 if (NULL == client) {
519 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
520 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
521 return TTS_ERROR_INVALID_PARAMETER;
525 if (client->current_state != TTS_STATE_CREATED) {
526 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
527 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
528 SLOG(LOG_DEBUG, TAG_TTSC, " ");
529 return TTS_ERROR_INVALID_STATE;
532 if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
535 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
536 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
537 SLOG(LOG_DEBUG, TAG_TTSC, " ");
538 return TTS_ERROR_INVALID_PARAMETER;
541 if (TTS_MODE_SCREEN_READER == mode) {
544 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
546 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader");
547 return TTS_ERROR_OPERATION_FAILED;
549 g_screen_reader = (bool)screen_reader;
550 tts_config_set_screen_reader_callback(client->uid, __tts_screen_reader_changed_cb);
552 tts_config_unset_screen_reader_callback(client->uid);
555 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
557 return TTS_ERROR_NONE;
560 int tts_get_mode(tts_h tts, tts_mode_e* mode)
562 if (0 != __tts_get_feature_enabled()) {
563 return TTS_ERROR_NOT_SUPPORTED;
566 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
568 tts_client_s* client = tts_client_get(tts);
571 if (NULL == client) {
572 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
573 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
574 SLOG(LOG_DEBUG, TAG_TTSC, " ");
575 return TTS_ERROR_INVALID_PARAMETER;
579 if (client->current_state != TTS_STATE_CREATED) {
580 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
581 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
582 SLOG(LOG_DEBUG, TAG_TTSC, " ");
583 return TTS_ERROR_INVALID_STATE;
587 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter(mode) is NULL");
588 return TTS_ERROR_INVALID_PARAMETER;
591 *mode = client->mode;
593 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
594 SLOG(LOG_DEBUG, TAG_TTSC, " ");
596 return TTS_ERROR_NONE;
599 int tts_set_credential(tts_h tts, const char* credential)
601 if (0 != __tts_get_feature_enabled()) {
602 return TTS_ERROR_NOT_SUPPORTED;
605 if (NULL == tts || NULL == credential) {
606 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
607 return TTS_ERROR_INVALID_PARAMETER;
610 tts_client_s* client = tts_client_get(tts);
612 if (NULL == client) {
613 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
614 return TTS_ERROR_INVALID_PARAMETER;
617 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
618 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
619 return TTS_ERROR_INVALID_STATE;
622 if (NULL != client->credential) {
623 free(client->credential);
624 client->credential = NULL;
626 client->credential = strdup(credential);
628 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
630 return TTS_ERROR_NONE;
634 int tts_set_server_tts(tts_h tts, const char* credential)
636 if (0 != __tts_get_feature_enabled()) {
637 return TTS_ERROR_NOT_SUPPORTED;
641 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
642 return TTS_ERROR_INVALID_PARAMETER;
645 tts_client_s* client = tts_client_get(tts);
647 if (NULL == client) {
648 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
649 return TTS_ERROR_INVALID_PARAMETER;
652 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
653 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
654 return TTS_ERROR_INVALID_STATE;
657 if (NULL != client->credential) {
658 free(client->credential);
659 client->credential = NULL;
662 client->internal = true;
665 if (NULL != credential) {
666 key = strdup("EnableServerTTS");
667 client->credential = strdup(credential);
668 if (NULL == client->credential) {
669 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
674 return TTS_ERROR_OUT_OF_MEMORY;
677 key = strdup("DisableServerTTS");
681 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
682 return TTS_ERROR_OUT_OF_MEMORY;
687 int ret = app_manager_get_app_id(pid, &appid);
688 if (0 != ret || NULL == appid) {
689 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
696 return TTS_ERROR_OPERATION_FAILED;
699 ret = tts_set_private_data(tts, key, appid);
701 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
714 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
716 return TTS_ERROR_NONE;
720 static Eina_Bool __tts_connect_daemon(void *data)
722 tts_h tts = (tts_h)data;
723 tts_client_s* client = tts_client_get(tts);
726 if (NULL == client) {
727 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
731 /* check whether engine is updating or not */
732 if (g_engine_update_status) {
733 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update");
734 __tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
740 if (0 != tts_dbus_request_hello(client->uid)) {
744 SLOG(LOG_INFO, TAG_TTSC, "@@@ Connect daemon");
746 /* do request initialize */
748 bool credential_needed = false;
750 ret = tts_dbus_request_initialize(client->uid, &credential_needed);
752 if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
753 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
755 client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
758 ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
759 if (client->conn_timer) {
760 ecore_timer_del(client->conn_timer);
761 client->conn_timer = NULL;
765 } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
766 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
768 client->reason = TTS_ERROR_PERMISSION_DENIED;
771 ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
772 if (client->conn_timer) {
773 ecore_timer_del(client->conn_timer);
774 client->conn_timer = NULL;
778 } else if (TTS_ERROR_NONE != ret) {
779 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
783 /* success to connect tts-daemon */
784 client->credential_needed = credential_needed;
785 SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
788 if (client->conn_timer) {
789 ecore_timer_del(client->conn_timer);
790 client->conn_timer = NULL;
793 client = tts_client_get(tts);
795 if (NULL == client) {
796 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
800 client->before_state = client->current_state;
801 client->current_state = TTS_STATE_READY;
803 if (NULL != client->state_changed_cb) {
804 tts_client_use_callback(client);
805 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
806 tts_client_not_use_callback(client);
808 SLOG(LOG_WARN, TAG_TTSC, "State changed callback is NULL");
811 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
816 int tts_prepare(tts_h tts)
818 if (0 != __tts_get_feature_enabled()) {
819 return TTS_ERROR_NOT_SUPPORTED;
822 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
824 tts_client_s* client = tts_client_get(tts);
827 if (NULL == client) {
828 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
829 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
830 return TTS_ERROR_INVALID_PARAMETER;
834 if (client->current_state != TTS_STATE_CREATED) {
835 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
836 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
837 return TTS_ERROR_INVALID_STATE;
840 ecore_thread_main_loop_begin();
841 if (client->conn_timer) {
842 ecore_timer_del(client->conn_timer);
843 client->conn_timer = NULL;
845 client->conn_timer = ecore_timer_add(0.02, __tts_connect_daemon, (void*)tts);
846 ecore_thread_main_loop_end();
848 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
850 return TTS_ERROR_NONE;
854 int tts_prepare_sync(tts_h tts)
856 if (0 != __tts_get_feature_enabled()) {
857 return TTS_ERROR_NOT_SUPPORTED;
860 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
862 tts_client_s* client = tts_client_get(tts);
865 if (NULL == client) {
866 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
867 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
868 return TTS_ERROR_INVALID_PARAMETER;
872 if (client->current_state != TTS_STATE_CREATED) {
873 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
874 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
875 return TTS_ERROR_INVALID_STATE;
879 while (EINA_TRUE == __tts_connect_daemon((void*)tts) && TTS_CONNECTION_RETRY_COUNT > cnt) {
883 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
885 if (TTS_CONNECTION_RETRY_COUNT == cnt) {
886 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect daemon");
887 return TTS_ERROR_OPERATION_FAILED;
890 return TTS_ERROR_NONE;
894 int tts_unprepare(tts_h tts)
896 if (0 != __tts_get_feature_enabled()) {
897 return TTS_ERROR_NOT_SUPPORTED;
900 SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
902 tts_client_s* client = tts_client_get(tts);
905 if (NULL == client) {
906 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
907 return TTS_ERROR_INVALID_PARAMETER;
911 if (client->current_state != TTS_STATE_READY) {
912 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'READY'");
913 return TTS_ERROR_INVALID_STATE;
918 int screen_reader = -1;
920 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
922 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
924 SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
925 g_screen_reader = (bool)screen_reader;
928 bool is_prepared = false;
929 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
931 ret = tts_dbus_request_finalize(client->uid);
934 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
935 client->current_state = TTS_STATE_CREATED;
936 if (0 == tts_prepare_sync(tts)) {
938 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
940 } else if (TTS_ERROR_TIMED_OUT != ret) {
941 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
944 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize : %s", __tts_get_error_code(ret));
947 if (TTS_RETRY_COUNT == count) {
948 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
956 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
959 client->before_state = client->current_state;
960 client->current_state = TTS_STATE_CREATED;
962 if (NULL != client->state_changed_cb) {
963 tts_client_use_callback(client);
964 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
965 tts_client_not_use_callback(client);
966 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
969 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
971 return TTS_ERROR_NONE;
974 bool __tts_supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
976 tts_h tts = (tts_h)user_data;
978 tts_client_s* client = tts_client_get(tts);
979 if (NULL == client) {
980 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
984 /* call callback function */
985 if (NULL != client->supported_voice_cb) {
986 return client->supported_voice_cb(tts, language, type, client->supported_voice_user_data);
988 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of supported voice");
994 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
996 if (0 != __tts_get_feature_enabled()) {
997 return TTS_ERROR_NOT_SUPPORTED;
1000 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported voices");
1002 if (NULL == tts || NULL == callback) {
1003 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1004 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1005 return TTS_ERROR_INVALID_PARAMETER;
1008 tts_client_s* client = tts_client_get(tts);
1011 if (NULL == client) {
1012 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1013 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1014 return TTS_ERROR_INVALID_PARAMETER;
1018 char* current_engine = NULL;
1019 ret = tts_config_mgr_get_engine(¤t_engine);
1021 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
1022 return __tts_convert_config_error_code(ret);
1025 client->supported_voice_cb = callback;
1026 client->supported_voice_user_data = user_data;
1028 ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts);
1030 if (NULL != current_engine) {
1031 free(current_engine);
1032 current_engine = NULL;
1035 client->supported_voice_cb = NULL;
1036 client->supported_voice_user_data = NULL;
1039 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
1040 ret = TTS_ERROR_OPERATION_FAILED;
1043 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1048 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
1050 if (0 != __tts_get_feature_enabled()) {
1051 return TTS_ERROR_NOT_SUPPORTED;
1054 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
1057 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1058 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1059 return TTS_ERROR_INVALID_PARAMETER;
1062 tts_client_s* client = tts_client_get(tts);
1064 if (NULL == client) {
1065 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1066 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1067 return TTS_ERROR_INVALID_PARAMETER;
1070 /* Request call remote method */
1072 ret = tts_config_mgr_get_voice(lang, vctype);
1074 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
1075 return __tts_convert_config_error_code(ret);
1077 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
1080 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1085 int tts_get_max_text_size(tts_h tts, unsigned int* size)
1087 if (0 != __tts_get_feature_enabled()) {
1088 return TTS_ERROR_NOT_SUPPORTED;
1091 if (NULL == tts || NULL == size) {
1092 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Input parameter is null");
1093 return TTS_ERROR_INVALID_PARAMETER;
1096 tts_client_s* client = tts_client_get(tts);
1098 if (NULL == client) {
1099 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : A handle is not valid");
1100 return TTS_ERROR_INVALID_PARAMETER;
1103 if (TTS_STATE_READY != client->current_state) {
1104 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Current state is NOT 'READY'.");
1105 return TTS_ERROR_INVALID_STATE;
1108 if (0 != tts_config_mgr_get_max_text_size(size)) {
1109 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
1110 return TTS_ERROR_INVALID_PARAMETER;
1113 g_max_text_size = (int)*size;
1115 SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
1116 return TTS_ERROR_NONE;
1119 int tts_get_state(tts_h tts, tts_state_e* state)
1121 if (0 != __tts_get_feature_enabled()) {
1122 return TTS_ERROR_NOT_SUPPORTED;
1125 if (NULL == tts || NULL == state) {
1126 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : Input parameter is null");
1127 return TTS_ERROR_INVALID_PARAMETER;
1130 tts_client_s* client = tts_client_get(tts);
1132 if (NULL == client) {
1133 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1134 return TTS_ERROR_INVALID_PARAMETER;
1137 *state = client->current_state;
1140 case TTS_STATE_CREATED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Created'"); break;
1141 case TTS_STATE_READY: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Ready'"); break;
1142 case TTS_STATE_PLAYING: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Playing'"); break;
1143 case TTS_STATE_PAUSED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Paused'"); break;
1144 default: SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value"); break;
1147 return TTS_ERROR_NONE;
1150 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
1152 if (0 != __tts_get_feature_enabled()) {
1153 return TTS_ERROR_NOT_SUPPORTED;
1156 if (NULL == tts || NULL == min || NULL == normal || NULL == max) {
1157 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1158 return TTS_ERROR_INVALID_PARAMETER;
1161 tts_client_s* client = tts_client_get(tts);
1163 if (NULL == client) {
1164 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1165 return TTS_ERROR_INVALID_PARAMETER;
1168 *min = TTS_SPEED_MIN;
1169 *normal = TTS_SPEED_NORMAL;
1170 *max = TTS_SPEED_MAX;
1172 return TTS_ERROR_NONE;
1175 int tts_get_error_message(tts_h tts, char** err_msg)
1177 if (0 != __tts_get_feature_enabled()) {
1178 return TTS_ERROR_NOT_SUPPORTED;
1181 if (NULL == tts || NULL == err_msg) {
1182 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1183 return TTS_ERROR_INVALID_PARAMETER;
1186 tts_client_s* client = tts_client_get(tts);
1188 if (NULL == client) {
1189 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1190 return TTS_ERROR_INVALID_PARAMETER;
1193 if (NULL != client->err_msg) {
1194 *err_msg = strdup(client->err_msg);
1195 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg);
1198 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)");
1201 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1203 return TTS_ERROR_NONE;
1206 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
1208 SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
1210 if (0 != __tts_get_feature_enabled()) {
1211 return TTS_ERROR_NOT_SUPPORTED;
1215 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Speed should not be negative(%d)", speed);
1216 return TTS_ERROR_INVALID_PARAMETER;
1219 if (voice_type < 0) {
1220 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Voice type should not be negative(%d)", voice_type);
1221 return TTS_ERROR_INVALID_PARAMETER;
1224 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Add text");
1226 if (NULL == tts || NULL == utt_id) {
1227 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1228 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1229 return TTS_ERROR_INVALID_PARAMETER;
1232 tts_client_s* client = tts_client_get(tts);
1234 if (NULL == client) {
1235 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1236 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1237 return TTS_ERROR_INVALID_PARAMETER;
1240 if (TTS_STATE_CREATED == client->current_state) {
1241 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1242 return TTS_ERROR_INVALID_STATE;
1245 if (-1 == g_max_text_size) {
1246 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
1247 if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
1248 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
1249 return TTS_ERROR_INVALID_PARAMETER;
1253 if (0 == g_max_text_size) {
1254 if (strlen(text) <= 0) {
1255 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d", g_max_text_size);
1256 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
1257 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1258 return TTS_ERROR_INVALID_PARAMETER;
1261 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
1262 if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
1263 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
1264 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1265 return TTS_ERROR_INVALID_PARAMETER;
1269 if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
1270 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] speed value(%d) is invalid.", speed);
1271 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1272 return TTS_ERROR_INVALID_PARAMETER;
1275 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1276 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1277 return TTS_ERROR_INVALID_STATE;
1280 if (true == client->credential_needed && NULL == client->credential) {
1281 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1282 return TTS_ERROR_PERMISSION_DENIED;
1285 /* check valid utf8 */
1289 dbus_error_init(&err);
1291 valid = dbus_validate_utf8(text, &err);
1292 if (dbus_error_is_set(&err)) {
1293 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
1294 dbus_error_free(&err);
1295 return TTS_ERROR_INVALID_PARAMETER;
1298 if (valid != true) {
1299 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
1300 return TTS_ERROR_INVALID_PARAMETER;
1302 SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
1304 /* save texts for repetition */
1305 if (NULL != client->text_repeat) {
1306 free(client->text_repeat);
1307 client->text_repeat = NULL;
1310 client->text_repeat = strdup(text);
1312 if (NULL != g_language) {
1316 if (NULL == language)
1319 g_language = strdup(language);
1321 g_voice_type = voice_type;
1324 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] repeat: text(%s), language(%s), voice type(%d), speed(%d)", client->text_repeat, (g_language) ? g_language : "NULL", g_voice_type, g_speed);
1326 /* change default language value */
1329 if (NULL == language)
1330 temp = strdup("default");
1332 temp = strdup(language);
1334 client->current_utt_id++;
1335 if (client->current_utt_id == 10000) {
1336 client->current_utt_id = 1;
1342 bool is_prepared = false;
1344 ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
1347 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1348 client->current_state = TTS_STATE_CREATED;
1349 if (0 == tts_prepare_sync(tts)) {
1351 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1353 } else if (TTS_ERROR_TIMED_OUT != ret) {
1354 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1357 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add text : %s", __tts_get_error_code(ret));
1360 if (TTS_RETRY_MIN_COUNT == count) {
1361 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1367 *utt_id = client->current_utt_id;
1376 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1382 static void __tts_play_async(void *data)
1384 tts_h tts = (tts_h)data;
1385 tts_client_s* client = tts_client_get(tts);
1388 if (NULL == client) {
1389 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1395 bool is_prepared = false;
1397 ret = tts_dbus_request_play(client->uid, client->credential);
1399 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1400 client->current_state = TTS_STATE_CREATED;
1401 if (0 == tts_prepare_sync(tts)) {
1403 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1405 } else if (TTS_ERROR_TIMED_OUT != ret) {
1406 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1409 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1412 if (TTS_RETRY_COUNT == count) {
1413 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1421 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
1423 client->reason = ret;
1424 client->utt_id = -1;
1426 ecore_timer_add(0, __tts_notify_error, client->tts);
1430 client->before_state = client->current_state;
1431 client->current_state = TTS_STATE_PLAYING;
1433 if (NULL != client->state_changed_cb) {
1434 tts_client_use_callback(client);
1435 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1436 tts_client_not_use_callback(client);
1437 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1440 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1445 int tts_play_async(tts_h tts)
1447 if (0 != __tts_get_feature_enabled()) {
1448 return TTS_ERROR_NOT_SUPPORTED;
1451 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play tts");
1454 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1455 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1456 return TTS_ERROR_INVALID_PARAMETER;
1459 tts_client_s* client = tts_client_get(tts);
1461 if (NULL == client) {
1462 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1463 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1464 return TTS_ERROR_INVALID_PARAMETER;
1467 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1468 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1469 return TTS_ERROR_INVALID_STATE;
1472 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1473 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1474 return TTS_ERROR_INVALID_STATE;
1477 if (true == client->credential_needed && NULL == client->credential) {
1478 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1479 return TTS_ERROR_PERMISSION_DENIED;
1482 ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
1484 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1486 return TTS_ERROR_NONE;
1489 int tts_play(tts_h tts)
1491 if (0 != __tts_get_feature_enabled()) {
1492 return TTS_ERROR_NOT_SUPPORTED;
1495 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
1498 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1499 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1500 return TTS_ERROR_INVALID_PARAMETER;
1503 tts_client_s* client = tts_client_get(tts);
1505 if (NULL == client) {
1506 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1507 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1508 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1509 return TTS_ERROR_INVALID_PARAMETER;
1512 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1513 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1514 return TTS_ERROR_INVALID_STATE;
1517 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1518 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1519 return TTS_ERROR_INVALID_STATE;
1522 if (true == client->credential_needed && NULL == client->credential) {
1523 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1524 return TTS_ERROR_PERMISSION_DENIED;
1529 bool is_prepared = false;
1531 ret = tts_dbus_request_play(client->uid, client->credential);
1534 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1535 client->current_state = TTS_STATE_CREATED;
1536 if (0 == tts_prepare_sync(tts)) {
1538 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1540 } else if (TTS_ERROR_TIMED_OUT != ret) {
1541 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1544 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1547 if (TTS_RETRY_COUNT == count) {
1548 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1556 client->before_state = client->current_state;
1557 client->current_state = TTS_STATE_PLAYING;
1559 if (NULL != client->state_changed_cb) {
1560 tts_client_use_callback(client);
1561 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1562 tts_client_not_use_callback(client);
1563 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1566 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1568 return TTS_ERROR_NONE;
1571 static void __tts_stop_async(void *data)
1573 tts_h tts = (tts_h)data;
1574 tts_client_s* client = tts_client_get(tts);
1577 if (NULL == client) {
1578 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1584 bool is_prepared = false;
1586 ret = tts_dbus_request_stop(client->uid);
1588 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1589 client->current_state = TTS_STATE_CREATED;
1590 if (0 == tts_prepare_sync(tts)) {
1592 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1594 } else if (TTS_ERROR_TIMED_OUT != ret) {
1595 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1598 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1601 if (TTS_RETRY_COUNT == count) {
1602 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1610 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
1612 client->reason = ret;
1613 client->utt_id = -1;
1615 ecore_timer_add(0, __tts_notify_error, client->tts);
1619 client->before_state = client->current_state;
1620 client->current_state = TTS_STATE_READY;
1622 if (NULL != client->state_changed_cb) {
1623 tts_client_use_callback(client);
1624 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1625 tts_client_not_use_callback(client);
1626 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1629 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1634 int tts_stop_aync(tts_h tts)
1636 if (0 != __tts_get_feature_enabled()) {
1637 return TTS_ERROR_NOT_SUPPORTED;
1640 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop tts");
1643 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1644 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1645 return TTS_ERROR_INVALID_PARAMETER;
1648 tts_client_s* client = tts_client_get(tts);
1650 if (NULL == client) {
1651 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1652 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1653 return TTS_ERROR_INVALID_PARAMETER;
1656 if (TTS_STATE_CREATED == client->current_state) {
1657 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1658 return TTS_ERROR_INVALID_STATE;
1661 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1662 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1663 return TTS_ERROR_INVALID_STATE;
1666 ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
1668 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1670 return TTS_ERROR_NONE;
1673 int tts_stop(tts_h tts)
1675 if (0 != __tts_get_feature_enabled()) {
1676 return TTS_ERROR_NOT_SUPPORTED;
1679 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
1682 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1683 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1684 return TTS_ERROR_INVALID_PARAMETER;
1687 tts_client_s* client = tts_client_get(tts);
1689 if (NULL == client) {
1690 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1691 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1692 return TTS_ERROR_INVALID_PARAMETER;
1695 if (TTS_STATE_CREATED == client->current_state) {
1696 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1697 return TTS_ERROR_INVALID_STATE;
1700 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1701 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1702 return TTS_ERROR_INVALID_STATE;
1707 bool is_prepared = false;
1709 ret = tts_dbus_request_stop(client->uid);
1712 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1713 client->current_state = TTS_STATE_CREATED;
1714 if (0 == tts_prepare_sync(tts)) {
1716 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1718 } else if (TTS_ERROR_TIMED_OUT != ret) {
1719 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1722 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1725 if (TTS_RETRY_COUNT == count) {
1726 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1734 client->before_state = client->current_state;
1735 client->current_state = TTS_STATE_READY;
1737 if (NULL != client->state_changed_cb) {
1738 tts_client_use_callback(client);
1739 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1740 tts_client_not_use_callback(client);
1741 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1744 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1746 return TTS_ERROR_NONE;
1749 static void __tts_pause_async(void *data)
1751 tts_h tts = (tts_h)data;
1752 tts_client_s* client = tts_client_get(tts);
1755 if (NULL == client) {
1756 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1762 bool is_prepared = false;
1764 ret = tts_dbus_request_pause(client->uid);
1766 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1767 client->current_state = TTS_STATE_CREATED;
1768 if (0 == tts_prepare_sync(tts)) {
1770 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1772 } else if (TTS_ERROR_TIMED_OUT != ret) {
1773 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1776 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1779 if (TTS_RETRY_COUNT == count) {
1780 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1788 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
1790 client->reason = ret;
1791 client->utt_id = -1;
1793 ecore_timer_add(0, __tts_notify_error, client->tts);
1797 client->before_state = client->current_state;
1798 client->current_state = TTS_STATE_PAUSED;
1800 if (NULL != client->state_changed_cb) {
1801 tts_client_use_callback(client);
1802 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1803 tts_client_not_use_callback(client);
1804 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1807 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1812 int tts_pause_async(tts_h tts)
1814 if (0 != __tts_get_feature_enabled()) {
1815 return TTS_ERROR_NOT_SUPPORTED;
1818 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause tts");
1821 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1822 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1823 return TTS_ERROR_INVALID_PARAMETER;
1826 tts_client_s* client = tts_client_get(tts);
1828 if (NULL == client) {
1829 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1830 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1831 return TTS_ERROR_INVALID_PARAMETER;
1834 if (TTS_STATE_PLAYING != client->current_state) {
1835 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1836 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1837 return TTS_ERROR_INVALID_STATE;
1840 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1841 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1842 return TTS_ERROR_INVALID_STATE;
1845 ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
1847 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1849 return TTS_ERROR_NONE;
1852 int tts_pause(tts_h tts)
1854 if (0 != __tts_get_feature_enabled()) {
1855 return TTS_ERROR_NOT_SUPPORTED;
1858 SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
1861 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1862 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1863 return TTS_ERROR_INVALID_PARAMETER;
1866 tts_client_s* client = tts_client_get(tts);
1868 if (NULL == client) {
1869 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1870 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1871 return TTS_ERROR_INVALID_PARAMETER;
1874 if (TTS_STATE_PLAYING != client->current_state) {
1875 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1876 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1877 return TTS_ERROR_INVALID_STATE;
1880 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1881 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1882 return TTS_ERROR_INVALID_STATE;
1887 bool is_prepared = false;
1889 ret = tts_dbus_request_pause(client->uid);
1892 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1893 client->current_state = TTS_STATE_CREATED;
1894 if (0 == tts_prepare_sync(tts)) {
1896 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1898 } else if (TTS_ERROR_TIMED_OUT != ret) {
1899 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1902 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1905 if (TTS_RETRY_COUNT == count) {
1906 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1914 client->before_state = client->current_state;
1915 client->current_state = TTS_STATE_PAUSED;
1917 if (NULL != client->state_changed_cb) {
1918 tts_client_use_callback(client);
1919 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1920 tts_client_not_use_callback(client);
1921 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1924 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1926 return TTS_ERROR_NONE;
1929 int tts_set_private_data(tts_h tts, const char* key, const char* data)
1931 if (0 != __tts_get_feature_enabled()) {
1932 return TTS_ERROR_NOT_SUPPORTED;
1935 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
1938 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1939 return TTS_ERROR_INVALID_PARAMETER;
1942 if (NULL == key || NULL == data) {
1943 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
1944 return TTS_ERROR_INVALID_PARAMETER;
1947 tts_client_s* client = tts_client_get(tts);
1949 if (NULL == client) {
1950 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1951 return TTS_ERROR_INVALID_PARAMETER;
1954 if (TTS_STATE_READY != client->current_state) {
1955 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
1956 return TTS_ERROR_INVALID_STATE;
1959 if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
1960 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
1961 return TTS_ERROR_INVALID_PARAMETER;
1966 bool is_prepared = false;
1968 ret = tts_dbus_request_set_private_data(client->uid, key, data);
1971 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1972 client->current_state = TTS_STATE_CREATED;
1973 if (0 == tts_prepare_sync(tts)) {
1975 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1977 } else if (TTS_ERROR_TIMED_OUT != ret) {
1978 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1981 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
1984 if (TTS_RETRY_COUNT == count) {
1985 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1993 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1998 int tts_get_private_data(tts_h tts, const char* key, char** data)
2000 if (0 != __tts_get_feature_enabled()) {
2001 return TTS_ERROR_NOT_SUPPORTED;
2004 SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
2007 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
2008 return TTS_ERROR_INVALID_PARAMETER;
2011 if (NULL == key || NULL == data) {
2012 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
2013 return TTS_ERROR_INVALID_PARAMETER;
2016 tts_client_s* client = tts_client_get(tts);
2018 if (NULL == client) {
2019 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
2020 return TTS_ERROR_INVALID_PARAMETER;
2023 if (TTS_STATE_READY != client->current_state) {
2024 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
2025 return TTS_ERROR_INVALID_STATE;
2030 bool is_prepared = false;
2032 ret = tts_dbus_request_get_private_data(client->uid, key, data);
2035 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2036 client->current_state = TTS_STATE_CREATED;
2037 if (0 == tts_prepare_sync(tts)) {
2039 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2041 } else if (TTS_ERROR_TIMED_OUT != ret) {
2042 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2045 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
2048 if (TTS_RETRY_COUNT == count) {
2049 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2057 if (0 == strncmp(*data, "NULL", strlen(*data))) {
2062 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2068 static Eina_Bool __tts_notify_error(void *data)
2070 tts_h tts = (tts_h)data;
2072 tts_client_s* client = tts_client_get(tts);
2075 if (NULL == client) {
2076 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify error msg : A handle is not valid");
2080 SLOG(LOG_DEBUG, TAG_TTSC, "Error data : uttid(%d) reason(%s)", client->utt_id, __tts_get_error_code(client->reason));
2082 if (NULL != client->error_cb) {
2083 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of error");
2084 tts_client_use_callback(client);
2085 g_err_callback_status = true;
2086 client->error_cb(client->tts, client->utt_id, client->reason, client->error_user_data);
2087 g_err_callback_status = false;
2088 tts_client_not_use_callback(client);
2090 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2096 static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
2098 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] start reprepare thread. engine update status(%d)", g_engine_update_status);
2100 tts_client_s* temp = (tts_client_s*)data;
2102 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] data is null");
2107 while (!g_engine_update_status && (cnt < 10)) {
2108 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for starting update");
2113 SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] update status(%d)", g_engine_update_status);
2115 while (g_engine_update_status && (NULL != g_pkgmgr)) {
2116 // SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for finishing update");
2120 SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish updating. request to prepare");
2122 if (0 != tts_prepare(temp->tts)) {
2123 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
2129 static void __end_reprepare_thread(void* data, Ecore_Thread* thread)
2131 SLOG(LOG_INFO, TAG_TTSC, "[INFO] end reprepare thread");
2134 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
2137 GList* client_list = NULL;
2138 client_list = tts_client_get_client_list();
2141 tts_client_s *data = NULL;
2143 if (g_list_length(client_list) > 0) {
2144 /* Get a first item */
2145 iter = g_list_first(client_list);
2147 while (NULL != iter) {
2150 data->utt_id = utt_id;
2151 data->reason = reason;
2152 if (NULL != data->err_msg) {
2153 free(data->err_msg);
2154 data->err_msg = NULL;
2156 if (NULL != err_msg)
2157 data->err_msg = strdup(err_msg);
2159 /* call callback function */
2160 if (NULL != data->error_cb) {
2161 ecore_timer_add(0, __tts_notify_error, data->tts);
2163 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2166 if (TTS_ERROR_SERVICE_RESET == reason) {
2167 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
2169 data->current_state = TTS_STATE_CREATED;
2170 ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, data);
2174 iter = g_list_next(iter);
2178 tts_client_s* client = tts_client_get_by_uid(uid);
2180 if (NULL == client) {
2181 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2182 return TTS_ERROR_INVALID_PARAMETER;
2185 client->utt_id = utt_id;
2186 client->reason = reason;
2187 if (NULL != client->err_msg) {
2188 free(client->err_msg);
2189 client->err_msg = NULL;
2191 if (NULL != err_msg)
2192 client->err_msg = strdup(err_msg);
2194 /* call callback function */
2195 if (NULL != client->error_cb) {
2196 ecore_timer_add(0, __tts_notify_error, client->tts);
2198 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2201 if (TTS_ERROR_SERVICE_RESET == reason) {
2202 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
2204 client->current_state = TTS_STATE_CREATED;
2206 ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, client);
2213 static Eina_Bool __tts_notify_state_changed(void *data)
2215 tts_h tts = (tts_h)data;
2217 tts_client_s* client = tts_client_get(tts);
2220 if (NULL == client) {
2221 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify state changed : A handle is not valid");
2225 if (NULL != client->state_changed_cb) {
2226 tts_client_use_callback(client);
2227 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2228 tts_client_not_use_callback(client);
2229 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called : pre(%d) cur(%d)", client->before_state, client->current_state);
2231 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
2237 int __tts_cb_set_state(int uid, int state)
2239 tts_client_s* client = tts_client_get_by_uid(uid);
2240 if (NULL == client) {
2241 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] The handle is not valid");
2245 tts_state_e state_from_daemon = (tts_state_e)state;
2247 if (client->current_state == state_from_daemon) {
2248 SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", client->current_state);
2252 if (NULL != client->state_changed_cb) {
2253 if (NULL != g_check_state_timer) {
2254 ecore_timer_del(g_check_state_timer);
2255 g_check_state_timer = NULL;
2257 g_check_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
2259 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
2262 client->before_state = client->current_state;
2263 client->current_state = state_from_daemon;
2269 int __tts_cb_utt_started(int uid, int utt_id)
2271 tts_client_s* client = tts_client_get_by_uid(uid);
2273 if (NULL == client) {
2274 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2275 return TTS_ERROR_INVALID_PARAMETER;
2278 SLOG(LOG_INFO, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
2280 client->utt_id = utt_id;
2282 /* call callback function */
2283 if (NULL != client->utt_started_cb) {
2284 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance started ");
2285 tts_client_use_callback(client);
2286 client->utt_started_cb(client->tts, client->utt_id, client->utt_started_user_data);
2287 tts_client_not_use_callback(client);
2289 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
2295 int __tts_cb_utt_completed(int uid, int utt_id)
2297 tts_client_s* client = tts_client_get_by_uid(uid);
2299 if (NULL == client) {
2300 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2301 return TTS_ERROR_INVALID_PARAMETER;
2304 SLOG(LOG_INFO, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
2306 client->utt_id = utt_id;
2308 /* call callback function */
2309 if (NULL != client->utt_completeted_cb) {
2310 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance completed ");
2311 tts_client_use_callback(client);
2312 client->utt_completeted_cb(client->tts, client->utt_id, client->utt_completed_user_data);
2313 tts_client_not_use_callback(client);
2315 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance completed ");
2321 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
2323 if (0 != __tts_get_feature_enabled()) {
2324 return TTS_ERROR_NOT_SUPPORTED;
2327 if (NULL == tts || NULL == callback) {
2328 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Input parameter is null");
2329 return TTS_ERROR_INVALID_PARAMETER;
2332 tts_client_s* client = tts_client_get(tts);
2334 if (NULL == client) {
2335 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : A handle is not valid");
2336 return TTS_ERROR_INVALID_PARAMETER;
2339 if (TTS_STATE_CREATED != client->current_state) {
2340 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Current state is not 'Created'.");
2341 return TTS_ERROR_INVALID_STATE;
2344 client->state_changed_cb = callback;
2345 client->state_changed_user_data = user_data;
2347 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
2352 int tts_unset_state_changed_cb(tts_h tts)
2354 if (0 != __tts_get_feature_enabled()) {
2355 return TTS_ERROR_NOT_SUPPORTED;
2359 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Input parameter is null");
2360 return TTS_ERROR_INVALID_PARAMETER;
2363 tts_client_s* client = tts_client_get(tts);
2365 if (NULL == client) {
2366 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : A handle is not valid");
2367 return TTS_ERROR_INVALID_PARAMETER;
2370 if (TTS_STATE_CREATED != client->current_state) {
2371 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Current state is not 'Created'.");
2372 return TTS_ERROR_INVALID_STATE;
2375 client->state_changed_cb = NULL;
2376 client->state_changed_user_data = NULL;
2378 if (NULL != g_check_state_timer) {
2379 ecore_timer_del(g_check_state_timer);
2380 g_check_state_timer = NULL;
2383 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
2388 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
2390 if (0 != __tts_get_feature_enabled()) {
2391 return TTS_ERROR_NOT_SUPPORTED;
2394 if (NULL == tts || NULL == callback) {
2395 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Input parameter is null");
2396 return TTS_ERROR_INVALID_PARAMETER;
2399 tts_client_s* client = tts_client_get(tts);
2401 if (NULL == client) {
2402 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : A handle is not valid");
2403 return TTS_ERROR_INVALID_PARAMETER;
2406 if (TTS_STATE_CREATED != client->current_state) {
2407 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Current state is not 'Created'.");
2408 return TTS_ERROR_INVALID_STATE;
2411 client->utt_started_cb = callback;
2412 client->utt_started_user_data = user_data;
2414 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
2419 int tts_unset_utterance_started_cb(tts_h tts)
2421 if (0 != __tts_get_feature_enabled()) {
2422 return TTS_ERROR_NOT_SUPPORTED;
2426 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Input parameter is null");
2427 return TTS_ERROR_INVALID_PARAMETER;
2430 tts_client_s* client = tts_client_get(tts);
2432 if (NULL == client) {
2433 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : A handle is not valid");
2434 return TTS_ERROR_INVALID_PARAMETER;
2437 if (TTS_STATE_CREATED != client->current_state) {
2438 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Current state is not 'Created'.");
2439 return TTS_ERROR_INVALID_STATE;
2442 client->utt_started_cb = NULL;
2443 client->utt_started_user_data = NULL;
2445 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
2450 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
2452 if (0 != __tts_get_feature_enabled()) {
2453 return TTS_ERROR_NOT_SUPPORTED;
2456 if (NULL == tts || NULL == callback) {
2457 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Input parameter is null");
2458 return TTS_ERROR_INVALID_PARAMETER;
2461 tts_client_s* client = tts_client_get(tts);
2463 if (NULL == client) {
2464 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : A handle is not valid");
2465 return TTS_ERROR_INVALID_PARAMETER;
2468 if (TTS_STATE_CREATED != client->current_state) {
2469 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Current state is not 'Created'.");
2470 return TTS_ERROR_INVALID_STATE;
2473 client->utt_completeted_cb = callback;
2474 client->utt_completed_user_data = user_data;
2476 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
2481 int tts_unset_utterance_completed_cb(tts_h tts)
2483 if (0 != __tts_get_feature_enabled()) {
2484 return TTS_ERROR_NOT_SUPPORTED;
2488 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Input parameter is null");
2489 return TTS_ERROR_INVALID_PARAMETER;
2492 tts_client_s* client = tts_client_get(tts);
2494 if (NULL == client) {
2495 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : A handle is not valid");
2496 return TTS_ERROR_INVALID_PARAMETER;
2499 if (TTS_STATE_CREATED != client->current_state) {
2500 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Current state is not 'Created'.");
2501 return TTS_ERROR_INVALID_STATE;
2504 client->utt_completeted_cb = NULL;
2505 client->utt_completed_user_data = NULL;
2507 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
2511 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
2513 if (0 != __tts_get_feature_enabled()) {
2514 return TTS_ERROR_NOT_SUPPORTED;
2517 if (NULL == tts || NULL == callback) {
2518 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Input parameter is null");
2519 return TTS_ERROR_INVALID_PARAMETER;
2522 tts_client_s* client = tts_client_get(tts);
2524 if (NULL == client) {
2525 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : A handle is not valid");
2526 return TTS_ERROR_INVALID_PARAMETER;
2529 if (TTS_STATE_CREATED != client->current_state) {
2530 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Current state is not 'Created'.");
2531 return TTS_ERROR_INVALID_STATE;
2534 client->error_cb = callback;
2535 client->error_user_data = user_data;
2537 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
2542 int tts_unset_error_cb(tts_h tts)
2544 if (0 != __tts_get_feature_enabled()) {
2545 return TTS_ERROR_NOT_SUPPORTED;
2549 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Input parameter is null");
2550 return TTS_ERROR_INVALID_PARAMETER;
2553 tts_client_s* client = tts_client_get(tts);
2555 if (NULL == client) {
2556 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : A handle is not valid");
2557 return TTS_ERROR_INVALID_PARAMETER;
2560 if (TTS_STATE_CREATED != client->current_state) {
2561 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Current state is not 'Created'.");
2562 return TTS_ERROR_INVALID_STATE;
2565 client->error_cb = NULL;
2566 client->error_user_data = NULL;
2568 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
2573 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
2575 if (0 != __tts_get_feature_enabled()) {
2576 return TTS_ERROR_NOT_SUPPORTED;
2579 if (NULL == tts || NULL == callback) {
2580 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Input parameter is null");
2581 return TTS_ERROR_INVALID_PARAMETER;
2584 tts_client_s* client = tts_client_get(tts);
2586 if (NULL == client) {
2587 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : A handle is not valid");
2588 return TTS_ERROR_INVALID_PARAMETER;
2591 if (TTS_STATE_CREATED != client->current_state) {
2592 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Current state is not 'Created'.");
2593 return TTS_ERROR_INVALID_STATE;
2596 client->default_voice_changed_cb = callback;
2597 client->default_voice_changed_user_data = user_data;
2599 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
2604 int tts_unset_default_voice_changed_cb(tts_h tts)
2606 if (0 != __tts_get_feature_enabled()) {
2607 return TTS_ERROR_NOT_SUPPORTED;
2611 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Input parameter is null");
2612 return TTS_ERROR_INVALID_PARAMETER;
2615 tts_client_s* client = tts_client_get(tts);
2617 if (NULL == client) {
2618 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : A handle is not valid");
2619 return TTS_ERROR_INVALID_PARAMETER;
2622 if (TTS_STATE_CREATED != client->current_state) {
2623 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Current state is not 'Created'.");
2624 return TTS_ERROR_INVALID_STATE;
2627 client->default_voice_changed_cb = NULL;
2628 client->default_voice_changed_user_data = NULL;
2630 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
2635 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
2637 if (0 != __tts_get_feature_enabled()) {
2638 return TTS_ERROR_NOT_SUPPORTED;
2641 if (NULL == tts || NULL == callback) {
2642 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Input parameter is null");
2643 return TTS_ERROR_INVALID_PARAMETER;
2646 tts_client_s* client = tts_client_get(tts);
2648 if (NULL == client) {
2649 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : A handle is not valid");
2650 return TTS_ERROR_INVALID_PARAMETER;
2653 if (TTS_STATE_CREATED != client->current_state) {
2654 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Current state is not 'Created'.");
2655 return TTS_ERROR_INVALID_STATE;
2658 client->engine_changed_cb = callback;
2659 client->engine_changed_user_data = user_data;
2661 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
2666 int tts_unset_engine_changed_cb(tts_h tts)
2668 if (0 != __tts_get_feature_enabled()) {
2669 return TTS_ERROR_NOT_SUPPORTED;
2673 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Input parameter is null");
2674 return TTS_ERROR_INVALID_PARAMETER;
2677 tts_client_s* client = tts_client_get(tts);
2679 if (NULL == client) {
2680 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : A handle is not valid");
2681 return TTS_ERROR_INVALID_PARAMETER;
2684 if (TTS_STATE_CREATED != client->current_state) {
2685 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Current state is not 'Created'.");
2686 return TTS_ERROR_INVALID_STATE;
2689 client->engine_changed_cb = NULL;
2690 client->engine_changed_user_data = NULL;
2692 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
2698 int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
2700 if (0 != __tts_get_feature_enabled()) {
2701 return TTS_ERROR_NOT_SUPPORTED;
2704 SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
2707 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2708 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2709 return TTS_ERROR_INVALID_PARAMETER;
2712 tts_client_s* client = tts_client_get(tts);
2714 if (NULL == client) {
2715 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2716 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2717 return TTS_ERROR_INVALID_PARAMETER;
2720 if (TTS_STATE_CREATED == client->current_state) {
2721 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2722 return TTS_ERROR_INVALID_STATE;
2725 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2726 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2727 return TTS_ERROR_INVALID_STATE;
2732 bool is_prepared = false;
2734 ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
2736 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2737 client->current_state = TTS_STATE_CREATED;
2738 if (0 == tts_prepare_sync(tts)) {
2740 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2742 } else if (TTS_ERROR_TIMED_OUT != ret) {
2743 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2746 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add pcm : %s", __tts_get_error_code(ret));
2749 if (TTS_RETRY_COUNT == count) {
2750 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2757 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2759 return TTS_ERROR_NONE;
2762 int tts_play_pcm(tts_h tts)
2764 if (0 != __tts_get_feature_enabled()) {
2765 return TTS_ERROR_NOT_SUPPORTED;
2768 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
2771 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2772 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2773 return TTS_ERROR_INVALID_PARAMETER;
2776 tts_client_s* client = tts_client_get(tts);
2778 if (NULL == client) {
2779 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2780 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2781 return TTS_ERROR_INVALID_PARAMETER;
2784 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
2785 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2786 return TTS_ERROR_INVALID_STATE;
2789 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2790 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2791 return TTS_ERROR_INVALID_STATE;
2796 bool is_prepared = false;
2798 ret = tts_dbus_request_play_pcm(client->uid);
2800 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2801 client->current_state = TTS_STATE_CREATED;
2802 if (0 == tts_prepare_sync(tts)) {
2804 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2806 } else if (TTS_ERROR_TIMED_OUT != ret) {
2807 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2810 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play pcm : %s", __tts_get_error_code(ret));
2813 if (TTS_RETRY_COUNT == count) {
2814 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2821 client->before_state = client->current_state;
2822 client->current_state = TTS_STATE_PLAYING;
2824 if (NULL != client->state_changed_cb) {
2825 tts_client_use_callback(client);
2826 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2827 tts_client_not_use_callback(client);
2828 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
2831 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2833 return TTS_ERROR_NONE;
2836 int tts_stop_pcm(tts_h tts)
2838 if (0 != __tts_get_feature_enabled()) {
2839 return TTS_ERROR_NOT_SUPPORTED;
2842 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
2845 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2846 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2847 return TTS_ERROR_INVALID_PARAMETER;
2850 tts_client_s* client = tts_client_get(tts);
2852 if (NULL == client) {
2853 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2854 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2855 return TTS_ERROR_INVALID_PARAMETER;
2858 if (TTS_STATE_CREATED == client->current_state) {
2859 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2860 return TTS_ERROR_INVALID_STATE;
2863 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2864 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2865 return TTS_ERROR_INVALID_STATE;
2870 bool is_prepared = false;
2872 ret = tts_dbus_request_stop_pcm(client->uid);
2874 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2875 client->current_state = TTS_STATE_CREATED;
2876 if (0 == tts_prepare_sync(tts)) {
2878 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2880 } else if (TTS_ERROR_TIMED_OUT != ret) {
2881 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2884 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop pcm : %s", __tts_get_error_code(ret));
2887 if (TTS_RETRY_COUNT == count) {
2888 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2895 client->before_state = client->current_state;
2896 client->current_state = TTS_STATE_READY;
2898 if (NULL != client->state_changed_cb) {
2899 tts_client_use_callback(client);
2900 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2901 tts_client_not_use_callback(client);
2902 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
2905 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2907 return TTS_ERROR_NONE;
2911 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
2913 if (0 != __tts_get_feature_enabled()) {
2914 return TTS_ERROR_NOT_SUPPORTED;
2917 SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
2920 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2921 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2922 return TTS_ERROR_INVALID_PARAMETER;
2925 if (NULL == text_repeat || NULL == utt_id) {
2926 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null.");
2927 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2928 return TTS_ERROR_INVALID_PARAMETER;
2931 *text_repeat = NULL;
2934 tts_client_s* client = tts_client_get(tts);
2936 if (NULL == client) {
2937 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2938 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2939 return TTS_ERROR_INVALID_PARAMETER;
2942 if (TTS_STATE_READY != client->current_state) {
2943 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", client->current_state);
2944 return TTS_ERROR_INVALID_STATE;
2947 /* Clear the legacy and Add texts to be played repeatedly */
2949 ret = tts_stop(tts);
2950 if (TTS_ERROR_NONE != ret) {
2951 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to clear the legacy");
2955 if (NULL != client->text_repeat) {
2956 char* tmp_text = strdup(client->text_repeat);
2957 char* tmp_lang = NULL;
2958 if (NULL != g_language) {
2959 tmp_lang = strdup(g_language);
2961 ret = tts_add_text(tts, tmp_text, tmp_lang, g_voice_type, g_speed, utt_id);
2962 if (TTS_ERROR_NONE != ret) {
2963 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add texts for repetition.");
2964 if (NULL != tmp_text) {
2968 if (NULL != tmp_lang) {
2974 *text_repeat = strdup(client->text_repeat);
2975 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] text to repeat(%s), utt_id(%d)", (*text_repeat) ? *text_repeat : "NULL", *utt_id);
2976 if (NULL != tmp_text) {
2980 if (NULL != tmp_lang) {
2985 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] There is no previous added texts. Please add texts");
2986 return TTS_ERROR_OPERATION_FAILED;
2989 /* Play added texts */
2990 ret = tts_play(tts);
2991 if (TTS_ERROR_NONE != ret) {
2992 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play texts for repetition.");
2993 if (NULL != *text_repeat) {
2995 *text_repeat = NULL;
3001 return TTS_ERROR_NONE;