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"
31 static bool g_screen_reader;
33 static int g_feature_enabled = -1;
35 static bool g_err_callback_status = false;
37 /* Function definition */
38 static Eina_Bool __tts_notify_state_changed(void *data);
39 static Eina_Bool __tts_notify_error(void *data);
46 static int __tts_get_feature_enabled()
48 if (0 == g_feature_enabled) {
49 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
50 return TTS_ERROR_NOT_SUPPORTED;
51 } else if (-1 == g_feature_enabled) {
52 bool tts_supported = false;
53 if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
54 if (false == tts_supported) {
55 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
56 g_feature_enabled = 0;
57 return TTS_ERROR_NOT_SUPPORTED;
60 g_feature_enabled = 1;
62 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
63 return TTS_ERROR_NOT_SUPPORTED;
70 static const char* __tts_get_error_code(tts_error_e err)
73 case TTS_ERROR_NONE: return "TTS_ERROR_NONE";
74 case TTS_ERROR_OUT_OF_MEMORY: return "TTS_ERROR_OUT_OF_MEMORY";
75 case TTS_ERROR_IO_ERROR: return "TTS_ERROR_IO_ERROR";
76 case TTS_ERROR_INVALID_PARAMETER: return "TTS_ERROR_INVALID_PARAMETER";
77 case TTS_ERROR_OUT_OF_NETWORK: return "TTS_ERROR_OUT_OF_NETWORK";
78 case TTS_ERROR_TIMED_OUT: return "TTS_ERROR_TIMED_OUT";
79 case TTS_ERROR_PERMISSION_DENIED: return "TTS_ERROR_PERMISSION_DENIED";
80 case TTS_ERROR_NOT_SUPPORTED: return "TTS_ERROR_NOT_SUPPORTED";
81 case TTS_ERROR_INVALID_STATE: return "TTS_ERROR_INVALID_STATE";
82 case TTS_ERROR_INVALID_VOICE: return "TTS_ERROR_INVALID_VOICE";
83 case TTS_ERROR_ENGINE_NOT_FOUND: return "TTS_ERROR_ENGINE_NOT_FOUND";
84 case TTS_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED";
85 case TTS_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
86 case TTS_ERROR_NOT_SUPPORTED_FEATURE: return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
87 case TTS_ERROR_SERVICE_RESET: return "TTS_ERROR_SERVICE_RESET";
89 return "Invalid error code";
94 static int __tts_convert_config_error_code(tts_config_error_e code)
96 if (code == TTS_CONFIG_ERROR_NONE) return TTS_ERROR_NONE;
97 if (code == TTS_CONFIG_ERROR_OUT_OF_MEMORY) return TTS_ERROR_OUT_OF_MEMORY;
98 if (code == TTS_CONFIG_ERROR_IO_ERROR) return TTS_ERROR_IO_ERROR;
99 if (code == TTS_CONFIG_ERROR_INVALID_PARAMETER) return TTS_ERROR_INVALID_PARAMETER;
100 if (code == TTS_CONFIG_ERROR_INVALID_STATE) return TTS_ERROR_INVALID_STATE;
101 if (code == TTS_CONFIG_ERROR_INVALID_VOICE) return TTS_ERROR_INVALID_VOICE;
102 if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND) return TTS_ERROR_ENGINE_NOT_FOUND;
103 if (code == TTS_CONFIG_ERROR_OPERATION_FAILED) return TTS_ERROR_OPERATION_FAILED;
104 if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE) return TTS_ERROR_NOT_SUPPORTED_FEATURE;
109 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)
111 SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
112 before_lang, before_voice_type, language, voice_type);
114 GList* client_list = NULL;
115 client_list = tts_client_get_client_list();
118 tts_client_s *data = NULL;
120 if (g_list_length(client_list) > 0) {
121 /* Get a first item */
122 iter = g_list_first(client_list);
124 while (NULL != iter) {
126 if (NULL != data->default_voice_changed_cb) {
127 SLOG(LOG_DEBUG, TAG_TTSC, "Call default voice changed callback : uid(%d)", data->uid);
128 data->default_voice_changed_cb(data->tts, before_lang, before_voice_type,
129 language, voice_type, data->default_voice_changed_user_data);
133 iter = g_list_next(iter);
140 void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
142 tts_h tts = (tts_h)user_data;
144 tts_client_s* client = tts_client_get(tts);
145 if (NULL == client) {
146 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
150 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
151 if (NULL != setting) SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
152 if (NULL != language) SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
153 SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
155 /* When the default engine is changed, please unload the old engine and load the new one. */
158 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
161 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
163 ret = tts_unprepare(tts);
165 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
167 ret = tts_prepare(tts);
169 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
171 } else if (TTS_STATE_READY == client->current_state) {
172 ret = tts_unprepare(tts);
174 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
176 ret = tts_prepare(tts);
178 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
182 /* call callback function */
183 if (NULL != client->engine_changed_cb) {
184 client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
186 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function for changed engine");
191 int tts_create(tts_h* tts)
193 if (0 != __tts_get_feature_enabled()) {
194 return TTS_ERROR_NOT_SUPPORTED;
197 SLOG(LOG_DEBUG, TAG_TTSC, "===== Create TTS");
201 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
202 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
203 SLOG(LOG_DEBUG, TAG_TTSC, " ");
204 return TTS_ERROR_INVALID_PARAMETER;
207 if (0 == tts_client_get_size()) {
208 if (0 != tts_dbus_open_connection()) {
209 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection");
210 return TTS_ERROR_OPERATION_FAILED;
214 if (0 != tts_client_new(tts)) {
215 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
216 return TTS_ERROR_OUT_OF_MEMORY;
219 tts_client_s* client = tts_client_get(*tts);
220 if (NULL == client) {
221 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
222 return TTS_ERROR_OPERATION_FAILED;
225 int ret = tts_config_mgr_initialize(client->uid);
227 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
228 tts_client_destroy(*tts);
229 return __tts_convert_config_error_code(ret);
232 ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL);
234 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
235 tts_client_destroy(*tts);
236 return __tts_convert_config_error_code(ret);
239 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
240 SLOG(LOG_DEBUG, TAG_TTSC, " ");
242 return TTS_ERROR_NONE;
245 int tts_destroy(tts_h tts)
247 if (0 != __tts_get_feature_enabled()) {
248 return TTS_ERROR_NOT_SUPPORTED;
251 SLOG(LOG_DEBUG, TAG_TTSC, "===== Destroy TTS");
254 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
255 return TTS_ERROR_INVALID_PARAMETER;
258 tts_client_s* client = tts_client_get(tts);
261 if (NULL == client) {
262 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
263 return TTS_ERROR_INVALID_PARAMETER;
266 /* check used callback */
267 if (0 != tts_client_get_use_callback(client)) {
268 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot destroy in Callback function");
269 return TTS_ERROR_OPERATION_FAILED;
272 tts_config_mgr_finalize(client->uid);
278 switch (client->current_state) {
279 case TTS_STATE_PAUSED:
280 case TTS_STATE_PLAYING:
281 case TTS_STATE_READY:
282 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
284 ret = tts_dbus_request_finalize(client->uid);
286 if (TTS_ERROR_TIMED_OUT != ret) {
287 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
290 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize");
293 if (TTS_RETRY_COUNT == count) {
294 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
301 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
304 client->before_state = client->current_state;
305 client->current_state = TTS_STATE_CREATED;
307 case TTS_STATE_CREATED:
308 if (NULL != client->conn_timer) {
309 SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted");
310 ecore_timer_del(client->conn_timer);
311 client->conn_timer = NULL;
314 tts_client_destroy(tts);
321 if (0 == tts_client_get_size()) {
322 if (0 != tts_dbus_close_connection()) {
323 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
329 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
330 SLOG(LOG_DEBUG, TAG_TTSC, " ");
332 return TTS_ERROR_NONE;
335 void __tts_screen_reader_changed_cb(bool value)
337 g_screen_reader = value;
340 int tts_set_mode(tts_h tts, tts_mode_e mode)
342 if (0 != __tts_get_feature_enabled()) {
343 return TTS_ERROR_NOT_SUPPORTED;
346 SLOG(LOG_DEBUG, TAG_TTSC, "===== Set TTS mode");
348 tts_client_s* client = tts_client_get(tts);
351 if (NULL == client) {
352 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
353 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
354 SLOG(LOG_DEBUG, TAG_TTSC, " ");
355 return TTS_ERROR_INVALID_PARAMETER;
359 if (client->current_state != TTS_STATE_CREATED) {
360 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
361 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
362 SLOG(LOG_DEBUG, TAG_TTSC, " ");
363 return TTS_ERROR_INVALID_STATE;
366 if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_SCREEN_READER) {
369 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
370 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
371 SLOG(LOG_DEBUG, TAG_TTSC, " ");
372 return TTS_ERROR_INVALID_PARAMETER;
375 if (TTS_MODE_SCREEN_READER == mode) {
378 ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
380 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader");
381 return TTS_ERROR_OPERATION_FAILED;
383 g_screen_reader = (bool)screen_reader;
384 tts_config_set_screen_reader_callback(client->uid, __tts_screen_reader_changed_cb);
386 tts_config_unset_screen_reader_callback(client->uid);
389 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
390 SLOG(LOG_DEBUG, TAG_TTSC, " ");
392 return TTS_ERROR_NONE;
395 int tts_get_mode(tts_h tts, tts_mode_e* mode)
397 if (0 != __tts_get_feature_enabled()) {
398 return TTS_ERROR_NOT_SUPPORTED;
401 SLOG(LOG_DEBUG, TAG_TTSC, "===== Get TTS mode");
403 tts_client_s* client = tts_client_get(tts);
406 if (NULL == client) {
407 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
408 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
409 SLOG(LOG_DEBUG, TAG_TTSC, " ");
410 return TTS_ERROR_INVALID_PARAMETER;
414 if (client->current_state != TTS_STATE_CREATED) {
415 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
416 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
417 SLOG(LOG_DEBUG, TAG_TTSC, " ");
418 return TTS_ERROR_INVALID_STATE;
422 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter(mode) is NULL");
423 return TTS_ERROR_INVALID_PARAMETER;
426 *mode = client->mode;
428 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
429 SLOG(LOG_DEBUG, TAG_TTSC, " ");
431 return TTS_ERROR_NONE;
434 int tts_set_credential(tts_h tts, const char* credential)
436 if (0 != __tts_get_feature_enabled()) {
437 return TTS_ERROR_NOT_SUPPORTED;
440 if (NULL == tts || NULL == credential) {
441 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
442 return TTS_ERROR_INVALID_PARAMETER;
445 tts_client_s* client = tts_client_get(tts);
447 if (NULL == client) {
448 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
449 return TTS_ERROR_INVALID_PARAMETER;
452 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
453 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
454 return TTS_ERROR_INVALID_STATE;
457 if (NULL != client->credential) {
458 free(client->credential);
459 client->credential = NULL;
461 client->credential = strdup(credential);
463 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
464 SLOG(LOG_DEBUG, TAG_TTSC, " ");
466 return TTS_ERROR_NONE;
469 int tts_set_server_tts(tts_h tts, const char* credential)
471 if (0 != __tts_get_feature_enabled()) {
472 return TTS_ERROR_NOT_SUPPORTED;
476 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
477 return TTS_ERROR_INVALID_PARAMETER;
480 tts_client_s* client = tts_client_get(tts);
482 if (NULL == client) {
483 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
484 return TTS_ERROR_INVALID_PARAMETER;
487 if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
488 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
489 return TTS_ERROR_INVALID_STATE;
492 if (NULL != client->credential) {
493 free(client->credential);
494 client->credential = NULL;
497 client->internal = true;
500 if (NULL != credential) {
501 key = strdup("EnableServerTTS");
502 client->credential = strdup(credential);
503 if (NULL == client->credential) {
504 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
505 return TTS_ERROR_OUT_OF_MEMORY;
508 key = strdup("DisableServerTTS");
512 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
513 return TTS_ERROR_OUT_OF_MEMORY;
518 int ret = app_manager_get_app_id(pid, &appid);
520 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
523 return TTS_ERROR_OPERATION_FAILED;
526 ret = tts_set_private_data(tts, key, appid);
528 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
539 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
540 SLOG(LOG_DEBUG, TAG_TTSC, " ");
542 return TTS_ERROR_NONE;
545 static Eina_Bool __tts_connect_daemon(void *data)
547 tts_h tts = (tts_h)data;
548 tts_client_s* client = tts_client_get(tts);
551 if (NULL == client) {
552 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
557 if (0 != tts_dbus_request_hello(client->uid)) {
561 SLOG(LOG_DEBUG, TAG_TTSC, "===== Connect daemon");
563 /* do request initialize */
565 bool credential_needed = false;
567 ret = tts_dbus_request_initialize(client->uid, &credential_needed);
569 if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
570 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
572 client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
575 ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
576 client->conn_timer = NULL;
579 } else if (TTS_ERROR_NONE != ret) {
580 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
584 /* success to connect tts-daemon */
585 client->credential_needed = credential_needed;
586 SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
589 client->conn_timer = NULL;
591 client = tts_client_get(tts);
593 if (NULL == client) {
594 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
598 client->before_state = client->current_state;
599 client->current_state = TTS_STATE_READY;
601 if (NULL != client->state_changed_cb) {
602 tts_client_use_callback(client);
603 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
604 tts_client_not_use_callback(client);
606 SLOG(LOG_WARN, TAG_TTSC, "State changed callback is NULL");
609 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
610 SLOG(LOG_DEBUG, TAG_TTSC, " ");
615 int tts_prepare(tts_h tts)
617 if (0 != __tts_get_feature_enabled()) {
618 return TTS_ERROR_NOT_SUPPORTED;
621 SLOG(LOG_DEBUG, TAG_TTSC, "===== Prepare TTS");
623 tts_client_s* client = tts_client_get(tts);
626 if (NULL == client) {
627 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
628 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
629 SLOG(LOG_DEBUG, TAG_TTSC, " ");
630 return TTS_ERROR_INVALID_PARAMETER;
634 if (client->current_state != TTS_STATE_CREATED) {
635 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
636 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
637 SLOG(LOG_DEBUG, TAG_TTSC, " ");
638 return TTS_ERROR_INVALID_STATE;
641 client->conn_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
643 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
644 SLOG(LOG_DEBUG, TAG_TTSC, " ");
646 return TTS_ERROR_NONE;
649 int tts_unprepare(tts_h tts)
651 if (0 != __tts_get_feature_enabled()) {
652 return TTS_ERROR_NOT_SUPPORTED;
655 SLOG(LOG_DEBUG, TAG_TTSC, "===== Unprepare TTS");
657 tts_client_s* client = tts_client_get(tts);
660 if (NULL == client) {
661 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
662 return TTS_ERROR_INVALID_PARAMETER;
666 if (client->current_state != TTS_STATE_READY) {
667 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'READY'");
668 return TTS_ERROR_INVALID_STATE;
673 if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
675 ret = tts_dbus_request_finalize(client->uid);
677 if (TTS_ERROR_TIMED_OUT != ret) {
678 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
681 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize : %s", __tts_get_error_code(ret));
684 if (TTS_RETRY_COUNT == count) {
685 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
692 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
695 client->before_state = client->current_state;
696 client->current_state = TTS_STATE_CREATED;
698 if (NULL != client->state_changed_cb) {
699 tts_client_use_callback(client);
700 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
701 tts_client_not_use_callback(client);
702 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
705 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
706 SLOG(LOG_DEBUG, TAG_TTSC, " ");
708 return TTS_ERROR_NONE;
711 bool __tts_supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
713 tts_h tts = (tts_h)user_data;
715 tts_client_s* client = tts_client_get(tts);
716 if (NULL == client) {
717 SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
721 /* call callback function */
722 if (NULL != client->supported_voice_cb) {
723 return client->supported_voice_cb(tts, language, type, client->supported_voice_user_data);
725 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of supported voice");
731 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
733 if (0 != __tts_get_feature_enabled()) {
734 return TTS_ERROR_NOT_SUPPORTED;
737 SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices");
739 if (NULL == tts || NULL == callback) {
740 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
741 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
742 SLOG(LOG_DEBUG, TAG_TTSC, " ");
743 return TTS_ERROR_INVALID_PARAMETER;
746 tts_client_s* client = tts_client_get(tts);
749 if (NULL == client) {
750 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
751 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
752 SLOG(LOG_DEBUG, TAG_TTSC, " ");
753 return TTS_ERROR_INVALID_PARAMETER;
757 char* current_engine = NULL;
758 ret = tts_config_mgr_get_engine(¤t_engine);
760 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
761 return __tts_convert_config_error_code(ret);
764 client->supported_voice_cb = callback;
765 client->supported_voice_user_data = user_data;
767 ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts);
769 if (NULL != current_engine)
770 free(current_engine);
772 client->supported_voice_cb = NULL;
773 client->supported_voice_user_data = NULL;
776 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
777 ret = TTS_ERROR_OPERATION_FAILED;
780 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
781 SLOG(LOG_DEBUG, TAG_TTSC, " ");
786 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
788 if (0 != __tts_get_feature_enabled()) {
789 return TTS_ERROR_NOT_SUPPORTED;
792 SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default voice");
795 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
796 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
797 SLOG(LOG_DEBUG, TAG_TTSC, " ");
798 return TTS_ERROR_INVALID_PARAMETER;
801 tts_client_s* client = tts_client_get(tts);
803 if (NULL == client) {
804 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
805 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
806 SLOG(LOG_DEBUG, TAG_TTSC, " ");
807 return TTS_ERROR_INVALID_PARAMETER;
810 /* Request call remote method */
812 ret = tts_config_mgr_get_voice(lang, vctype);
814 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
815 return __tts_convert_config_error_code(ret);
817 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
820 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
821 SLOG(LOG_DEBUG, TAG_TTSC, " ");
826 int tts_get_max_text_size(tts_h tts, unsigned int* size)
828 if (0 != __tts_get_feature_enabled()) {
829 return TTS_ERROR_NOT_SUPPORTED;
832 if (NULL == tts || NULL == size) {
833 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Input parameter is null");
834 return TTS_ERROR_INVALID_PARAMETER;
837 tts_client_s* client = tts_client_get(tts);
839 if (NULL == client) {
840 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : A handle is not valid");
841 return TTS_ERROR_INVALID_PARAMETER;
844 if (TTS_STATE_READY != client->current_state) {
845 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Current state is NOT 'READY'.");
846 return TTS_ERROR_INVALID_STATE;
849 *size = TTS_MAX_TEXT_SIZE;
851 SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
852 return TTS_ERROR_NONE;
855 int tts_get_state(tts_h tts, tts_state_e* state)
857 if (0 != __tts_get_feature_enabled()) {
858 return TTS_ERROR_NOT_SUPPORTED;
861 if (NULL == tts || NULL == state) {
862 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : Input parameter is null");
863 return TTS_ERROR_INVALID_PARAMETER;
866 tts_client_s* client = tts_client_get(tts);
868 if (NULL == client) {
869 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
870 return TTS_ERROR_INVALID_PARAMETER;
873 *state = client->current_state;
876 case TTS_STATE_CREATED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Created'"); break;
877 case TTS_STATE_READY: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Ready'"); break;
878 case TTS_STATE_PLAYING: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Playing'"); break;
879 case TTS_STATE_PAUSED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Paused'"); break;
880 default: SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value"); break;
883 return TTS_ERROR_NONE;
886 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
888 if (0 != __tts_get_feature_enabled()) {
889 return TTS_ERROR_NOT_SUPPORTED;
892 if (NULL == tts || NULL == min || NULL == normal || NULL == max) {
893 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
894 return TTS_ERROR_INVALID_PARAMETER;
897 tts_client_s* client = tts_client_get(tts);
899 if (NULL == client) {
900 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
901 return TTS_ERROR_INVALID_PARAMETER;
904 *min = TTS_SPEED_MIN;
905 *normal = TTS_SPEED_NORMAL;
906 *max = TTS_SPEED_MAX;
908 return TTS_ERROR_NONE;
911 int tts_get_error_message(tts_h tts, char** err_msg)
913 if (0 != __tts_get_feature_enabled()) {
914 return TTS_ERROR_NOT_SUPPORTED;
917 if (NULL == tts || NULL == err_msg) {
918 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
919 return TTS_ERROR_INVALID_PARAMETER;
922 tts_client_s* client = tts_client_get(tts);
924 if (NULL == client) {
925 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
926 return TTS_ERROR_INVALID_PARAMETER;
929 if (NULL != client->err_msg) {
930 *err_msg = strdup(client->err_msg);
931 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg);
933 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)");
936 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
937 SLOG(LOG_DEBUG, TAG_TTSC, " ");
939 return TTS_ERROR_NONE;
942 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
944 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
946 if (0 != __tts_get_feature_enabled()) {
947 return TTS_ERROR_NOT_SUPPORTED;
951 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Speed should not be negative(%d)", speed);
952 return TTS_ERROR_INVALID_PARAMETER;
955 if (voice_type < 0) {
956 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Voice type should not be negative(%d)", voice_type);
957 return TTS_ERROR_INVALID_PARAMETER;
960 SLOG(LOG_DEBUG, TAG_TTSC, "===== Add text");
962 if (NULL == tts || NULL == utt_id) {
963 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
964 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
965 SLOG(LOG_DEBUG, TAG_TTSC, " ");
966 return TTS_ERROR_INVALID_PARAMETER;
969 tts_client_s* client = tts_client_get(tts);
971 if (NULL == client) {
972 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
973 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
974 SLOG(LOG_DEBUG, TAG_TTSC, " ");
975 return TTS_ERROR_INVALID_PARAMETER;
978 if (TTS_STATE_CREATED == client->current_state) {
979 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
980 return TTS_ERROR_INVALID_STATE;
983 if (TTS_MAX_TEXT_SIZE < strlen(text) || strlen(text) <= 0) {
984 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
985 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
986 SLOG(LOG_DEBUG, TAG_TTSC, " ");
987 return TTS_ERROR_INVALID_PARAMETER;
990 if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
991 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] speed value(%d) is invalid.", speed);
992 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
993 SLOG(LOG_DEBUG, TAG_TTSC, " ");
994 return TTS_ERROR_INVALID_PARAMETER;
997 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
998 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
999 return TTS_ERROR_INVALID_STATE;
1002 if (true == client->credential_needed && NULL == client->credential) {
1003 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1004 return TTS_ERROR_PERMISSION_DENIED;
1007 /* check valid utf8 */
1009 ict = iconv_open("utf-8", "");
1010 if ((iconv_t)-1 == ict) {
1011 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init for text check");
1012 return TTS_ERROR_OPERATION_FAILED;
1015 size_t len = strlen(text);
1016 char *in_tmp = NULL;
1017 char in_buf[TTS_MAX_TEXT_SIZE];
1018 char *out_tmp = NULL;
1019 char out_buf[TTS_MAX_TEXT_SIZE];
1020 size_t len_tmp = sizeof(out_buf);
1022 memset(in_buf, 0, TTS_MAX_TEXT_SIZE);
1023 snprintf(in_buf, TTS_MAX_TEXT_SIZE, "%s", text);
1026 memset(out_buf, 0, TTS_MAX_TEXT_SIZE);
1030 st = iconv(ict, &in_tmp, &len, &out_tmp, &len_tmp);
1031 if ((size_t)-1 == st) {
1032 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", in_buf);
1034 return TTS_ERROR_INVALID_PARAMETER;
1037 SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - Converted text is '%s'", out_buf);
1039 /* change default language value */
1042 if (NULL == language)
1043 temp = strdup("default");
1045 temp = strdup(language);
1047 client->current_utt_id++;
1048 if (client->current_utt_id == 10000) {
1049 client->current_utt_id = 1;
1056 ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
1058 if (TTS_ERROR_TIMED_OUT != ret) {
1059 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1062 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add text : %s", __tts_get_error_code(ret));
1065 if (TTS_RETRY_MIN_COUNT == count) {
1066 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1071 *utt_id = client->current_utt_id;
1075 if (NULL != temp) free(temp);
1077 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1078 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1083 static void __tts_play_async(void *data)
1085 tts_h tts = (tts_h)data;
1086 tts_client_s* client = tts_client_get(tts);
1089 if (NULL == client) {
1090 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1097 ret = tts_dbus_request_play(client->uid, client->credential);
1099 if (TTS_ERROR_TIMED_OUT != ret) {
1100 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1103 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1106 if (TTS_RETRY_COUNT == count) {
1107 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1115 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
1117 client->reason = ret;
1118 client->utt_id = -1;
1120 ecore_timer_add(0, __tts_notify_error, client->tts);
1124 client->before_state = client->current_state;
1125 client->current_state = TTS_STATE_PLAYING;
1127 if (NULL != client->state_changed_cb) {
1128 tts_client_use_callback(client);
1129 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1130 tts_client_not_use_callback(client);
1131 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1134 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1135 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1140 int tts_play_async(tts_h tts)
1142 if (0 != __tts_get_feature_enabled()) {
1143 return TTS_ERROR_NOT_SUPPORTED;
1146 SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
1149 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1150 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1151 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1152 return TTS_ERROR_INVALID_PARAMETER;
1155 tts_client_s* client = tts_client_get(tts);
1157 if (NULL == client) {
1158 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1159 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1160 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1161 return TTS_ERROR_INVALID_PARAMETER;
1164 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1165 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1166 return TTS_ERROR_INVALID_STATE;
1169 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1170 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1171 return TTS_ERROR_INVALID_STATE;
1174 if (true == client->credential_needed && NULL == client->credential) {
1175 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1176 return TTS_ERROR_PERMISSION_DENIED;
1179 ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
1181 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1182 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1184 return TTS_ERROR_NONE;
1187 int tts_play(tts_h tts)
1189 if (0 != __tts_get_feature_enabled()) {
1190 return TTS_ERROR_NOT_SUPPORTED;
1193 SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
1196 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
1197 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1198 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1199 return TTS_ERROR_INVALID_PARAMETER;
1202 tts_client_s* client = tts_client_get(tts);
1204 if (NULL == client) {
1205 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
1206 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1207 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1208 return TTS_ERROR_INVALID_PARAMETER;
1211 if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
1212 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
1213 return TTS_ERROR_INVALID_STATE;
1216 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1217 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1218 return TTS_ERROR_INVALID_STATE;
1221 if (true == client->credential_needed && NULL == client->credential) {
1222 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1223 return TTS_ERROR_PERMISSION_DENIED;
1229 ret = tts_dbus_request_play(client->uid, client->credential);
1231 if (TTS_ERROR_TIMED_OUT != ret) {
1232 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1235 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", __tts_get_error_code(ret));
1238 if (TTS_RETRY_COUNT == count) {
1239 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1246 client->before_state = client->current_state;
1247 client->current_state = TTS_STATE_PLAYING;
1249 if (NULL != client->state_changed_cb) {
1250 tts_client_use_callback(client);
1251 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1252 tts_client_not_use_callback(client);
1253 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1256 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1257 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1259 return TTS_ERROR_NONE;
1262 static void __tts_stop_async(void *data)
1264 tts_h tts = (tts_h)data;
1265 tts_client_s* client = tts_client_get(tts);
1268 if (NULL == client) {
1269 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1276 ret = tts_dbus_request_stop(client->uid);
1278 if (TTS_ERROR_TIMED_OUT != ret) {
1279 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1282 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1285 if (TTS_RETRY_COUNT == count) {
1286 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1294 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
1296 client->reason = ret;
1297 client->utt_id = -1;
1299 ecore_timer_add(0, __tts_notify_error, client->tts);
1303 client->before_state = client->current_state;
1304 client->current_state = TTS_STATE_READY;
1306 if (NULL != client->state_changed_cb) {
1307 tts_client_use_callback(client);
1308 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1309 tts_client_not_use_callback(client);
1310 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1313 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1314 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1319 int tts_stop_aync(tts_h tts)
1321 if (0 != __tts_get_feature_enabled()) {
1322 return TTS_ERROR_NOT_SUPPORTED;
1325 SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
1328 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1329 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1330 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1331 return TTS_ERROR_INVALID_PARAMETER;
1334 tts_client_s* client = tts_client_get(tts);
1336 if (NULL == client) {
1337 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1338 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1339 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1340 return TTS_ERROR_INVALID_PARAMETER;
1343 if (TTS_STATE_CREATED == client->current_state) {
1344 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1345 return TTS_ERROR_INVALID_STATE;
1348 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1349 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1350 return TTS_ERROR_INVALID_STATE;
1353 ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
1355 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1356 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1358 return TTS_ERROR_NONE;
1361 int tts_stop(tts_h tts)
1363 if (0 != __tts_get_feature_enabled()) {
1364 return TTS_ERROR_NOT_SUPPORTED;
1367 SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
1370 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1371 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1372 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1373 return TTS_ERROR_INVALID_PARAMETER;
1376 tts_client_s* client = tts_client_get(tts);
1378 if (NULL == client) {
1379 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1380 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1381 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1382 return TTS_ERROR_INVALID_PARAMETER;
1385 if (TTS_STATE_CREATED == client->current_state) {
1386 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
1387 return TTS_ERROR_INVALID_STATE;
1390 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1391 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1392 return TTS_ERROR_INVALID_STATE;
1398 ret = tts_dbus_request_stop(client->uid);
1400 if (TTS_ERROR_TIMED_OUT != ret) {
1401 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1404 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop : %s", __tts_get_error_code(ret));
1407 if (TTS_RETRY_COUNT == count) {
1408 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1415 client->before_state = client->current_state;
1416 client->current_state = TTS_STATE_READY;
1418 if (NULL != client->state_changed_cb) {
1419 tts_client_use_callback(client);
1420 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1421 tts_client_not_use_callback(client);
1422 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1425 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1426 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1428 return TTS_ERROR_NONE;
1431 static void __tts_pause_async(void *data)
1433 tts_h tts = (tts_h)data;
1434 tts_client_s* client = tts_client_get(tts);
1437 if (NULL == client) {
1438 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1445 ret = tts_dbus_request_pause(client->uid);
1447 if (TTS_ERROR_TIMED_OUT != ret) {
1448 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1451 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1454 if (TTS_RETRY_COUNT == count) {
1455 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1463 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
1465 client->reason = ret;
1466 client->utt_id = -1;
1468 ecore_timer_add(0, __tts_notify_error, client->tts);
1472 client->before_state = client->current_state;
1473 client->current_state = TTS_STATE_PAUSED;
1475 if (NULL != client->state_changed_cb) {
1476 tts_client_use_callback(client);
1477 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1478 tts_client_not_use_callback(client);
1479 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1482 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1483 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1488 int tts_pause_async(tts_h tts)
1490 if (0 != __tts_get_feature_enabled()) {
1491 return TTS_ERROR_NOT_SUPPORTED;
1494 SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
1497 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1498 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
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) {
1513 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1514 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1515 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1516 return TTS_ERROR_INVALID_STATE;
1519 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1520 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1521 return TTS_ERROR_INVALID_STATE;
1524 ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
1526 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1527 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1529 return TTS_ERROR_NONE;
1532 int tts_pause(tts_h tts)
1534 if (0 != __tts_get_feature_enabled()) {
1535 return TTS_ERROR_NOT_SUPPORTED;
1538 SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
1541 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1542 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1543 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1544 return TTS_ERROR_INVALID_PARAMETER;
1547 tts_client_s* client = tts_client_get(tts);
1549 if (NULL == client) {
1550 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1551 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1552 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1553 return TTS_ERROR_INVALID_PARAMETER;
1556 if (TTS_STATE_PLAYING != client->current_state) {
1557 SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
1558 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1559 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1560 return TTS_ERROR_INVALID_STATE;
1563 if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
1564 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
1565 return TTS_ERROR_INVALID_STATE;
1571 ret = tts_dbus_request_pause(client->uid);
1573 if (TTS_ERROR_TIMED_OUT != ret) {
1574 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1577 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry pause : %s", __tts_get_error_code(ret));
1580 if (TTS_RETRY_COUNT == count) {
1581 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1588 client->before_state = client->current_state;
1589 client->current_state = TTS_STATE_PAUSED;
1591 if (NULL != client->state_changed_cb) {
1592 tts_client_use_callback(client);
1593 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1594 tts_client_not_use_callback(client);
1595 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
1598 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1599 SLOG(LOG_DEBUG, TAG_TTSC, " ");
1601 return TTS_ERROR_NONE;
1604 int tts_set_private_data(tts_h tts, const char* key, const char* data)
1606 if (0 != __tts_get_feature_enabled()) {
1607 return TTS_ERROR_NOT_SUPPORTED;
1610 SLOG(LOG_DEBUG, TAG_TTSC, "===== Set private data");
1613 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1614 return TTS_ERROR_INVALID_PARAMETER;
1617 if (NULL == key || NULL == data) {
1618 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
1619 return TTS_ERROR_INVALID_PARAMETER;
1622 tts_client_s* client = tts_client_get(tts);
1624 if (NULL == client) {
1625 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1626 return TTS_ERROR_INVALID_PARAMETER;
1629 if (TTS_STATE_READY != client->current_state) {
1630 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
1631 return TTS_ERROR_INVALID_STATE;
1634 if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
1635 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
1636 return TTS_ERROR_INVALID_PARAMETER;
1642 ret = tts_dbus_request_set_private_data(client->uid, key, data);
1644 if (TTS_ERROR_TIMED_OUT != ret) {
1645 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1648 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
1651 if (TTS_RETRY_COUNT == count) {
1652 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1659 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1660 SLOG(LOG_DEBUG, TAG_TTSC, "");
1665 int tts_get_private_data(tts_h tts, const char* key, char** data)
1667 if (0 != __tts_get_feature_enabled()) {
1668 return TTS_ERROR_NOT_SUPPORTED;
1671 SLOG(LOG_DEBUG, TAG_TTSC, "===== Get private data");
1674 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
1675 return TTS_ERROR_INVALID_PARAMETER;
1678 if (NULL == key || NULL == data) {
1679 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
1680 return TTS_ERROR_INVALID_PARAMETER;
1683 tts_client_s* client = tts_client_get(tts);
1685 if (NULL == client) {
1686 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
1687 return TTS_ERROR_INVALID_PARAMETER;
1690 if (TTS_STATE_READY != client->current_state) {
1691 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
1692 return TTS_ERROR_INVALID_STATE;
1698 ret = tts_dbus_request_get_private_data(client->uid, key, data);
1700 if (TTS_ERROR_TIMED_OUT != ret) {
1701 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
1704 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry : %s", __tts_get_error_code(ret));
1707 if (TTS_RETRY_COUNT == count) {
1708 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
1715 if (0 == strncmp(*data, "NULL", strlen(*data))) {
1720 SLOG(LOG_DEBUG, TAG_TTSC, "=====");
1721 SLOG(LOG_DEBUG, TAG_TTSC, "");
1726 static Eina_Bool __tts_notify_error(void *data)
1728 tts_h tts = (tts_h)data;
1730 tts_client_s* client = tts_client_get(tts);
1733 if (NULL == client) {
1734 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify error msg : A handle is not valid");
1738 SLOG(LOG_DEBUG, TAG_TTSC, "Error data : uttid(%d) reason(%s)", client->utt_id, __tts_get_error_code(client->reason));
1740 if (NULL != client->error_cb) {
1741 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of error");
1742 tts_client_use_callback(client);
1743 g_err_callback_status = true;
1744 client->error_cb(client->tts, client->utt_id, client->reason, client->error_user_data);
1745 g_err_callback_status = false;
1746 tts_client_not_use_callback(client);
1748 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
1754 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
1756 tts_client_s* client = tts_client_get_by_uid(uid);
1758 if (NULL == client) {
1759 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
1760 return TTS_ERROR_INVALID_PARAMETER;
1763 client->utt_id = utt_id;
1764 client->reason = reason;
1765 if (NULL != client->err_msg) {
1766 free(client->err_msg);
1767 client->err_msg = NULL;
1769 client->err_msg = strdup(err_msg);
1771 /* call callback function */
1772 if (NULL != client->error_cb) {
1773 ecore_timer_add(0, __tts_notify_error, client->tts);
1775 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
1778 if (TTS_ERROR_SERVICE_RESET == reason) {
1779 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
1781 client->current_state = TTS_STATE_CREATED;
1782 if (0 != tts_prepare(client->tts)) {
1783 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
1790 static Eina_Bool __tts_notify_state_changed(void *data)
1792 tts_h tts = (tts_h)data;
1794 tts_client_s* client = tts_client_get(tts);
1797 if (NULL == client) {
1798 SLOG(LOG_WARN, TAG_TTSC, "Fail to notify state changed : A handle is not valid");
1802 if (NULL != client->state_changed_cb) {
1803 tts_client_use_callback(client);
1804 client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
1805 tts_client_not_use_callback(client);
1806 SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called : pre(%d) cur(%d)", client->before_state, client->current_state);
1808 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
1814 int __tts_cb_set_state(int uid, int state)
1816 tts_client_s* client = tts_client_get_by_uid(uid);
1817 if (NULL == client) {
1818 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] The handle is not valid");
1822 tts_state_e state_from_daemon = (tts_state_e)state;
1824 if (client->current_state == state_from_daemon) {
1825 SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", client->current_state);
1829 if (NULL != client->state_changed_cb) {
1830 ecore_timer_add(0, __tts_notify_state_changed, client->tts);
1832 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
1835 client->before_state = client->current_state;
1836 client->current_state = state_from_daemon;
1841 int __tts_cb_utt_started(int uid, int utt_id)
1843 tts_client_s* client = tts_client_get_by_uid(uid);
1845 if (NULL == client) {
1846 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
1847 return TTS_ERROR_INVALID_PARAMETER;
1850 SLOG(LOG_DEBUG, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
1852 client->utt_id = utt_id;
1854 /* call callback function */
1855 if (NULL != client->utt_started_cb) {
1856 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance started ");
1857 tts_client_use_callback(client);
1858 client->utt_started_cb(client->tts, client->utt_id, client->utt_started_user_data);
1859 tts_client_not_use_callback(client);
1861 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
1867 int __tts_cb_utt_completed(int uid, int utt_id)
1869 tts_client_s* client = tts_client_get_by_uid(uid);
1871 if (NULL == client) {
1872 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
1873 return TTS_ERROR_INVALID_PARAMETER;
1876 SLOG(LOG_DEBUG, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
1878 client->utt_id = utt_id;
1880 /* call callback function */
1881 if (NULL != client->utt_completeted_cb) {
1882 SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance completed ");
1883 tts_client_use_callback(client);
1884 client->utt_completeted_cb(client->tts, client->utt_id, client->utt_completed_user_data);
1885 tts_client_not_use_callback(client);
1887 SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance completed ");
1893 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
1895 if (0 != __tts_get_feature_enabled()) {
1896 return TTS_ERROR_NOT_SUPPORTED;
1899 if (NULL == tts || NULL == callback) {
1900 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Input parameter is null");
1901 return TTS_ERROR_INVALID_PARAMETER;
1904 tts_client_s* client = tts_client_get(tts);
1906 if (NULL == client) {
1907 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : A handle is not valid");
1908 return TTS_ERROR_INVALID_PARAMETER;
1911 if (TTS_STATE_CREATED != client->current_state) {
1912 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Current state is not 'Created'.");
1913 return TTS_ERROR_INVALID_STATE;
1916 client->state_changed_cb = callback;
1917 client->state_changed_user_data = user_data;
1919 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set state changed cb");
1924 int tts_unset_state_changed_cb(tts_h tts)
1926 if (0 != __tts_get_feature_enabled()) {
1927 return TTS_ERROR_NOT_SUPPORTED;
1931 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Input parameter is null");
1932 return TTS_ERROR_INVALID_PARAMETER;
1935 tts_client_s* client = tts_client_get(tts);
1937 if (NULL == client) {
1938 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : A handle is not valid");
1939 return TTS_ERROR_INVALID_PARAMETER;
1942 if (TTS_STATE_CREATED != client->current_state) {
1943 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Current state is not 'Created'.");
1944 return TTS_ERROR_INVALID_STATE;
1947 client->state_changed_cb = NULL;
1948 client->state_changed_user_data = NULL;
1950 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
1955 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
1957 if (0 != __tts_get_feature_enabled()) {
1958 return TTS_ERROR_NOT_SUPPORTED;
1961 if (NULL == tts || NULL == callback) {
1962 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Input parameter is null");
1963 return TTS_ERROR_INVALID_PARAMETER;
1966 tts_client_s* client = tts_client_get(tts);
1968 if (NULL == client) {
1969 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : A handle is not valid");
1970 return TTS_ERROR_INVALID_PARAMETER;
1973 if (TTS_STATE_CREATED != client->current_state) {
1974 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Current state is not 'Created'.");
1975 return TTS_ERROR_INVALID_STATE;
1978 client->utt_started_cb = callback;
1979 client->utt_started_user_data = user_data;
1981 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
1986 int tts_unset_utterance_started_cb(tts_h tts)
1988 if (0 != __tts_get_feature_enabled()) {
1989 return TTS_ERROR_NOT_SUPPORTED;
1993 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Input parameter is null");
1994 return TTS_ERROR_INVALID_PARAMETER;
1997 tts_client_s* client = tts_client_get(tts);
1999 if (NULL == client) {
2000 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : A handle is not valid");
2001 return TTS_ERROR_INVALID_PARAMETER;
2004 if (TTS_STATE_CREATED != client->current_state) {
2005 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Current state is not 'Created'.");
2006 return TTS_ERROR_INVALID_STATE;
2009 client->utt_started_cb = NULL;
2010 client->utt_started_user_data = NULL;
2012 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
2017 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
2019 if (0 != __tts_get_feature_enabled()) {
2020 return TTS_ERROR_NOT_SUPPORTED;
2023 if (NULL == tts || NULL == callback) {
2024 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Input parameter is null");
2025 return TTS_ERROR_INVALID_PARAMETER;
2028 tts_client_s* client = tts_client_get(tts);
2030 if (NULL == client) {
2031 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : A handle is not valid");
2032 return TTS_ERROR_INVALID_PARAMETER;
2035 if (TTS_STATE_CREATED != client->current_state) {
2036 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Current state is not 'Created'.");
2037 return TTS_ERROR_INVALID_STATE;
2040 client->utt_completeted_cb = callback;
2041 client->utt_completed_user_data = user_data;
2043 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
2048 int tts_unset_utterance_completed_cb(tts_h tts)
2050 if (0 != __tts_get_feature_enabled()) {
2051 return TTS_ERROR_NOT_SUPPORTED;
2055 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Input parameter is null");
2056 return TTS_ERROR_INVALID_PARAMETER;
2059 tts_client_s* client = tts_client_get(tts);
2061 if (NULL == client) {
2062 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : A handle is not valid");
2063 return TTS_ERROR_INVALID_PARAMETER;
2066 if (TTS_STATE_CREATED != client->current_state) {
2067 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Current state is not 'Created'.");
2068 return TTS_ERROR_INVALID_STATE;
2071 client->utt_completeted_cb = NULL;
2072 client->utt_completed_user_data = NULL;
2074 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
2078 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
2080 if (0 != __tts_get_feature_enabled()) {
2081 return TTS_ERROR_NOT_SUPPORTED;
2084 if (NULL == tts || NULL == callback) {
2085 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Input parameter is null");
2086 return TTS_ERROR_INVALID_PARAMETER;
2089 tts_client_s* client = tts_client_get(tts);
2091 if (NULL == client) {
2092 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : A handle is not valid");
2093 return TTS_ERROR_INVALID_PARAMETER;
2096 if (TTS_STATE_CREATED != client->current_state) {
2097 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Current state is not 'Created'.");
2098 return TTS_ERROR_INVALID_STATE;
2101 client->error_cb = callback;
2102 client->error_user_data = user_data;
2104 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
2109 int tts_unset_error_cb(tts_h tts)
2111 if (0 != __tts_get_feature_enabled()) {
2112 return TTS_ERROR_NOT_SUPPORTED;
2116 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Input parameter is null");
2117 return TTS_ERROR_INVALID_PARAMETER;
2120 tts_client_s* client = tts_client_get(tts);
2122 if (NULL == client) {
2123 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : A handle is not valid");
2124 return TTS_ERROR_INVALID_PARAMETER;
2127 if (TTS_STATE_CREATED != client->current_state) {
2128 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Current state is not 'Created'.");
2129 return TTS_ERROR_INVALID_STATE;
2132 client->error_cb = NULL;
2133 client->error_user_data = NULL;
2135 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
2140 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
2142 if (0 != __tts_get_feature_enabled()) {
2143 return TTS_ERROR_NOT_SUPPORTED;
2146 if (NULL == tts || NULL == callback) {
2147 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Input parameter is null");
2148 return TTS_ERROR_INVALID_PARAMETER;
2151 tts_client_s* client = tts_client_get(tts);
2153 if (NULL == client) {
2154 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : A handle is not valid");
2155 return TTS_ERROR_INVALID_PARAMETER;
2158 if (TTS_STATE_CREATED != client->current_state) {
2159 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Current state is not 'Created'.");
2160 return TTS_ERROR_INVALID_STATE;
2163 client->default_voice_changed_cb = callback;
2164 client->default_voice_changed_user_data = user_data;
2166 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
2171 int tts_unset_default_voice_changed_cb(tts_h tts)
2173 if (0 != __tts_get_feature_enabled()) {
2174 return TTS_ERROR_NOT_SUPPORTED;
2178 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Input parameter is null");
2179 return TTS_ERROR_INVALID_PARAMETER;
2182 tts_client_s* client = tts_client_get(tts);
2184 if (NULL == client) {
2185 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : A handle is not valid");
2186 return TTS_ERROR_INVALID_PARAMETER;
2189 if (TTS_STATE_CREATED != client->current_state) {
2190 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Current state is not 'Created'.");
2191 return TTS_ERROR_INVALID_STATE;
2194 client->default_voice_changed_cb = NULL;
2195 client->default_voice_changed_user_data = NULL;
2197 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
2202 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
2204 if (0 != __tts_get_feature_enabled()) {
2205 return TTS_ERROR_NOT_SUPPORTED;
2208 if (NULL == tts || NULL == callback) {
2209 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Input parameter is null");
2210 return TTS_ERROR_INVALID_PARAMETER;
2213 tts_client_s* client = tts_client_get(tts);
2215 if (NULL == client) {
2216 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : A handle is not valid");
2217 return TTS_ERROR_INVALID_PARAMETER;
2220 if (TTS_STATE_CREATED != client->current_state) {
2221 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Current state is not 'Created'.");
2222 return TTS_ERROR_INVALID_STATE;
2225 client->engine_changed_cb = callback;
2226 client->engine_changed_user_data = user_data;
2228 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
2233 int tts_unset_engine_changed_cb(tts_h tts)
2235 if (0 != __tts_get_feature_enabled()) {
2236 return TTS_ERROR_NOT_SUPPORTED;
2240 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Input parameter is null");
2241 return TTS_ERROR_INVALID_PARAMETER;
2244 tts_client_s* client = tts_client_get(tts);
2246 if (NULL == client) {
2247 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : A handle is not valid");
2248 return TTS_ERROR_INVALID_PARAMETER;
2251 if (TTS_STATE_CREATED != client->current_state) {
2252 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Current state is not 'Created'.");
2253 return TTS_ERROR_INVALID_STATE;
2256 client->engine_changed_cb = NULL;
2257 client->engine_changed_user_data = NULL;
2259 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");