2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
14 #include <app_manager.h>
17 #include <system_info.h>
19 #include <package-manager.h>
23 #include "tts_client.h"
24 #include "tts_config_mgr.h"
30 #include "tts_internal.h"
32 static int g_feature_enabled = -1;
35 static int __tts_get_feature_enabled()
37 RETV_IF(1 == g_feature_enabled, TTS_ERROR_NONE);
38 RETVM_IF(0 == g_feature_enabled, TTS_ERROR_NOT_SUPPORTED, "[ERROR] TTS feature NOT supported");
40 bool tts_supported = false;
41 if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
42 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
43 return TTS_ERROR_NOT_SUPPORTED;
46 if (false == tts_supported) {
47 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
48 g_feature_enabled = 0;
49 return TTS_ERROR_NOT_SUPPORTED;
52 g_feature_enabled = 1;
53 return TTS_ERROR_NONE;
56 // TODO: move into tts_core to make common function
58 static int __tts_convert_config_error_code(tts_config_error_e code)
60 if (code == TTS_CONFIG_ERROR_NONE) return TTS_ERROR_NONE;
61 if (code == TTS_CONFIG_ERROR_OUT_OF_MEMORY) return TTS_ERROR_OUT_OF_MEMORY;
62 if (code == TTS_CONFIG_ERROR_IO_ERROR) return TTS_ERROR_IO_ERROR;
63 if (code == TTS_CONFIG_ERROR_INVALID_PARAMETER) return TTS_ERROR_INVALID_PARAMETER;
64 if (code == TTS_CONFIG_ERROR_INVALID_STATE) return TTS_ERROR_INVALID_STATE;
65 if (code == TTS_CONFIG_ERROR_INVALID_VOICE) return TTS_ERROR_INVALID_VOICE;
66 if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND) return TTS_ERROR_ENGINE_NOT_FOUND;
67 if (code == TTS_CONFIG_ERROR_OPERATION_FAILED) return TTS_ERROR_OPERATION_FAILED;
68 if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE) return TTS_ERROR_NOT_SUPPORTED_FEATURE;
73 static void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
75 SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
76 before_lang, before_voice_type, language, voice_type);
78 GList* client_list = tts_client_get_client_list();
79 if (NULL == client_list) {
80 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
85 if (g_list_length(client_list) > 0) {
86 /* Get a first item */
87 iter = g_list_first(client_list);
89 while (NULL != iter) {
90 tts_client_s *client = iter->data;
91 if (tts_client_is_valid_client(client)) {
92 tts_core_notify_default_voice_changed(client, before_lang, before_voice_type, language, voice_type);
94 /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
95 if (0 != strncmp(before_lang, language, strlen(before_lang))) {
96 tts_client_set_repeat_text(client, NULL);
99 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid (%p)", client);
103 iter = g_list_next(iter);
107 g_list_free(client_list);
112 static 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)
114 tts_h tts = (tts_h)user_data;
116 tts_client_s* client = tts_client_get(tts);
117 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
119 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
120 if (NULL != setting) SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
121 if (NULL != language) SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
122 SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
124 /* When the default engine is changed, please unload the old engine and load the new one. */
127 tts_state_e current_state = tts_client_get_current_state(client);
128 if (TTS_STATE_PLAYING == current_state || TTS_STATE_PAUSED == current_state) {
131 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
134 ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
135 } else if (TTS_STATE_READY == current_state) {
136 // TODO: change to tts_core function
137 ret = tts_unprepare(tts);
139 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
141 ret = tts_prepare(tts);
143 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
147 /* call callback function */
148 tts_core_notify_engine_changed(client, engine_id, language, voice_type, need_credential);
153 static void __tts_config_screen_reader_changed_cb(bool value, void* user_data)
155 tts_h tts = (tts_h)user_data;
157 tts_client_s* client = tts_client_get(tts);
158 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
160 SLOG(LOG_DEBUG, TAG_TTSC, "Screen reader is changed. current status (%d)", value);
162 /* call callback function */
163 tts_core_notify_screen_reader_changed(client, value);
166 static int __initialize_tts_config(unsigned int uid, tts_h new_tts)
168 int ret = tts_config_mgr_initialize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
169 if (TTS_CONFIG_ERROR_NONE != ret) {
170 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
171 return __tts_convert_config_error_code(ret);
174 ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, new_tts);
175 if (TTS_CONFIG_ERROR_NONE != ret) {
176 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
177 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
178 return __tts_convert_config_error_code(ret);
181 ret = tts_config_mgr_set_screen_reader_callback(uid, __tts_config_screen_reader_changed_cb, new_tts);
182 if (TTS_CONFIG_ERROR_NONE != ret) {
183 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
184 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
185 return __tts_convert_config_error_code(ret);
188 return TTS_ERROR_NONE;
191 int tts_create(tts_h* tts)
193 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
195 SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
197 RETVM_IF(NULL == tts, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
199 bool is_first_client = false;
200 if (0 == tts_client_get_size()) {
201 is_first_client = true;
204 tts_h new_tts = NULL;
205 if (0 != tts_client_new(&new_tts)) {
206 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
207 return TTS_ERROR_OUT_OF_MEMORY;
210 tts_client_s* client = tts_client_get(new_tts);
211 if (NULL == client) {
212 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
213 tts_client_destroy(new_tts);
214 return TTS_ERROR_OPERATION_FAILED;
217 unsigned int uid = tts_client_get_uid(client);
218 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%u)", tts, client, uid);
220 if (false == tts_ipc_is_method_set()) {
223 int ret = app_manager_get_app_id(pid, &appid);
224 if (0 != ret || NULL == appid) {
225 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d)", ret, pid);
226 tts_ipc_set_method(TTS_IPC_METHOD_DBUS);
228 SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_create : client appid(%s), pid(%d)", appid, pid);
229 tts_ipc_set_method(TTS_IPC_METHOD_TIDL);
238 if (0 != tts_ipc_open_connection(uid)) {
239 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open ipc connection");
240 tts_client_destroy(new_tts);
241 return TTS_ERROR_OPERATION_FAILED;
244 int ret = __initialize_tts_config(uid, new_tts);
245 if (TTS_ERROR_NONE != ret) {
246 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
247 tts_client_destroy(new_tts);
251 if (is_first_client) {
252 // These function would be called only when first client is created.
253 if (0 != tts_core_initialize()) {
254 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize core");
255 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
256 tts_client_destroy(new_tts);
257 return TTS_ERROR_OPERATION_FAILED;
262 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
263 return TTS_ERROR_NONE;
266 static int destroy_tts_handle(tts_h tts)
268 SLOG(LOG_INFO, TAG_TTSC, "Destroy TTS handle");
269 tts_client_s* client = tts_client_get(tts);
270 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
272 unsigned int uid = tts_client_get_uid(client);
273 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%u)", tts, client, uid);
275 /* check used callback */
276 if (0 != tts_client_get_use_callback(client)) {
277 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot destroy in Callback function");
278 return TTS_ERROR_OPERATION_FAILED;
281 tts_config_mgr_finalize(uid, TTS_CONFIG_CLIENT_TYPE_DEFAULT);
283 // TODO: move into tts_client
284 if (client->hello_timer) {
285 ecore_timer_del(client->hello_timer);
286 client->hello_timer = NULL;
289 switch (tts_client_get_current_state(client)) {
290 case TTS_STATE_PAUSED:
291 case TTS_STATE_PLAYING:
292 case TTS_STATE_READY: {
293 if (0 != tts_core_unprepare(client)) {
294 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare");
296 tts_client_set_current_state(client, TTS_STATE_CREATED);
298 case TTS_STATE_CREATED: {
299 /* Unset registered callbacks */
300 tts_client_unset_all_cb(client);
302 if (0 != tts_ipc_close_connection(uid)) {
303 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to close connection");
304 return TTS_ERROR_OPERATION_FAILED;
308 tts_client_destroy(tts);
313 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
314 return TTS_ERROR_INVALID_PARAMETER;
318 unsigned int num_of_client = tts_client_get_size();
319 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] num_of_client(%u)", num_of_client);
321 if (0 == num_of_client) {
322 if (0 != tts_core_deinitialize()) {
323 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to deinitialize core");
327 return TTS_ERROR_NONE;
330 static void *destroy_tts_handle_on_main_thread(void* data)
332 SLOG(LOG_INFO, TAG_TTSC, "Destroy on main thread synchronously");
333 tts_h tts = (tts_h)data;
335 int ret = destroy_tts_handle(tts);
336 intptr_t p_ret = (intptr_t)ret;
338 return (void *)p_ret;
341 int tts_destroy(tts_h tts)
343 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
344 SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
346 intptr_t ret = (intptr_t)ecore_main_loop_thread_safe_call_sync(destroy_tts_handle_on_main_thread, (void *)tts);
347 SLOG(LOG_INFO, TAG_TTSC, "Return value: (%d/%s)", (int)ret, get_error_message((int)ret));
349 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
353 int tts_set_mode(tts_h tts, tts_mode_e mode)
355 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
357 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
359 RETVM_IF(TTS_MODE_DEFAULT > mode || TTS_MODE_INTERRUPT < mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] mode is not valid : %d", mode);
361 tts_client_s* client = tts_client_get(tts);
362 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
364 tts_state_e current_state = tts_client_get_current_state(client);
365 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
367 tts_client_set_mode(client, mode);
369 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
370 return TTS_ERROR_NONE;
373 int tts_get_mode(tts_h tts, tts_mode_e* mode)
375 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
377 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
379 RETVM_IF(NULL == mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter(mode) is NULL");
381 tts_client_s* client = tts_client_get(tts);
382 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
384 tts_state_e current_state = tts_client_get_current_state(client);
385 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
387 *mode = tts_client_get_mode(client);
389 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
390 return TTS_ERROR_NONE;
393 int tts_set_playing_mode(tts_h tts, tts_playing_mode_e mode)
395 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
397 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS playing mode(%d)", mode);
399 RETVM_IF(TTS_PLAYING_MODE_BY_SERVICE > mode || TTS_PLAYING_MODE_BY_CLIENT < mode, TTS_ERROR_INVALID_PARAMETER, "[ERROR] mode is not valid : %d", mode);
401 tts_client_s* client = tts_client_get(tts);
402 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
404 tts_state_e current_state = tts_client_get_current_state(client);
405 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
407 tts_client_set_playing_mode(client, mode);
409 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
410 return TTS_ERROR_NONE;
413 int tts_set_credential(tts_h tts, const char* credential)
415 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
417 RETVM_IF(NULL == credential, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
419 tts_client_s* client = tts_client_get(tts);
420 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
422 tts_state_e current_state = tts_client_get_current_state(client);
423 RETVM_IF(TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
425 tts_client_set_credential_key(client, credential);
427 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
428 return TTS_ERROR_NONE;
431 int tts_set_server_tts(tts_h tts, const char* credential)
433 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
435 tts_client_s* client = tts_client_get(tts);
436 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
438 // TODO: fix state check, because set_private_data runs only ready state
439 tts_state_e current_state = tts_client_get_current_state(client);
440 RETVM_IF(TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
442 // TODO: fix name more clear and move into tts_client
443 client->internal = true;
446 if (NULL != credential) {
447 key = "EnableServerTTS";
448 tts_client_set_credential_key(client, credential);
449 if (NULL == tts_client_get_credential_key(client)) {
450 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
451 return TTS_ERROR_OUT_OF_MEMORY;
454 key = "DisableServerTTS";
459 int ret = app_manager_get_app_id(pid, &appid);
460 if (0 != ret || NULL == appid) {
461 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);;
464 return TTS_ERROR_OPERATION_FAILED;
467 ret = tts_core_set_private_data(client, key, appid);
469 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
478 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
479 return TTS_ERROR_NONE;
482 int tts_prepare(tts_h tts)
484 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
486 tts_client_s* client = tts_client_get(tts);
487 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
489 tts_state_e current_state = tts_client_get_current_state(client);
490 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
492 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
493 int ret = tts_core_prepare(client);
495 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_prepare failed. (%s)", tts_core_covert_error_code(ret));
499 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
500 return TTS_ERROR_NONE;
503 int tts_prepare_sync(tts_h tts)
505 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
507 tts_client_s* client = tts_client_get(tts);
508 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
510 tts_state_e current_state = tts_client_get_current_state(client);
511 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
513 SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS synchronously");
514 int ret = tts_core_prepare_sync(client);
515 if (TTS_ERROR_NONE != ret) {
516 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_prepare_sync failed. (%s)", tts_core_covert_error_code(ret));
520 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
521 return TTS_ERROR_NONE;
524 int tts_unprepare(tts_h tts)
526 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
528 tts_client_s* client = tts_client_get(tts);
529 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
531 tts_state_e current_state = tts_client_get_current_state(client);
532 RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
534 SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
535 int ret = tts_core_unprepare(client);
537 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_unprepare is failed(%s)", tts_core_covert_error_code(ret));
541 tts_core_notify_state_changed(client, TTS_STATE_CREATED);
543 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
544 return TTS_ERROR_NONE;
547 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
549 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
551 SLOG(LOG_INFO, TAG_TTSC, "@@@ Foreach supported voices");
553 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
555 tts_client_s* client = tts_client_get(tts);
556 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
559 char* current_engine = NULL;
560 ret = tts_config_mgr_get_engine(¤t_engine);
561 if (0 != ret || NULL == current_engine) {
562 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
563 return __tts_convert_config_error_code(ret);
566 ret = tts_core_foreach_supported_voices(client, current_engine, callback, user_data);
567 free(current_engine);
570 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
574 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
575 return TTS_ERROR_NONE;
578 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
580 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
582 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
584 RETVM_IF(NULL == lang || NULL == vctype, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid");
586 tts_client_s* client = tts_client_get(tts);
587 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
589 /* Request call remote method */
591 ret = tts_config_mgr_get_voice(lang, vctype);
593 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %d", ret);
594 return __tts_convert_config_error_code(ret);
597 SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
598 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
599 return TTS_ERROR_NONE;
602 int tts_get_max_text_size(tts_h tts, unsigned int* size)
604 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
606 RETVM_IF(NULL == size, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get max text count : Input parameter is null");
608 tts_client_s* client = tts_client_get(tts);
609 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
611 tts_state_e current_state = tts_client_get_current_state(client);
612 RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
614 if (0 != tts_config_mgr_get_max_text_size(size)) {
615 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
616 return TTS_ERROR_OPERATION_FAILED;
619 SLOG(LOG_INFO, TAG_TTSC, "Get max text size : %d byte", *size);
620 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
621 return TTS_ERROR_NONE;
624 int tts_get_state(tts_h tts, tts_state_e* state)
626 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
628 RETVM_IF(NULL == state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get state : Input parameter is null");
630 tts_client_s* client = tts_client_get(tts);
631 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
633 tts_state_e current_state = tts_client_get_current_state(client);
634 switch (current_state) {
635 case TTS_STATE_CREATED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Created'"); break;
636 case TTS_STATE_READY: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Ready'"); break;
637 case TTS_STATE_PLAYING: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Playing'"); break;
638 case TTS_STATE_PAUSED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Paused'"); break;
640 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
641 return TTS_ERROR_INVALID_PARAMETER;
644 *state = current_state;
645 return TTS_ERROR_NONE;
648 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
650 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
652 RETVM_IF(NULL == min || NULL == normal || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
654 tts_client_s* client = tts_client_get(tts);
655 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
657 *min = TTS_SPEED_MIN;
658 *normal = TTS_SPEED_NORMAL;
659 *max = TTS_SPEED_MAX;
661 return TTS_ERROR_NONE;
664 int tts_get_error_message(tts_h tts, char** err_msg)
666 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
668 RETVM_IF(NULL == err_msg, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
670 tts_client_s* client = tts_client_get(tts);
671 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
673 const char* error_message = tts_client_get_error_message(client);
674 if (NULL != error_message) {
675 *err_msg = strdup(error_message);
676 SLOG(LOG_DEBUG, TAG_TTSC, "Error msg (%s)", error_message);
679 SLOG(LOG_DEBUG, TAG_TTSC, "Error msg (NULL)");
682 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
683 return TTS_ERROR_NONE;
686 int tts_check_screen_reader_on(tts_h tts, bool* is_on)
688 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
690 RETVM_IF(NULL == is_on, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
692 tts_client_s* client = tts_client_get(tts);
693 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
695 if (false == tts_core_check_screen_reader(client)) {
696 SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is not available");
699 SLOG(LOG_INFO, TAG_TTSC, "[INFO] Screen reader option is available");
703 return TTS_ERROR_NONE;
706 int tts_get_service_state(tts_h tts, tts_service_state_e* service_state)
708 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
710 RETVM_IF(NULL == service_state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get service state : Input parameter is null");
712 tts_client_s* client = tts_client_get(tts);
713 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
715 tts_state_e current_state = tts_client_get_current_state(client);
716 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
718 int ret = tts_core_get_service_state(client, service_state);
719 if (TTS_ERROR_NONE != ret) {
720 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get service state. ret(%d/%s)", ret, get_error_message(ret));
724 return TTS_ERROR_NONE;
727 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
729 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
731 SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
733 RETVM_IF(TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed, TTS_ERROR_INVALID_PARAMETER, "[ERROR] speed value(%d) is invalid.", speed);
734 RETVM_IF(voice_type < 0, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Voice type should not be negative(%d)", voice_type);
735 RETVM_IF(NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null");
736 RETVM_IF(false == tts_core_is_valid_text(text), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input text is invalid");
738 tts_client_s* client = tts_client_get(tts);
739 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
741 tts_state_e current_state = tts_client_get_current_state(client);
742 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
744 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
745 RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
747 int ret = tts_core_add_text(client, text, language, voice_type, speed, utt_id);
748 if (TTS_ERROR_NONE != ret) {
749 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add text. ret(%s)", tts_core_covert_error_code(ret));
753 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
754 return TTS_ERROR_NONE;
758 static void __tts_play_async(void *data)
760 tts_h tts = (tts_h)data;
762 tts_client_s* client = tts_client_get(tts);
763 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
765 int ret = tts_core_play(client);
767 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", tts_core_covert_error_code(ret));
768 tts_core_notify_error_async(client, ret, -1, NULL);
772 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
776 int tts_play_async(tts_h tts)
778 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
780 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play asynchronously tts");
782 tts_client_s* client = tts_client_get(tts);
783 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
785 tts_state_e current_state = tts_client_get_current_state(client);
786 RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
788 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
789 RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
791 ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
793 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
794 return TTS_ERROR_NONE;
798 int tts_play(tts_h tts)
800 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
802 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
804 tts_client_s* client = tts_client_get(tts);
805 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
807 tts_state_e current_state = tts_client_get_current_state(client);
808 RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
810 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
811 RETVM_IF(false == tts_core_check_credential(client), TTS_ERROR_PERMISSION_DENIED, "[ERROR] Do not have app credential for this engine");
813 int ret = tts_core_play(client);
814 if (TTS_ERROR_NONE != ret) {
815 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request play. ret(%s)", tts_core_covert_error_code(ret));
819 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
820 return TTS_ERROR_NONE;
824 static void __tts_stop_async(void *data)
826 tts_h tts = (tts_h)data;
828 tts_client_s* client = tts_client_get(tts);
829 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
831 int ret = tts_core_stop(client);
833 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", tts_core_covert_error_code(ret));
834 tts_core_notify_error_async(client, ret, -1, NULL);
838 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
842 int tts_stop_aync(tts_h tts)
844 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
846 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop asynchronously tts");
848 tts_client_s* client = tts_client_get(tts);
849 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
851 tts_state_e current_state = tts_client_get_current_state(client);
852 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
854 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
856 ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
858 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
859 return TTS_ERROR_NONE;
863 int tts_stop(tts_h tts)
865 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
867 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
869 tts_client_s* client = tts_client_get(tts);
870 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
872 tts_state_e current_state = tts_client_get_current_state(client);
873 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
875 int ret = tts_core_stop(client);
876 if (TTS_ERROR_NONE != ret) {
877 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop. ret(%s)", tts_core_covert_error_code(ret));
881 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
882 return TTS_ERROR_NONE;
886 static void __tts_pause_async(void *data)
888 tts_h tts = (tts_h)data;
890 tts_client_s* client = tts_client_get(tts);
891 RETM_IF(NULL == client, "[ERROR] A handle is not valid. tts(%p)", tts);
893 int ret = tts_core_pause(client);
895 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", tts_core_covert_error_code(ret));
896 tts_core_notify_error_async(client, ret, -1, NULL);
900 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
904 int tts_pause_async(tts_h tts)
906 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
908 SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause asynchronously tts");
910 tts_client_s* client = tts_client_get(tts);
911 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
913 tts_state_e current_state = tts_client_get_current_state(client);
914 RETVM_IF(TTS_STATE_PLAYING != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
916 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
918 ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
920 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
921 return TTS_ERROR_NONE;
924 int tts_pause(tts_h tts)
926 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
928 SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
930 tts_client_s* client = tts_client_get(tts);
931 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
933 tts_state_e current_state = tts_client_get_current_state(client);
934 RETVM_IF(TTS_STATE_PLAYING != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
936 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
938 int ret = tts_core_pause(client);
939 if (TTS_ERROR_NONE != ret) {
940 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request pause. ret(%s)", tts_core_covert_error_code(ret));
944 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
945 return TTS_ERROR_NONE;
948 int tts_set_private_data(tts_h tts, const char* key, const char* data)
950 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
952 SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
954 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
956 tts_client_s* client = tts_client_get(tts);
957 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
959 tts_state_e current_state = tts_client_get_current_state(client);
960 RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
962 if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
963 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
964 return TTS_ERROR_INVALID_PARAMETER;
967 int ret = tts_core_set_private_data(client, key, data);
968 if (TTS_ERROR_NONE != ret) {
969 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request set private data. ret(%s)", tts_core_covert_error_code(ret));
973 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
977 int tts_get_private_data(tts_h tts, const char* key, char** data)
979 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
981 SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
983 RETVM_IF(NULL == key || NULL == data, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Invalid parameter");
985 tts_client_s* client = tts_client_get(tts);
986 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
988 tts_state_e current_state = tts_client_get_current_state(client);
989 RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
991 int ret = tts_core_get_private_data(client, key, data);
992 if (TTS_ERROR_NONE != ret) {
993 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request get private data. ret(%s)", tts_core_covert_error_code(ret));
997 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1001 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
1003 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1005 tts_client_s* client = tts_client_get(tts);
1006 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1008 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set state changed cb : Input parameter is null");
1010 tts_state_e current_state = tts_client_get_current_state(client);
1011 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1013 tts_client_set_state_changed_cb(client, callback, user_data);
1015 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
1019 int tts_unset_state_changed_cb(tts_h tts)
1021 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1023 tts_client_s* client = tts_client_get(tts);
1024 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1026 tts_state_e current_state = tts_client_get_current_state(client);
1027 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1029 tts_client_set_state_changed_cb(client, NULL, NULL);
1031 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
1035 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
1037 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1039 tts_client_s* client = tts_client_get(tts);
1040 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1042 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt started cb : Input parameter is null");
1044 tts_state_e current_state = tts_client_get_current_state(client);
1045 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1047 tts_client_set_utterance_started_cb(client, callback, user_data);
1049 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt started cb");
1054 int tts_unset_utterance_started_cb(tts_h tts)
1056 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1058 tts_client_s* client = tts_client_get(tts);
1059 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1061 tts_state_e current_state = tts_client_get_current_state(client);
1062 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1064 tts_client_set_utterance_started_cb(client, NULL, NULL);
1066 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt started cb");
1071 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
1073 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1075 tts_client_s* client = tts_client_get(tts);
1076 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1078 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set utt completed cb : Input parameter is null");
1080 tts_state_e current_state = tts_client_get_current_state(client);
1081 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1083 tts_client_set_utterance_completed_cb(client, callback, user_data);
1085 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set utt completed cb");
1090 int tts_unset_utterance_completed_cb(tts_h tts)
1092 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1094 tts_client_s* client = tts_client_get(tts);
1095 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1097 tts_state_e current_state = tts_client_get_current_state(client);
1098 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1100 tts_client_set_utterance_completed_cb(client, NULL, NULL);
1102 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset utt completed cb");
1106 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
1108 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1110 tts_client_s* client = tts_client_get(tts);
1111 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1113 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set error cb : Input parameter is null");
1115 tts_state_e current_state = tts_client_get_current_state(client);
1116 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1118 tts_client_set_error_cb(client, callback, user_data);
1120 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set error cb");
1125 int tts_unset_error_cb(tts_h tts)
1127 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1129 tts_client_s* client = tts_client_get(tts);
1130 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1132 tts_state_e current_state = tts_client_get_current_state(client);
1133 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1135 tts_client_set_error_cb(client, NULL, NULL);
1137 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset error cb");
1142 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
1144 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1146 tts_client_s* client = tts_client_get(tts);
1147 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1149 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set default voice changed cb : Input parameter is null");
1151 tts_state_e current_state = tts_client_get_current_state(client);
1152 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1154 tts_client_set_default_voice_changed_cb(client, callback, user_data);
1156 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice changed cb");
1161 int tts_unset_default_voice_changed_cb(tts_h tts)
1163 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1165 tts_client_s* client = tts_client_get(tts);
1166 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1168 tts_state_e current_state = tts_client_get_current_state(client);
1169 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1171 tts_client_set_default_voice_changed_cb(client, NULL, NULL);
1173 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset default voice changed cb");
1178 int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
1180 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1182 tts_client_s* client = tts_client_get(tts);
1183 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1185 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set engine changed cb : Input parameter is null");
1187 tts_state_e current_state = tts_client_get_current_state(client);
1188 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1190 tts_client_set_engine_changed_cb(client, callback, user_data);
1192 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
1197 int tts_unset_engine_changed_cb(tts_h tts)
1199 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1201 tts_client_s* client = tts_client_get(tts);
1202 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1204 tts_state_e current_state = tts_client_get_current_state(client);
1205 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1207 tts_client_set_engine_changed_cb(client, NULL, NULL);
1209 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
1214 int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb callback, void* user_data)
1216 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1218 tts_client_s* client = tts_client_get(tts);
1219 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1221 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set screen reader changed cb : Input parameter is null");
1223 tts_state_e current_state = tts_client_get_current_state(client);
1224 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1226 tts_client_set_screen_reader_changed_cb(client, callback, user_data);
1228 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set screen reader changed cb");
1233 int tts_unset_screen_reader_changed_cb(tts_h tts)
1235 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1237 tts_client_s* client = tts_client_get(tts);
1238 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1240 tts_state_e current_state = tts_client_get_current_state(client);
1241 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1243 tts_client_set_screen_reader_changed_cb(client, NULL, NULL);
1245 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset screen reader changed cb");
1250 int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
1252 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1254 SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
1256 tts_client_s* client = tts_client_get(tts);
1257 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1259 tts_state_e current_state = tts_client_get_current_state(client);
1260 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1262 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1264 int ret = tts_core_add_pcm(client, event, data, data_size, audio_type, rate);
1265 if (TTS_ERROR_NONE != ret) {
1266 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request add_pcm. ret(%s)", tts_core_covert_error_code(ret));
1270 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1271 return TTS_ERROR_NONE;
1274 int tts_play_pcm(tts_h tts)
1276 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1278 SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
1280 tts_client_s* client = tts_client_get(tts);
1281 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1283 tts_state_e current_state = tts_client_get_current_state(client);
1284 RETVM_IF(TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1286 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1288 int ret = tts_core_play_pcm(client);
1289 if (TTS_ERROR_NONE != ret) {
1290 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request play_pcm. ret(%s)", tts_core_covert_error_code(ret));
1294 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1295 return TTS_ERROR_NONE;
1298 int tts_stop_pcm(tts_h tts)
1300 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1302 SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
1304 tts_client_s* client = tts_client_get(tts);
1305 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1307 tts_state_e current_state = tts_client_get_current_state(client);
1308 RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1310 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1312 int ret = tts_core_stop_pcm(client);
1313 if (TTS_ERROR_NONE != ret) {
1314 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop_pcm. ret(%s)", tts_core_covert_error_code(ret));
1318 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1319 return TTS_ERROR_NONE;
1322 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
1324 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1326 SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
1328 RETVM_IF(NULL == text_repeat || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null.");
1330 tts_client_s* client = tts_client_get(tts);
1331 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1333 tts_state_e current_state = tts_client_get_current_state(client);
1334 RETVM_IF(TTS_STATE_READY != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1336 RETVM_IF(false == tts_core_check_screen_reader(client), TTS_ERROR_SCREEN_READER_OFF, "[ERROR] Screen reader option is not available");
1338 if (true == client->credential_needed && NULL == client->credential) {
1339 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
1340 return TTS_ERROR_PERMISSION_DENIED;
1343 *text_repeat = NULL;
1346 int ret = tts_core_repeat(client, text_repeat, utt_id);
1347 if (TTS_ERROR_NONE != ret) {
1348 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request stop. ret(%s)", tts_core_covert_error_code(ret));
1352 SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
1353 return TTS_ERROR_NONE;
1356 int tts_set_service_state_changed_cb(tts_h tts, tts_service_state_changed_cb callback, void* user_data)
1358 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1360 tts_client_s* client = tts_client_get(tts);
1361 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1362 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set service state changed cb : Input parameter is null");
1364 tts_state_e current_state = tts_client_get_current_state(client);
1365 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1367 tts_client_set_service_state_changed_cb(client, callback, user_data);
1369 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set service state changed cb");
1370 return TTS_ERROR_NONE;
1373 int tts_unset_service_state_changed_cb(tts_h tts)
1375 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1377 tts_client_s* client = tts_client_get(tts);
1378 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1380 tts_state_e current_state = tts_client_get_current_state(client);
1381 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1383 tts_client_set_service_state_changed_cb(client, NULL, NULL);
1385 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset service state changed cb");
1386 return TTS_ERROR_NONE;
1389 int tts_set_synthesized_pcm_cb(tts_h tts, tts_synthesized_pcm_cb callback, void* user_data)
1391 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1393 tts_client_s* client = tts_client_get(tts);
1394 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1395 RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set synthesized pcm cb : Input parameter is null");
1397 tts_state_e current_state = tts_client_get_current_state(client);
1398 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1400 tts_client_set_synthesized_pcm_cb(client, callback, user_data);
1402 SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set synthesized pcm cb");
1403 return TTS_ERROR_NONE;
1406 int tts_unset_synthesized_pcm_cb(tts_h tts)
1408 RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
1410 tts_client_s* client = tts_client_get(tts);
1411 RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
1413 tts_state_e current_state = tts_client_get_current_state(client);
1414 RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
1416 tts_client_set_synthesized_pcm_cb(client, NULL, NULL);
1418 SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset synthesized pcm cb");
1419 return TTS_ERROR_NONE;