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>
25 #include "tts_client.h"
26 #include "tts_config_mgr.h"
30 #include "tts_internal.h"
32 static bool g_screen_reader;
34 static int g_feature_enabled = -1;
36 static bool g_err_callback_status = false;
38 static int g_max_text_size = -1;
40 static Ecore_Timer* g_check_state_timer = NULL;
44 static char* g_language = NULL;
46 static int g_voice_type = -1;
48 static int g_speed = -1;
51 /* Function definition */
52 static Eina_Bool __tts_notify_state_changed(void *data);
53 static Eina_Bool __tts_notify_error(void *data);
60 static int __tts_get_feature_enabled()
62 if (0 == g_feature_enabled) {
63 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
64 return TTS_ERROR_NOT_SUPPORTED;
65 } else if (-1 == g_feature_enabled) {
66 bool tts_supported = false;
67 if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
68 if (false == tts_supported) {
69 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
70 g_feature_enabled = 0;
71 return TTS_ERROR_NOT_SUPPORTED;
74 g_feature_enabled = 1;
76 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
77 return TTS_ERROR_NOT_SUPPORTED;
84 static const char* __tts_get_error_code(tts_error_e err)
87 case TTS_ERROR_NONE: return "TTS_ERROR_NONE";
88 case TTS_ERROR_OUT_OF_MEMORY: return "TTS_ERROR_OUT_OF_MEMORY";
89 case TTS_ERROR_IO_ERROR: return "TTS_ERROR_IO_ERROR";
90 case TTS_ERROR_INVALID_PARAMETER: return "TTS_ERROR_INVALID_PARAMETER";
91 case TTS_ERROR_OUT_OF_NETWORK: return "TTS_ERROR_OUT_OF_NETWORK";
92 case TTS_ERROR_TIMED_OUT: return "TTS_ERROR_TIMED_OUT";
93 case TTS_ERROR_PERMISSION_DENIED: return "TTS_ERROR_PERMISSION_DENIED";
94 case TTS_ERROR_NOT_SUPPORTED: return "TTS_ERROR_NOT_SUPPORTED";
95 case TTS_ERROR_INVALID_STATE: return "TTS_ERROR_INVALID_STATE";
96 case TTS_ERROR_INVALID_VOICE: return "TTS_ERROR_INVALID_VOICE";
97 case TTS_ERROR_ENGINE_NOT_FOUND: return "TTS_ERROR_ENGINE_NOT_FOUND";
98 case TTS_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED";
99 case TTS_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
100 case TTS_ERROR_NOT_SUPPORTED_FEATURE: return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
101 case TTS_ERROR_SERVICE_RESET: return "TTS_ERROR_SERVICE_RESET";
103 return "Invalid error code";
108 static int __tts_convert_config_error_code(tts_config_error_e code)
110 if (code == TTS_CONFIG_ERROR_NONE) return TTS_ERROR_NONE;
111 if (code == TTS_CONFIG_ERROR_OUT_OF_MEMORY) return TTS_ERROR_OUT_OF_MEMORY;
112 if (code == TTS_CONFIG_ERROR_IO_ERROR) return TTS_ERROR_IO_ERROR;
113 if (code == TTS_CONFIG_ERROR_INVALID_PARAMETER) return TTS_ERROR_INVALID_PARAMETER;
114 if (code == TTS_CONFIG_ERROR_INVALID_STATE) return TTS_ERROR_INVALID_STATE;
115 if (code == TTS_CONFIG_ERROR_INVALID_VOICE) return TTS_ERROR_INVALID_VOICE;
116 if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND) return TTS_ERROR_ENGINE_NOT_FOUND;
117 if (code == TTS_CONFIG_ERROR_OPERATION_FAILED) return TTS_ERROR_OPERATION_FAILED;
118 if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE) return TTS_ERROR_NOT_SUPPORTED_FEATURE;
124 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)
126 SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
127 before_lang, before_voice_type, language, voice_type);
129 GList* client_list = NULL;
130 client_list = tts_client_get_client_list();
133 tts_client_s *data = NULL;
135 if (g_list_length(client_list) > 0) {
136 /* Get a first item */
137 iter = g_list_first(client_list);
139 while (NULL != iter) {
141 if (NULL != data->default_voice_changed_cb) {
142 SLOG(LOG_DEBUG, TAG_TTSC, "Call default voice changed callback : uid(%d)", data->uid);
143 data->default_voice_changed_cb(data->tts, before_lang, before_voice_type,
144 language, voice_type, data->default_voice_changed_user_data);
147 /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
148 if (0 != strncmp(before_lang, language, strlen(before_lang))) {
149 if (NULL != data->text_repeat) {
150 free(data->text_repeat);
151 data->text_repeat = NULL;
156 iter = g_list_next(iter);
163 static Eina_Bool __reconnect_by_engine_changed(void* data)
165 tts_h tts = (tts_h)data;
167 tts_client_s* client = tts_client_get(tts);
168 if (NULL == client) {
169 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
173 if (TTS_STATE_READY != client->current_state) {
178 int ret = tts_unprepare(tts);
180 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
182 ret = tts_prepare(tts);
184 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
190 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)
192 tts_h tts = (tts_h)user_data;
194 tts_client_s* client = tts_client_get(tts);
195 if (NULL == client) {
196 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
200 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
201 if (NULL != setting) SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
202 if (NULL != language) SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
203 SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
205 /* When the default engine is changed, please unload the old engine and load the new one. */
208 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
211 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
214 ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
215 } else if (TTS_STATE_READY == client->current_state) {
216 ret = tts_unprepare(tts);
218 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
220 ret = tts_prepare(tts);
222 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
226 /* call callback function */
227 if (NULL != client->engine_changed_cb) {
228 client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
230 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function for changed engine");
236 void __tts_unset_all_callbacks(tts_h tts)
238 SLOG(LOG_INFO, TAG_TTSC, "@@@ unset all callbacks");
240 tts_unset_state_changed_cb(tts);
241 tts_unset_utterance_started_cb(tts);
242 tts_unset_utterance_completed_cb(tts);
243 tts_unset_error_cb(tts);
244 tts_unset_default_voice_changed_cb(tts);
245 tts_unset_engine_changed_cb(tts);
247 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
250 int tts_create(tts_h* tts)
252 if (0 != __tts_get_feature_enabled()) {
253 return TTS_ERROR_NOT_SUPPORTED;
256 SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
260 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
261 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
262 return TTS_ERROR_INVALID_PARAMETER;
265 if (0 == tts_client_get_size()) {
266 if (0 != tts_dbus_open_connection()) {
267 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection");
268 return TTS_ERROR_OPERATION_FAILED;
272 if (0 != tts_client_new(tts)) {
273 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
274 return TTS_ERROR_OUT_OF_MEMORY;
277 tts_client_s* client = tts_client_get(*tts);
278 if (NULL == client) {
279 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
280 return TTS_ERROR_OPERATION_FAILED;
283 int ret = tts_config_mgr_initialize(client->uid);
285 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
286 tts_client_destroy(*tts);
287 return __tts_convert_config_error_code(ret);
290 ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
292 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
293 tts_client_destroy(*tts);
294 return __tts_convert_config_error_code(ret);
297 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
298 SLOG(LOG_DEBUG, TAG_TTSC, " ");
300 return TTS_ERROR_NONE;
303 int tts_destroy(tts_h tts)
305 if (0 != __tts_get_feature_enabled()) {
306 return TTS_ERROR_NOT_SUPPORTED;
309 SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
312 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
313 return TTS_ERROR_INVALID_PARAMETER;
316 tts_client_s* client = tts_client_get(tts);
319 if (NULL == client) {
320 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
321 return TTS_ERROR_INVALID_PARAMETER;
324 /* check used callback */
325 if (0 != tts_client_get_use_callback(client)) {
326 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot destroy in Callback function");
327 return TTS_ERROR_OPERATION_FAILED;
330 tts_config_mgr_finalize(client->uid);
334 int screen_reader = -1;
337 switch (client->current_state) {
338 case TTS_STATE_PAUSED:
339 case TTS_STATE_PLAYING:
340 case TTS_STATE_READY:
341 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
343 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
345 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);
346 g_screen_reader = (bool)screen_reader;
348 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
350 ret = tts_dbus_request_finalize(client->uid);
353 if (TTS_ERROR_TIMED_OUT != ret) {
354 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
357 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize");
360 if (TTS_RETRY_COUNT == count) {
361 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
369 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
372 client->before_state = client->current_state;
373 client->current_state = TTS_STATE_CREATED;
375 case TTS_STATE_CREATED:
376 if (NULL != client->conn_timer) {
377 SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted");
378 ecore_timer_del(client->conn_timer);
379 client->conn_timer = NULL;
381 /* Unset registered callbacks */
382 __tts_unset_all_callbacks(tts);
385 tts_client_destroy(tts);
392 if (0 == tts_client_get_size()) {
393 if (0 != tts_dbus_close_connection()) {
394 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
398 if (NULL != g_language) {
403 /* Delete state timer before destroying handle */
404 if (NULL != g_check_state_timer) {
405 ecore_timer_del(g_check_state_timer);
406 g_check_state_timer = NULL;
411 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
413 return TTS_ERROR_NONE;
417 void __tts_screen_reader_changed_cb(bool value)
419 g_screen_reader = value;
423 int tts_set_mode(tts_h tts, tts_mode_e mode)
425 if (0 != __tts_get_feature_enabled()) {
426 return TTS_ERROR_NOT_SUPPORTED;
429 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
431 tts_client_s* client = tts_client_get(tts);
434 if (NULL == client) {
435 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
436 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
437 return TTS_ERROR_INVALID_PARAMETER;
441 if (client->current_state != TTS_STATE_CREATED) {
442 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
443 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
444 SLOG(LOG_DEBUG, TAG_TTSC, " ");
445 return TTS_ERROR_INVALID_STATE;
448 if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
451 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
452 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
453 SLOG(LOG_DEBUG, TAG_TTSC, " ");
454 return TTS_ERROR_INVALID_PARAMETER;
457 if (TTS_MODE_SCREEN_READER == mode) {
460 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
462 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader");
463 return TTS_ERROR_OPERATION_FAILED;
465 g_screen_reader = (bool)screen_reader;
466 tts_config_set_screen_reader_callback(client->uid, __tts_screen_reader_changed_cb);
468 tts_config_unset_screen_reader_callback(client->uid);
471 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
473 return TTS_ERROR_NONE;
476 int tts_get_mode(tts_h tts, tts_mode_e* mode)
478 if (0 != __tts_get_feature_enabled()) {
479 return TTS_ERROR_NOT_SUPPORTED;
482 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
484 tts_client_s* client = tts_client_get(tts);
487 if (NULL == client) {
488 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
489 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
490 SLOG(LOG_DEBUG, TAG_TTSC, " ");
491 return TTS_ERROR_INVALID_PARAMETER;
495 if (client->current_state != TTS_STATE_CREATED) {
496 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
497 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
498 SLOG(LOG_DEBUG, TAG_TTSC, " ");
499 return TTS_ERROR_INVALID_STATE;
503 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter(mode) is NULL");
504 return TTS_ERROR_INVALID_PARAMETER;
507 *mode = client->mode;
509 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
510 SLOG(LOG_DEBUG, TAG_TTSC, " ");
512 return TTS_ERROR_NONE;
515 int tts_set_credential(tts_h tts, const char* credential)
517 if (0 != __tts_get_feature_enabled()) {
518 return TTS_ERROR_NOT_SUPPORTED;
521 if (NULL == tts || NULL == credential) {
522 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
523 return TTS_ERROR_INVALID_PARAMETER;
526 tts_client_s* client = tts_client_get(tts);
528 if (NULL == client) {
529 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
530 return TTS_ERROR_INVALID_PARAMETER;
533 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
534 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
535 return TTS_ERROR_INVALID_STATE;
538 if (NULL != client->credential) {
539 free(client->credential);
540 client->credential = NULL;
542 client->credential = strdup(credential);
544 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
546 return TTS_ERROR_NONE;
550 int tts_set_server_tts(tts_h tts, const char* credential)
552 if (0 != __tts_get_feature_enabled()) {
553 return TTS_ERROR_NOT_SUPPORTED;
557 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
558 return TTS_ERROR_INVALID_PARAMETER;
561 tts_client_s* client = tts_client_get(tts);
563 if (NULL == client) {
564 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
565 return TTS_ERROR_INVALID_PARAMETER;
568 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
569 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
570 return TTS_ERROR_INVALID_STATE;
573 if (NULL != client->credential) {
574 free(client->credential);
575 client->credential = NULL;
578 client->internal = true;
581 if (NULL != credential) {
582 key = strdup("EnableServerTTS");
583 client->credential = strdup(credential);
584 if (NULL == client->credential) {
585 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
590 return TTS_ERROR_OUT_OF_MEMORY;
593 key = strdup("DisableServerTTS");
597 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
598 return TTS_ERROR_OUT_OF_MEMORY;
603 int ret = app_manager_get_app_id(pid, &appid);
604 if (0 != ret || NULL == appid) {
605 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
612 return TTS_ERROR_OPERATION_FAILED;
615 ret = tts_set_private_data(tts, key, appid);
617 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
630 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
632 return TTS_ERROR_NONE;
636 static Eina_Bool __tts_connect_daemon(void *data)
638 tts_h tts = (tts_h)data;
639 tts_client_s* client = tts_client_get(tts);
642 if (NULL == client) {
643 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
648 if (0 != tts_dbus_request_hello(client->uid)) {
652 SLOG(LOG_INFO, TAG_TTSC, "@@@ Connect daemon");
654 /* do request initialize */
656 bool credential_needed = false;
658 ret = tts_dbus_request_initialize(client->uid, &credential_needed);
660 if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
661 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
663 client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
666 ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
667 if (client->conn_timer) {
668 ecore_timer_del(client->conn_timer);
669 client->conn_timer = NULL;
673 } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
674 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
676 client->reason = TTS_ERROR_PERMISSION_DENIED;
679 ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
680 if (client->conn_timer) {
681 ecore_timer_del(client->conn_timer);
682 client->conn_timer = NULL;
686 } else if (TTS_ERROR_NONE != ret) {
687 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
691 /* success to connect tts-daemon */
692 client->credential_needed = credential_needed;
693 SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
696 if (client->conn_timer) {
697 ecore_timer_del(client->conn_timer);
698 client->conn_timer = NULL;
701 client = tts_client_get(tts);
703 if (NULL == client) {
704 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
708 client->before_state = client->current_state;
709 client->current_state = TTS_STATE_READY;
711 if (NULL != client->state_changed_cb) {
712 tts_client_use_callback(client);
713 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
714 tts_client_not_use_callback(client);
716 SLOG(LOG_WARN, TAG_TTSC, "State changed callback is NULL");
719 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
724 int tts_prepare(tts_h tts)
726 if (0 != __tts_get_feature_enabled()) {
727 return TTS_ERROR_NOT_SUPPORTED;
730 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
732 tts_client_s* client = tts_client_get(tts);
735 if (NULL == client) {
736 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
737 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
738 return TTS_ERROR_INVALID_PARAMETER;
742 if (client->current_state != TTS_STATE_CREATED) {
743 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
744 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
745 return TTS_ERROR_INVALID_STATE;
748 ecore_thread_main_loop_begin();
749 if (client->conn_timer) {
750 ecore_timer_del(client->conn_timer);
751 client->conn_timer = NULL;
753 client->conn_timer = ecore_timer_add(0.02, __tts_connect_daemon, (void*)tts);
754 ecore_thread_main_loop_end();
756 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
758 return TTS_ERROR_NONE;
762 int tts_prepare_sync(tts_h tts)
764 if (0 != __tts_get_feature_enabled()) {
765 return TTS_ERROR_NOT_SUPPORTED;
768 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
770 tts_client_s* client = tts_client_get(tts);
773 if (NULL == client) {
774 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
775 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
776 return TTS_ERROR_INVALID_PARAMETER;
780 if (client->current_state != TTS_STATE_CREATED) {
781 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
782 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
783 return TTS_ERROR_INVALID_STATE;
787 while (EINA_TRUE == __tts_connect_daemon((void*)tts) && TTS_CONNECTION_RETRY_COUNT > cnt) {
791 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
793 if (TTS_CONNECTION_RETRY_COUNT == cnt) {
794 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect daemon");
795 return TTS_ERROR_OPERATION_FAILED;
798 return TTS_ERROR_NONE;
802 int tts_unprepare(tts_h tts)
804 if (0 != __tts_get_feature_enabled()) {
805 return TTS_ERROR_NOT_SUPPORTED;
808 SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
810 tts_client_s* client = tts_client_get(tts);
813 if (NULL == client) {
814 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
815 return TTS_ERROR_INVALID_PARAMETER;
819 if (client->current_state != TTS_STATE_READY) {
820 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'READY'");
821 return TTS_ERROR_INVALID_STATE;
826 int screen_reader = -1;
828 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
830 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
832 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);
833 g_screen_reader = (bool)screen_reader;
836 bool is_prepared = false;
837 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
839 ret = tts_dbus_request_finalize(client->uid);
842 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
843 client->current_state = TTS_STATE_CREATED;
844 if (0 == tts_prepare_sync(tts)) {
846 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
848 } else if (TTS_ERROR_TIMED_OUT != ret) {
849 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
852 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize : %s", __tts_get_error_code(ret));
855 if (TTS_RETRY_COUNT == count) {
856 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
864 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
867 client->before_state = client->current_state;
868 client->current_state = TTS_STATE_CREATED;
870 if (NULL != client->state_changed_cb) {
871 tts_client_use_callback(client);
872 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
873 tts_client_not_use_callback(client);
874 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
877 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
879 return TTS_ERROR_NONE;
882 bool __tts_supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
884 tts_h tts = (tts_h)user_data;
886 tts_client_s* client = tts_client_get(tts);
887 if (NULL == client) {
888 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
892 /* call callback function */
893 if (NULL != client->supported_voice_cb) {
894 return client->supported_voice_cb(tts, language, type, client->supported_voice_user_data);
896 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of supported voice");
902 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
904 if (0 != __tts_get_feature_enabled()) {
905 return TTS_ERROR_NOT_SUPPORTED;
908 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported voices");
910 if (NULL == tts || NULL == callback) {
911 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
912 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
913 return TTS_ERROR_INVALID_PARAMETER;
916 tts_client_s* client = tts_client_get(tts);
919 if (NULL == client) {
920 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
921 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
922 return TTS_ERROR_INVALID_PARAMETER;
926 char* current_engine = NULL;
927 ret = tts_config_mgr_get_engine(¤t_engine);
929 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
930 return __tts_convert_config_error_code(ret);
933 client->supported_voice_cb = callback;
934 client->supported_voice_user_data = user_data;
936 ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts);
938 if (NULL != current_engine) {
939 free(current_engine);
940 current_engine = NULL;
943 client->supported_voice_cb = NULL;
944 client->supported_voice_user_data = NULL;
947 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
948 ret = TTS_ERROR_OPERATION_FAILED;
951 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
956 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
958 if (0 != __tts_get_feature_enabled()) {
959 return TTS_ERROR_NOT_SUPPORTED;
962 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
965 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
966 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
967 return TTS_ERROR_INVALID_PARAMETER;
970 tts_client_s* client = tts_client_get(tts);
972 if (NULL == client) {
973 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
974 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
975 return TTS_ERROR_INVALID_PARAMETER;
978 /* Request call remote method */
980 ret = tts_config_mgr_get_voice(lang, vctype);
982 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
983 return __tts_convert_config_error_code(ret);
985 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
988 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
993 int tts_get_max_text_size(tts_h tts, unsigned int* size)
995 if (0 != __tts_get_feature_enabled()) {
996 return TTS_ERROR_NOT_SUPPORTED;
999 if (NULL == tts || NULL == size) {
1000 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Input parameter is null");
1001 return TTS_ERROR_INVALID_PARAMETER;
1004 tts_client_s* client = tts_client_get(tts);
1006 if (NULL == client) {
1007 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : A handle is not valid");
1008 return TTS_ERROR_INVALID_PARAMETER;
1011 if (TTS_STATE_READY != client->current_state) {
1012 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Current state is NOT 'READY'.");
1013 return TTS_ERROR_INVALID_STATE;
1016 if (0 != tts_config_mgr_get_max_text_size(size)) {
1017 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
1018 return TTS_ERROR_INVALID_PARAMETER;
1021 g_max_text_size = (int)*size;
1023 SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
1024 return TTS_ERROR_NONE;
1027 int tts_get_state(tts_h tts, tts_state_e* state)
1029 if (0 != __tts_get_feature_enabled()) {
1030 return TTS_ERROR_NOT_SUPPORTED;
1033 if (NULL == tts || NULL == state) {
1034 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : Input parameter is null");
1035 return TTS_ERROR_INVALID_PARAMETER;
1038 tts_client_s* client = tts_client_get(tts);
1040 if (NULL == client) {
1041 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1042 return TTS_ERROR_INVALID_PARAMETER;
1045 *state = client->current_state;
1048 case TTS_STATE_CREATED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Created'"); break;
1049 case TTS_STATE_READY: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Ready'"); break;
1050 case TTS_STATE_PLAYING: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Playing'"); break;
1051 case TTS_STATE_PAUSED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Paused'"); break;
1052 default: SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value"); break;
1055 return TTS_ERROR_NONE;
1058 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
1060 if (0 != __tts_get_feature_enabled()) {
1061 return TTS_ERROR_NOT_SUPPORTED;
1064 if (NULL == tts || NULL == min || NULL == normal || NULL == max) {
1065 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1066 return TTS_ERROR_INVALID_PARAMETER;
1069 tts_client_s* client = tts_client_get(tts);
1071 if (NULL == client) {
1072 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1073 return TTS_ERROR_INVALID_PARAMETER;
1076 *min = TTS_SPEED_MIN;
1077 *normal = TTS_SPEED_NORMAL;
1078 *max = TTS_SPEED_MAX;
1080 return TTS_ERROR_NONE;
1083 int tts_get_error_message(tts_h tts, char** err_msg)
1085 if (0 != __tts_get_feature_enabled()) {
1086 return TTS_ERROR_NOT_SUPPORTED;
1089 if (NULL == tts || NULL == err_msg) {
1090 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1091 return TTS_ERROR_INVALID_PARAMETER;
1094 tts_client_s* client = tts_client_get(tts);
1096 if (NULL == client) {
1097 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
1098 return TTS_ERROR_INVALID_PARAMETER;
1101 if (NULL != client->err_msg) {
1102 *err_msg = strdup(client->err_msg);
1103 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg);
1106 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)");
1109 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1111 return TTS_ERROR_NONE;
1114 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
1116 SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
1118 if (0 != __tts_get_feature_enabled()) {
1119 return TTS_ERROR_NOT_SUPPORTED;
1123 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Speed should not be negative(%d)", speed);
1124 return TTS_ERROR_INVALID_PARAMETER;
1127 if (voice_type < 0) {
1128 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Voice type should not be negative(%d)", voice_type);
1129 return TTS_ERROR_INVALID_PARAMETER;
1132 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Add text");
1134 if (NULL == tts || NULL == utt_id) {
1135 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
1136 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1137 return TTS_ERROR_INVALID_PARAMETER;
1140 tts_client_s* client = tts_client_get(tts);
1142 if (NULL == client) {
1143 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1144 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1145 return TTS_ERROR_INVALID_PARAMETER;
1148 if (TTS_STATE_CREATED == client->current_state) {
1149 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1150 return TTS_ERROR_INVALID_STATE;
1153 if (-1 == g_max_text_size) {
1154 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
1155 if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
1156 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
1157 return TTS_ERROR_INVALID_PARAMETER;
1161 if (0 == g_max_text_size) {
1162 if (strlen(text) <= 0) {
1163 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d", g_max_text_size);
1164 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
1165 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1166 return TTS_ERROR_INVALID_PARAMETER;
1169 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
1170 if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
1171 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
1172 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1173 return TTS_ERROR_INVALID_PARAMETER;
1177 if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
1178 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] speed value(%d) is invalid.", speed);
1179 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1180 return TTS_ERROR_INVALID_PARAMETER;
1183 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1184 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1185 return TTS_ERROR_INVALID_STATE;
1188 if (true == client->credential_needed && NULL == client->credential) {
1189 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1190 return TTS_ERROR_PERMISSION_DENIED;
1193 /* check valid utf8 */
1197 dbus_error_init(&err);
1199 valid = dbus_validate_utf8(text, &err);
1200 if (dbus_error_is_set(&err)) {
1201 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
1202 dbus_error_free(&err);
1203 return TTS_ERROR_INVALID_PARAMETER;
1206 if (valid != true) {
1207 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
1208 return TTS_ERROR_INVALID_PARAMETER;
1210 SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
1212 /* save texts for repetition */
1213 if (NULL != client->text_repeat) {
1214 free(client->text_repeat);
1215 client->text_repeat = NULL;
1218 client->text_repeat = strdup(text);
1220 if (NULL != g_language) {
1224 if (NULL == language)
1227 g_language = strdup(language);
1229 g_voice_type = voice_type;
1232 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);
1234 /* change default language value */
1237 if (NULL == language)
1238 temp = strdup("default");
1240 temp = strdup(language);
1242 client->current_utt_id++;
1243 if (client->current_utt_id == 10000) {
1244 client->current_utt_id = 1;
1250 bool is_prepared = false;
1252 ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
1255 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1256 client->current_state = TTS_STATE_CREATED;
1257 if (0 == tts_prepare_sync(tts)) {
1259 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1261 } else if (TTS_ERROR_TIMED_OUT != ret) {
1262 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1265 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add text : %s", __tts_get_error_code(ret));
1268 if (TTS_RETRY_MIN_COUNT == count) {
1269 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1275 *utt_id = client->current_utt_id;
1284 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1290 static void __tts_play_async(void *data)
1292 tts_h tts = (tts_h)data;
1293 tts_client_s* client = tts_client_get(tts);
1296 if (NULL == client) {
1297 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1303 bool is_prepared = false;
1305 ret = tts_dbus_request_play(client->uid, client->credential);
1307 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1308 client->current_state = TTS_STATE_CREATED;
1309 if (0 == tts_prepare_sync(tts)) {
1311 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1313 } else if (TTS_ERROR_TIMED_OUT != ret) {
1314 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1317 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1320 if (TTS_RETRY_COUNT == count) {
1321 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1329 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
1331 client->reason = ret;
1332 client->utt_id = -1;
1334 ecore_timer_add(0, __tts_notify_error, client->tts);
1338 client->before_state = client->current_state;
1339 client->current_state = TTS_STATE_PLAYING;
1341 if (NULL != client->state_changed_cb) {
1342 tts_client_use_callback(client);
1343 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1344 tts_client_not_use_callback(client);
1345 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1348 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1353 int tts_play_async(tts_h tts)
1355 if (0 != __tts_get_feature_enabled()) {
1356 return TTS_ERROR_NOT_SUPPORTED;
1359 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play tts");
1362 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1363 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1364 return TTS_ERROR_INVALID_PARAMETER;
1367 tts_client_s* client = tts_client_get(tts);
1369 if (NULL == client) {
1370 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1371 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1372 return TTS_ERROR_INVALID_PARAMETER;
1375 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1376 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1377 return TTS_ERROR_INVALID_STATE;
1380 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1381 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1382 return TTS_ERROR_INVALID_STATE;
1385 if (true == client->credential_needed && NULL == client->credential) {
1386 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1387 return TTS_ERROR_PERMISSION_DENIED;
1390 ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
1392 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1394 return TTS_ERROR_NONE;
1397 int tts_play(tts_h tts)
1399 if (0 != __tts_get_feature_enabled()) {
1400 return TTS_ERROR_NOT_SUPPORTED;
1403 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
1406 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1407 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1408 return TTS_ERROR_INVALID_PARAMETER;
1411 tts_client_s* client = tts_client_get(tts);
1413 if (NULL == client) {
1414 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1415 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1416 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1417 return TTS_ERROR_INVALID_PARAMETER;
1420 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1421 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1422 return TTS_ERROR_INVALID_STATE;
1425 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1426 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1427 return TTS_ERROR_INVALID_STATE;
1430 if (true == client->credential_needed && NULL == client->credential) {
1431 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1432 return TTS_ERROR_PERMISSION_DENIED;
1437 bool is_prepared = false;
1439 ret = tts_dbus_request_play(client->uid, client->credential);
1442 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1443 client->current_state = TTS_STATE_CREATED;
1444 if (0 == tts_prepare_sync(tts)) {
1446 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1448 } else if (TTS_ERROR_TIMED_OUT != ret) {
1449 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1452 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1455 if (TTS_RETRY_COUNT == count) {
1456 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1464 client->before_state = client->current_state;
1465 client->current_state = TTS_STATE_PLAYING;
1467 if (NULL != client->state_changed_cb) {
1468 tts_client_use_callback(client);
1469 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1470 tts_client_not_use_callback(client);
1471 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1474 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1476 return TTS_ERROR_NONE;
1479 static void __tts_stop_async(void *data)
1481 tts_h tts = (tts_h)data;
1482 tts_client_s* client = tts_client_get(tts);
1485 if (NULL == client) {
1486 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1492 bool is_prepared = false;
1494 ret = tts_dbus_request_stop(client->uid);
1496 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1497 client->current_state = TTS_STATE_CREATED;
1498 if (0 == tts_prepare_sync(tts)) {
1500 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1502 } else if (TTS_ERROR_TIMED_OUT != ret) {
1503 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1506 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1509 if (TTS_RETRY_COUNT == count) {
1510 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1518 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
1520 client->reason = ret;
1521 client->utt_id = -1;
1523 ecore_timer_add(0, __tts_notify_error, client->tts);
1527 client->before_state = client->current_state;
1528 client->current_state = TTS_STATE_READY;
1530 if (NULL != client->state_changed_cb) {
1531 tts_client_use_callback(client);
1532 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1533 tts_client_not_use_callback(client);
1534 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1537 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1542 int tts_stop_aync(tts_h tts)
1544 if (0 != __tts_get_feature_enabled()) {
1545 return TTS_ERROR_NOT_SUPPORTED;
1548 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop tts");
1551 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1552 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1553 return TTS_ERROR_INVALID_PARAMETER;
1556 tts_client_s* client = tts_client_get(tts);
1558 if (NULL == client) {
1559 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1560 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1561 return TTS_ERROR_INVALID_PARAMETER;
1564 if (TTS_STATE_CREATED == client->current_state) {
1565 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1566 return TTS_ERROR_INVALID_STATE;
1569 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1570 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1571 return TTS_ERROR_INVALID_STATE;
1574 ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
1576 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1578 return TTS_ERROR_NONE;
1581 int tts_stop(tts_h tts)
1583 if (0 != __tts_get_feature_enabled()) {
1584 return TTS_ERROR_NOT_SUPPORTED;
1587 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
1590 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1591 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1592 return TTS_ERROR_INVALID_PARAMETER;
1595 tts_client_s* client = tts_client_get(tts);
1597 if (NULL == client) {
1598 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1599 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1600 return TTS_ERROR_INVALID_PARAMETER;
1603 if (TTS_STATE_CREATED == client->current_state) {
1604 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1605 return TTS_ERROR_INVALID_STATE;
1608 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1609 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1610 return TTS_ERROR_INVALID_STATE;
1615 bool is_prepared = false;
1617 ret = tts_dbus_request_stop(client->uid);
1620 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1621 client->current_state = TTS_STATE_CREATED;
1622 if (0 == tts_prepare_sync(tts)) {
1624 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1626 } else if (TTS_ERROR_TIMED_OUT != ret) {
1627 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1630 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1633 if (TTS_RETRY_COUNT == count) {
1634 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1642 client->before_state = client->current_state;
1643 client->current_state = TTS_STATE_READY;
1645 if (NULL != client->state_changed_cb) {
1646 tts_client_use_callback(client);
1647 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1648 tts_client_not_use_callback(client);
1649 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1652 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1654 return TTS_ERROR_NONE;
1657 static void __tts_pause_async(void *data)
1659 tts_h tts = (tts_h)data;
1660 tts_client_s* client = tts_client_get(tts);
1663 if (NULL == client) {
1664 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1670 bool is_prepared = false;
1672 ret = tts_dbus_request_pause(client->uid);
1674 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1675 client->current_state = TTS_STATE_CREATED;
1676 if (0 == tts_prepare_sync(tts)) {
1678 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1680 } else if (TTS_ERROR_TIMED_OUT != ret) {
1681 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1684 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1687 if (TTS_RETRY_COUNT == count) {
1688 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1696 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
1698 client->reason = ret;
1699 client->utt_id = -1;
1701 ecore_timer_add(0, __tts_notify_error, client->tts);
1705 client->before_state = client->current_state;
1706 client->current_state = TTS_STATE_PAUSED;
1708 if (NULL != client->state_changed_cb) {
1709 tts_client_use_callback(client);
1710 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1711 tts_client_not_use_callback(client);
1712 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1715 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1720 int tts_pause_async(tts_h tts)
1722 if (0 != __tts_get_feature_enabled()) {
1723 return TTS_ERROR_NOT_SUPPORTED;
1726 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause tts");
1729 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1730 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1731 return TTS_ERROR_INVALID_PARAMETER;
1734 tts_client_s* client = tts_client_get(tts);
1736 if (NULL == client) {
1737 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1738 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1739 return TTS_ERROR_INVALID_PARAMETER;
1742 if (TTS_STATE_PLAYING != client->current_state) {
1743 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1744 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1745 return TTS_ERROR_INVALID_STATE;
1748 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1749 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1750 return TTS_ERROR_INVALID_STATE;
1753 ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
1755 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1757 return TTS_ERROR_NONE;
1760 int tts_pause(tts_h tts)
1762 if (0 != __tts_get_feature_enabled()) {
1763 return TTS_ERROR_NOT_SUPPORTED;
1766 SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
1769 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1770 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1771 return TTS_ERROR_INVALID_PARAMETER;
1774 tts_client_s* client = tts_client_get(tts);
1776 if (NULL == client) {
1777 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1778 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1779 return TTS_ERROR_INVALID_PARAMETER;
1782 if (TTS_STATE_PLAYING != client->current_state) {
1783 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1784 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1785 return TTS_ERROR_INVALID_STATE;
1788 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1789 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1790 return TTS_ERROR_INVALID_STATE;
1795 bool is_prepared = false;
1797 ret = tts_dbus_request_pause(client->uid);
1800 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1801 client->current_state = TTS_STATE_CREATED;
1802 if (0 == tts_prepare_sync(tts)) {
1804 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1806 } else if (TTS_ERROR_TIMED_OUT != ret) {
1807 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1810 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1813 if (TTS_RETRY_COUNT == count) {
1814 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1822 client->before_state = client->current_state;
1823 client->current_state = TTS_STATE_PAUSED;
1825 if (NULL != client->state_changed_cb) {
1826 tts_client_use_callback(client);
1827 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1828 tts_client_not_use_callback(client);
1829 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1832 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1834 return TTS_ERROR_NONE;
1837 int tts_set_private_data(tts_h tts, const char* key, const char* data)
1839 if (0 != __tts_get_feature_enabled()) {
1840 return TTS_ERROR_NOT_SUPPORTED;
1843 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
1846 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1847 return TTS_ERROR_INVALID_PARAMETER;
1850 if (NULL == key || NULL == data) {
1851 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
1852 return TTS_ERROR_INVALID_PARAMETER;
1855 tts_client_s* client = tts_client_get(tts);
1857 if (NULL == client) {
1858 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1859 return TTS_ERROR_INVALID_PARAMETER;
1862 if (TTS_STATE_READY != client->current_state) {
1863 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
1864 return TTS_ERROR_INVALID_STATE;
1867 if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
1868 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
1869 return TTS_ERROR_INVALID_PARAMETER;
1874 bool is_prepared = false;
1876 ret = tts_dbus_request_set_private_data(client->uid, key, data);
1879 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1880 client->current_state = TTS_STATE_CREATED;
1881 if (0 == tts_prepare_sync(tts)) {
1883 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1885 } else if (TTS_ERROR_TIMED_OUT != ret) {
1886 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1889 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
1892 if (TTS_RETRY_COUNT == count) {
1893 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1901 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1906 int tts_get_private_data(tts_h tts, const char* key, char** data)
1908 if (0 != __tts_get_feature_enabled()) {
1909 return TTS_ERROR_NOT_SUPPORTED;
1912 SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
1915 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1916 return TTS_ERROR_INVALID_PARAMETER;
1919 if (NULL == key || NULL == data) {
1920 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
1921 return TTS_ERROR_INVALID_PARAMETER;
1924 tts_client_s* client = tts_client_get(tts);
1926 if (NULL == client) {
1927 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1928 return TTS_ERROR_INVALID_PARAMETER;
1931 if (TTS_STATE_READY != client->current_state) {
1932 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
1933 return TTS_ERROR_INVALID_STATE;
1938 bool is_prepared = false;
1940 ret = tts_dbus_request_get_private_data(client->uid, key, data);
1943 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
1944 client->current_state = TTS_STATE_CREATED;
1945 if (0 == tts_prepare_sync(tts)) {
1947 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
1949 } else if (TTS_ERROR_TIMED_OUT != ret) {
1950 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1953 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
1956 if (TTS_RETRY_COUNT == count) {
1957 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1965 if (0 == strncmp(*data, "NULL", strlen(*data))) {
1970 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1976 static Eina_Bool __tts_notify_error(void *data)
1978 tts_h tts = (tts_h)data;
1980 tts_client_s* client = tts_client_get(tts);
1983 if (NULL == client) {
1984 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify error msg : A handle is not valid");
1988 SLOG(LOG_DEBUG, TAG_TTSC, "Error data : uttid(%d) reason(%s)", client->utt_id, __tts_get_error_code(client->reason));
1990 if (NULL != client->error_cb) {
1991 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of error");
1992 tts_client_use_callback(client);
1993 g_err_callback_status = true;
1994 client->error_cb(client->tts, client->utt_id, client->reason, client->error_user_data);
1995 g_err_callback_status = false;
1996 tts_client_not_use_callback(client);
1998 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2004 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
2007 GList* client_list = NULL;
2008 client_list = tts_client_get_client_list();
2011 tts_client_s *data = NULL;
2013 if (g_list_length(client_list) > 0) {
2014 /* Get a first item */
2015 iter = g_list_first(client_list);
2017 while (NULL != iter) {
2020 data->utt_id = utt_id;
2021 data->reason = reason;
2022 if (NULL != data->err_msg) {
2023 free(data->err_msg);
2024 data->err_msg = NULL;
2026 if (NULL != err_msg)
2027 data->err_msg = strdup(err_msg);
2029 /* call callback function */
2030 if (NULL != data->error_cb) {
2031 ecore_timer_add(0, __tts_notify_error, data->tts);
2033 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2036 if (TTS_ERROR_SERVICE_RESET == reason) {
2037 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
2039 data->current_state = TTS_STATE_CREATED;
2040 if (0 != tts_prepare(data->tts)) {
2041 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
2046 iter = g_list_next(iter);
2050 tts_client_s* client = tts_client_get_by_uid(uid);
2052 if (NULL == client) {
2053 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2054 return TTS_ERROR_INVALID_PARAMETER;
2057 client->utt_id = utt_id;
2058 client->reason = reason;
2059 if (NULL != client->err_msg) {
2060 free(client->err_msg);
2061 client->err_msg = NULL;
2063 if (NULL != err_msg)
2064 client->err_msg = strdup(err_msg);
2066 /* call callback function */
2067 if (NULL != client->error_cb) {
2068 ecore_timer_add(0, __tts_notify_error, client->tts);
2070 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
2073 if (TTS_ERROR_SERVICE_RESET == reason) {
2074 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
2076 client->current_state = TTS_STATE_CREATED;
2077 if (0 != tts_prepare(client->tts)) {
2078 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
2086 static Eina_Bool __tts_notify_state_changed(void *data)
2088 tts_h tts = (tts_h)data;
2090 tts_client_s* client = tts_client_get(tts);
2093 if (NULL == client) {
2094 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify state changed : A handle is not valid");
2098 if (NULL != client->state_changed_cb) {
2099 tts_client_use_callback(client);
2100 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2101 tts_client_not_use_callback(client);
2102 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called : pre(%d) cur(%d)", client->before_state, client->current_state);
2104 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
2110 int __tts_cb_set_state(int uid, int state)
2112 tts_client_s* client = tts_client_get_by_uid(uid);
2113 if (NULL == client) {
2114 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] The handle is not valid");
2118 tts_state_e state_from_daemon = (tts_state_e)state;
2120 if (client->current_state == state_from_daemon) {
2121 SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", client->current_state);
2125 if (NULL != client->state_changed_cb) {
2126 if (NULL != g_check_state_timer) {
2127 ecore_timer_del(g_check_state_timer);
2128 g_check_state_timer = NULL;
2130 g_check_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
2132 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
2135 client->before_state = client->current_state;
2136 client->current_state = state_from_daemon;
2142 int __tts_cb_utt_started(int uid, int utt_id)
2144 tts_client_s* client = tts_client_get_by_uid(uid);
2146 if (NULL == client) {
2147 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2148 return TTS_ERROR_INVALID_PARAMETER;
2151 SLOG(LOG_INFO, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
2153 client->utt_id = utt_id;
2155 /* call callback function */
2156 if (NULL != client->utt_started_cb) {
2157 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance started ");
2158 tts_client_use_callback(client);
2159 client->utt_started_cb(client->tts, client->utt_id, client->utt_started_user_data);
2160 tts_client_not_use_callback(client);
2162 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
2168 int __tts_cb_utt_completed(int uid, int utt_id)
2170 tts_client_s* client = tts_client_get_by_uid(uid);
2172 if (NULL == client) {
2173 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
2174 return TTS_ERROR_INVALID_PARAMETER;
2177 SLOG(LOG_INFO, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
2179 client->utt_id = utt_id;
2181 /* call callback function */
2182 if (NULL != client->utt_completeted_cb) {
2183 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance completed ");
2184 tts_client_use_callback(client);
2185 client->utt_completeted_cb(client->tts, client->utt_id, client->utt_completed_user_data);
2186 tts_client_not_use_callback(client);
2188 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance completed ");
2194 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
2196 if (0 != __tts_get_feature_enabled()) {
2197 return TTS_ERROR_NOT_SUPPORTED;
2200 if (NULL == tts || NULL == callback) {
2201 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Input parameter is null");
2202 return TTS_ERROR_INVALID_PARAMETER;
2205 tts_client_s* client = tts_client_get(tts);
2207 if (NULL == client) {
2208 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : A handle is not valid");
2209 return TTS_ERROR_INVALID_PARAMETER;
2212 if (TTS_STATE_CREATED != client->current_state) {
2213 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Current state is not 'Created'.");
2214 return TTS_ERROR_INVALID_STATE;
2217 client->state_changed_cb = callback;
2218 client->state_changed_user_data = user_data;
2220 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
2225 int tts_unset_state_changed_cb(tts_h tts)
2227 if (0 != __tts_get_feature_enabled()) {
2228 return TTS_ERROR_NOT_SUPPORTED;
2232 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Input parameter is null");
2233 return TTS_ERROR_INVALID_PARAMETER;
2236 tts_client_s* client = tts_client_get(tts);
2238 if (NULL == client) {
2239 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : A handle is not valid");
2240 return TTS_ERROR_INVALID_PARAMETER;
2243 if (TTS_STATE_CREATED != client->current_state) {
2244 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Current state is not 'Created'.");
2245 return TTS_ERROR_INVALID_STATE;
2248 client->state_changed_cb = NULL;
2249 client->state_changed_user_data = NULL;
2251 if (NULL != g_check_state_timer) {
2252 ecore_timer_del(g_check_state_timer);
2253 g_check_state_timer = NULL;
2256 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
2261 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
2263 if (0 != __tts_get_feature_enabled()) {
2264 return TTS_ERROR_NOT_SUPPORTED;
2267 if (NULL == tts || NULL == callback) {
2268 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Input parameter is null");
2269 return TTS_ERROR_INVALID_PARAMETER;
2272 tts_client_s* client = tts_client_get(tts);
2274 if (NULL == client) {
2275 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : A handle is not valid");
2276 return TTS_ERROR_INVALID_PARAMETER;
2279 if (TTS_STATE_CREATED != client->current_state) {
2280 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Current state is not 'Created'.");
2281 return TTS_ERROR_INVALID_STATE;
2284 client->utt_started_cb = callback;
2285 client->utt_started_user_data = user_data;
2287 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
2292 int tts_unset_utterance_started_cb(tts_h tts)
2294 if (0 != __tts_get_feature_enabled()) {
2295 return TTS_ERROR_NOT_SUPPORTED;
2299 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Input parameter is null");
2300 return TTS_ERROR_INVALID_PARAMETER;
2303 tts_client_s* client = tts_client_get(tts);
2305 if (NULL == client) {
2306 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : A handle is not valid");
2307 return TTS_ERROR_INVALID_PARAMETER;
2310 if (TTS_STATE_CREATED != client->current_state) {
2311 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Current state is not 'Created'.");
2312 return TTS_ERROR_INVALID_STATE;
2315 client->utt_started_cb = NULL;
2316 client->utt_started_user_data = NULL;
2318 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
2323 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
2325 if (0 != __tts_get_feature_enabled()) {
2326 return TTS_ERROR_NOT_SUPPORTED;
2329 if (NULL == tts || NULL == callback) {
2330 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Input parameter is null");
2331 return TTS_ERROR_INVALID_PARAMETER;
2334 tts_client_s* client = tts_client_get(tts);
2336 if (NULL == client) {
2337 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : A handle is not valid");
2338 return TTS_ERROR_INVALID_PARAMETER;
2341 if (TTS_STATE_CREATED != client->current_state) {
2342 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Current state is not 'Created'.");
2343 return TTS_ERROR_INVALID_STATE;
2346 client->utt_completeted_cb = callback;
2347 client->utt_completed_user_data = user_data;
2349 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
2354 int tts_unset_utterance_completed_cb(tts_h tts)
2356 if (0 != __tts_get_feature_enabled()) {
2357 return TTS_ERROR_NOT_SUPPORTED;
2361 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Input parameter is null");
2362 return TTS_ERROR_INVALID_PARAMETER;
2365 tts_client_s* client = tts_client_get(tts);
2367 if (NULL == client) {
2368 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : A handle is not valid");
2369 return TTS_ERROR_INVALID_PARAMETER;
2372 if (TTS_STATE_CREATED != client->current_state) {
2373 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Current state is not 'Created'.");
2374 return TTS_ERROR_INVALID_STATE;
2377 client->utt_completeted_cb = NULL;
2378 client->utt_completed_user_data = NULL;
2380 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
2384 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
2386 if (0 != __tts_get_feature_enabled()) {
2387 return TTS_ERROR_NOT_SUPPORTED;
2390 if (NULL == tts || NULL == callback) {
2391 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Input parameter is null");
2392 return TTS_ERROR_INVALID_PARAMETER;
2395 tts_client_s* client = tts_client_get(tts);
2397 if (NULL == client) {
2398 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : A handle is not valid");
2399 return TTS_ERROR_INVALID_PARAMETER;
2402 if (TTS_STATE_CREATED != client->current_state) {
2403 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Current state is not 'Created'.");
2404 return TTS_ERROR_INVALID_STATE;
2407 client->error_cb = callback;
2408 client->error_user_data = user_data;
2410 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
2415 int tts_unset_error_cb(tts_h tts)
2417 if (0 != __tts_get_feature_enabled()) {
2418 return TTS_ERROR_NOT_SUPPORTED;
2422 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Input parameter is null");
2423 return TTS_ERROR_INVALID_PARAMETER;
2426 tts_client_s* client = tts_client_get(tts);
2428 if (NULL == client) {
2429 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : A handle is not valid");
2430 return TTS_ERROR_INVALID_PARAMETER;
2433 if (TTS_STATE_CREATED != client->current_state) {
2434 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Current state is not 'Created'.");
2435 return TTS_ERROR_INVALID_STATE;
2438 client->error_cb = NULL;
2439 client->error_user_data = NULL;
2441 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
2446 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
2448 if (0 != __tts_get_feature_enabled()) {
2449 return TTS_ERROR_NOT_SUPPORTED;
2452 if (NULL == tts || NULL == callback) {
2453 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Input parameter is null");
2454 return TTS_ERROR_INVALID_PARAMETER;
2457 tts_client_s* client = tts_client_get(tts);
2459 if (NULL == client) {
2460 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : A handle is not valid");
2461 return TTS_ERROR_INVALID_PARAMETER;
2464 if (TTS_STATE_CREATED != client->current_state) {
2465 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Current state is not 'Created'.");
2466 return TTS_ERROR_INVALID_STATE;
2469 client->default_voice_changed_cb = callback;
2470 client->default_voice_changed_user_data = user_data;
2472 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
2477 int tts_unset_default_voice_changed_cb(tts_h tts)
2479 if (0 != __tts_get_feature_enabled()) {
2480 return TTS_ERROR_NOT_SUPPORTED;
2484 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Input parameter is null");
2485 return TTS_ERROR_INVALID_PARAMETER;
2488 tts_client_s* client = tts_client_get(tts);
2490 if (NULL == client) {
2491 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : A handle is not valid");
2492 return TTS_ERROR_INVALID_PARAMETER;
2495 if (TTS_STATE_CREATED != client->current_state) {
2496 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Current state is not 'Created'.");
2497 return TTS_ERROR_INVALID_STATE;
2500 client->default_voice_changed_cb = NULL;
2501 client->default_voice_changed_user_data = NULL;
2503 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
2508 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
2510 if (0 != __tts_get_feature_enabled()) {
2511 return TTS_ERROR_NOT_SUPPORTED;
2514 if (NULL == tts || NULL == callback) {
2515 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Input parameter is null");
2516 return TTS_ERROR_INVALID_PARAMETER;
2519 tts_client_s* client = tts_client_get(tts);
2521 if (NULL == client) {
2522 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : A handle is not valid");
2523 return TTS_ERROR_INVALID_PARAMETER;
2526 if (TTS_STATE_CREATED != client->current_state) {
2527 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Current state is not 'Created'.");
2528 return TTS_ERROR_INVALID_STATE;
2531 client->engine_changed_cb = callback;
2532 client->engine_changed_user_data = user_data;
2534 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
2539 int tts_unset_engine_changed_cb(tts_h tts)
2541 if (0 != __tts_get_feature_enabled()) {
2542 return TTS_ERROR_NOT_SUPPORTED;
2546 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Input parameter is null");
2547 return TTS_ERROR_INVALID_PARAMETER;
2550 tts_client_s* client = tts_client_get(tts);
2552 if (NULL == client) {
2553 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : A handle is not valid");
2554 return TTS_ERROR_INVALID_PARAMETER;
2557 if (TTS_STATE_CREATED != client->current_state) {
2558 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Current state is not 'Created'.");
2559 return TTS_ERROR_INVALID_STATE;
2562 client->engine_changed_cb = NULL;
2563 client->engine_changed_user_data = NULL;
2565 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
2571 int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
2573 if (0 != __tts_get_feature_enabled()) {
2574 return TTS_ERROR_NOT_SUPPORTED;
2577 SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
2580 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2581 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2582 return TTS_ERROR_INVALID_PARAMETER;
2585 tts_client_s* client = tts_client_get(tts);
2587 if (NULL == client) {
2588 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2589 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2590 return TTS_ERROR_INVALID_PARAMETER;
2593 if (TTS_STATE_CREATED == client->current_state) {
2594 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2595 return TTS_ERROR_INVALID_STATE;
2598 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2599 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2600 return TTS_ERROR_INVALID_STATE;
2605 bool is_prepared = false;
2607 ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
2609 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2610 client->current_state = TTS_STATE_CREATED;
2611 if (0 == tts_prepare_sync(tts)) {
2613 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2615 } else if (TTS_ERROR_TIMED_OUT != ret) {
2616 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2619 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add pcm : %s", __tts_get_error_code(ret));
2622 if (TTS_RETRY_COUNT == count) {
2623 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2630 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2632 return TTS_ERROR_NONE;
2635 int tts_play_pcm(tts_h tts)
2637 if (0 != __tts_get_feature_enabled()) {
2638 return TTS_ERROR_NOT_SUPPORTED;
2641 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
2644 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2645 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2646 return TTS_ERROR_INVALID_PARAMETER;
2649 tts_client_s* client = tts_client_get(tts);
2651 if (NULL == client) {
2652 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2653 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2654 return TTS_ERROR_INVALID_PARAMETER;
2657 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
2658 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2659 return TTS_ERROR_INVALID_STATE;
2662 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2663 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2664 return TTS_ERROR_INVALID_STATE;
2669 bool is_prepared = false;
2671 ret = tts_dbus_request_play_pcm(client->uid);
2673 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2674 client->current_state = TTS_STATE_CREATED;
2675 if (0 == tts_prepare_sync(tts)) {
2677 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2679 } else if (TTS_ERROR_TIMED_OUT != ret) {
2680 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2683 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play pcm : %s", __tts_get_error_code(ret));
2686 if (TTS_RETRY_COUNT == count) {
2687 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2694 client->before_state = client->current_state;
2695 client->current_state = TTS_STATE_PLAYING;
2697 if (NULL != client->state_changed_cb) {
2698 tts_client_use_callback(client);
2699 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2700 tts_client_not_use_callback(client);
2701 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
2704 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2706 return TTS_ERROR_NONE;
2709 int tts_stop_pcm(tts_h tts)
2711 if (0 != __tts_get_feature_enabled()) {
2712 return TTS_ERROR_NOT_SUPPORTED;
2715 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
2718 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2719 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2720 return TTS_ERROR_INVALID_PARAMETER;
2723 tts_client_s* client = tts_client_get(tts);
2725 if (NULL == client) {
2726 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2727 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2728 return TTS_ERROR_INVALID_PARAMETER;
2731 if (TTS_STATE_CREATED == client->current_state) {
2732 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
2733 return TTS_ERROR_INVALID_STATE;
2736 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
2737 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
2738 return TTS_ERROR_INVALID_STATE;
2743 bool is_prepared = false;
2745 ret = tts_dbus_request_stop_pcm(client->uid);
2747 if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
2748 client->current_state = TTS_STATE_CREATED;
2749 if (0 == tts_prepare_sync(tts)) {
2751 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
2753 } else if (TTS_ERROR_TIMED_OUT != ret) {
2754 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
2757 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop pcm : %s", __tts_get_error_code(ret));
2760 if (TTS_RETRY_COUNT == count) {
2761 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
2768 client->before_state = client->current_state;
2769 client->current_state = TTS_STATE_READY;
2771 if (NULL != client->state_changed_cb) {
2772 tts_client_use_callback(client);
2773 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
2774 tts_client_not_use_callback(client);
2775 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
2778 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2780 return TTS_ERROR_NONE;
2784 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
2786 if (0 != __tts_get_feature_enabled()) {
2787 return TTS_ERROR_NOT_SUPPORTED;
2790 SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
2793 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
2794 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2795 return TTS_ERROR_INVALID_PARAMETER;
2798 if (NULL == text_repeat || NULL == utt_id) {
2799 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null.");
2800 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2801 return TTS_ERROR_INVALID_PARAMETER;
2804 *text_repeat = NULL;
2807 tts_client_s* client = tts_client_get(tts);
2809 if (NULL == client) {
2810 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
2811 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
2812 return TTS_ERROR_INVALID_PARAMETER;
2815 if (TTS_STATE_READY != client->current_state) {
2816 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", client->current_state);
2817 return TTS_ERROR_INVALID_STATE;
2820 /* Clear the legacy and Add texts to be played repeatedly */
2822 ret = tts_stop(tts);
2823 if (TTS_ERROR_NONE != ret) {
2824 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to clear the legacy");
2828 if (NULL != client->text_repeat) {
2829 char* tmp_text = strdup(client->text_repeat);
2830 char* tmp_lang = NULL;
2831 if (NULL != g_language) {
2832 tmp_lang = strdup(g_language);
2834 ret = tts_add_text(tts, tmp_text, tmp_lang, g_voice_type, g_speed, utt_id);
2835 if (TTS_ERROR_NONE != ret) {
2836 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add texts for repetition.");
2837 if (NULL != tmp_text) {
2841 if (NULL != tmp_lang) {
2847 *text_repeat = strdup(client->text_repeat);
2848 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] text to repeat(%s), utt_id(%d)", (*text_repeat) ? *text_repeat : "NULL", *utt_id);
2849 if (NULL != tmp_text) {
2853 if (NULL != tmp_lang) {
2858 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] There is no previous added texts. Please add texts");
2859 return TTS_ERROR_OPERATION_FAILED;
2862 /* Play added texts */
2863 ret = tts_play(tts);
2864 if (TTS_ERROR_NONE != ret) {
2865 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play texts for repetition.");
2866 if (NULL != *text_repeat) {
2868 *text_repeat = NULL;
2874 return TTS_ERROR_NONE;