#include "tts_dbus.h"
#include "tts_main.h"
+#include "tts_internal.h"
static bool g_screen_reader;
static bool g_err_callback_status = false;
+static int g_max_text_size = -1;
+
/* Function definition */
static Eina_Bool __tts_notify_state_changed(void *data);
static Eina_Bool __tts_notify_error(void *data);
return;
}
+static Eina_Bool __reconnect_by_engine_changed(void* data)
+{
+ tts_h tts = (tts_h)data;
+
+ tts_client_s* client = tts_client_get(tts);
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
+ return EINA_FALSE;
+ }
+
+ if (TTS_STATE_READY != client->current_state) {
+ usleep(10000);
+ return EINA_TRUE;
+ }
+
+ int ret = tts_unprepare(tts);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+ }
+ ret = tts_prepare(tts);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+ }
+
+ return EINA_FALSE;
+}
+
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)
{
tts_h tts = (tts_h)user_data;
if (NULL != language) SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
+ /* When the default engine is changed, please unload the old engine and load the new one. */
+ int ret = -1;
+
+ if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
+ ret = tts_stop(tts);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
+ }
+
+ ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
+ } else if (TTS_STATE_READY == client->current_state) {
+ ret = tts_unprepare(tts);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
+ }
+ ret = tts_prepare(tts);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+ }
+ }
+
/* call callback function */
if (NULL != client->engine_changed_cb) {
client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Create TTS");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
/* check param */
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
return __tts_convert_config_error_code(ret);
}
- ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL);
+ ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
tts_client_destroy(*tts);
return __tts_convert_config_error_code(ret);
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_NONE;
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Destroy TTS");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
int ret = -1;
int count = 0;
+ int screen_reader = -1;
/* check state */
switch (client->current_state) {
case TTS_STATE_PAUSED:
case TTS_STATE_PLAYING:
case TTS_STATE_READY:
+ ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
+ } else {
+ SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
+ g_screen_reader = (bool)screen_reader;
+ }
if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
- while (0 != ret) {
+ do {
ret = tts_dbus_request_finalize(client->uid);
if (0 != ret) {
if (TTS_ERROR_TIMED_OUT != ret) {
}
}
}
- }
+ } while (0 != ret);
} else {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
}
tts = NULL;
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Set TTS mode");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
tts_client_s* client = tts_client_get(tts);
/* check handle */
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
/* check state */
if (client->current_state != TTS_STATE_CREATED) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_INVALID_STATE;
}
- if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_SCREEN_READER) {
+ if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
client->mode = mode;
} else {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_INVALID_PARAMETER;
}
tts_config_unset_screen_reader_callback(client->uid);
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get TTS mode");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
tts_client_s* client = tts_client_get(tts);
/* check handle */
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_INVALID_PARAMETER;
}
/* check state */
if (client->current_state != TTS_STATE_CREATED) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_INVALID_STATE;
}
*mode = client->mode;
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_NONE;
}
client->credential = strdup(credential);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
client->credential = strdup(credential);
if (NULL == client->credential) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ if (NULL != key) {
+ free(key);
+ key = NULL;
+ }
return TTS_ERROR_OUT_OF_MEMORY;
}
} else {
int pid = getpid();
char* appid = NULL;
int ret = app_manager_get_app_id(pid, &appid);
- if (0 != ret) {
+ if (0 != ret || NULL == appid) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
free(key);
key = NULL;
+ if (NULL != appid) {
+ free(appid);
+ appid = NULL;
+ }
return TTS_ERROR_OPERATION_FAILED;
}
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
free(key);
key = NULL;
+ free(appid);
+ appid = NULL;
return ret;
}
free(key);
key = NULL;
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return EINA_TRUE;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Connect daemon");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Connect daemon");
/* do request initialize */
int ret = -1;
client->conn_timer = NULL;
return EINA_FALSE;
+ } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
+
+ client->reason = TTS_ERROR_PERMISSION_DENIED;
+ client->utt_id = -1;
+
+ ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+ client->conn_timer = NULL;
+ return EINA_FALSE;
+
} else if (TTS_ERROR_NONE != ret) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
return EINA_TRUE;
SLOG(LOG_WARN, TAG_TTSC, "State changed callback is NULL");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return EINA_FALSE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Prepare TTS");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
tts_client_s* client = tts_client_get(tts);
/* check handle */
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
/* check state */
if (client->current_state != TTS_STATE_CREATED) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_STATE;
}
client->conn_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return TTS_ERROR_NONE;
+}
+
+int tts_prepare_sync(tts_h tts)
+{
+ if (0 != __tts_get_feature_enabled()) {
+ return TTS_ERROR_NOT_SUPPORTED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
+
+ tts_client_s* client = tts_client_get(tts);
+
+ /* check handle */
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check state */
+ if (client->current_state != TTS_STATE_CREATED) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ int cnt = 0;
+ while (EINA_TRUE == __tts_connect_daemon(NULL) && TTS_CONNECTION_RETRY_COUNT > cnt) {
+ cnt++;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ if (TTS_CONNECTION_RETRY_COUNT == cnt) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect daemon");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Unprepare TTS");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
tts_client_s* client = tts_client_get(tts);
int ret = -1;
int count = 0;
+ int screen_reader = -1;
+
+ ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
+ } else {
+ SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
+ g_screen_reader = (bool)screen_reader;
+ }
+
+ bool is_prepared = false;
if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
- while (0 != ret) {
+ do {
ret = tts_dbus_request_finalize(client->uid);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
break;
} else {
}
}
}
- }
+ } while (0 != ret);
} else {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
}
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported voices");
if (NULL == tts || NULL == callback) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
/* check handle */
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts);
- if (NULL != current_engine)
+ if (NULL != current_engine) {
free(current_engine);
+ current_engine = NULL;
+ }
client->supported_voice_cb = NULL;
client->supported_voice_user_data = NULL;
ret = TTS_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return ret;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default voice");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return ret;
}
return TTS_ERROR_INVALID_STATE;
}
- *size = TTS_MAX_TEXT_SIZE;
+ if (0 != tts_config_mgr_get_max_text_size(size)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ g_max_text_size = (int)*size;
SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
return TTS_ERROR_NONE;
*err_msg = strdup(client->err_msg);
SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg);
} else {
+ *err_msg = NULL;
SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
{
- SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
+ SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
if (0 != __tts_get_feature_enabled()) {
return TTS_ERROR_NOT_SUPPORTED;
return TTS_ERROR_INVALID_PARAMETER;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Add text");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Add text");
if (NULL == tts || NULL == utt_id) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
return TTS_ERROR_INVALID_STATE;
}
- if (TTS_MAX_TEXT_SIZE < strlen(text) || strlen(text) <= 0) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- return TTS_ERROR_INVALID_PARAMETER;
+ if (-1 == g_max_text_size) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+ if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ if (0 == g_max_text_size) {
+ if (strlen(text) <= 0) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d", g_max_text_size);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+ } else {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+ if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
}
if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] speed value(%d) is invalid.", speed);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
}
/* check valid utf8 */
- iconv_t *ict;
- ict = iconv_open("utf-8", "");
- if ((iconv_t)-1 == ict) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init for text check");
- return TTS_ERROR_OPERATION_FAILED;
- }
+ bool valid = false;
- size_t len = strlen(text);
- char *in_tmp = NULL;
- char in_buf[TTS_MAX_TEXT_SIZE];
- char *out_tmp = NULL;
- char out_buf[TTS_MAX_TEXT_SIZE];
- size_t len_tmp = sizeof(out_buf);
+ DBusError err;
+ dbus_error_init(&err);
- memset(in_buf, 0, TTS_MAX_TEXT_SIZE);
- snprintf(in_buf, TTS_MAX_TEXT_SIZE, "%s", text);
- in_tmp = in_buf;
-
- memset(out_buf, 0, TTS_MAX_TEXT_SIZE);
- out_tmp = out_buf;
+ valid = dbus_validate_utf8(text, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
+ dbus_error_free(&err);
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
- size_t st;
- st = iconv(ict, &in_tmp, &len, &out_tmp, &len_tmp);
- if ((size_t)-1 == st) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", in_buf);
- iconv_close(ict);
+ if (valid != true) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
return TTS_ERROR_INVALID_PARAMETER;
}
- iconv_close(ict);
- SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - Converted text is '%s'", out_buf);
+ SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
/* change default language value */
char* temp = NULL;
/* do request */
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
- ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
+ ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
break;
} else {
}
}
- if (NULL != temp) free(temp);
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return ret;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_play(client->uid, client->credential);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
break;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
SLOG(LOG_DEBUG, TAG_TTSC, " ");
return TTS_ERROR_INVALID_PARAMETER;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_play(client->uid, client->credential);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
return ret;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_stop(client->uid);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
break;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_stop(client->uid);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
return ret;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_pause(client->uid);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
break;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (TTS_STATE_PLAYING != client->current_state) {
SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_STATE;
}
ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_PARAMETER;
}
if (TTS_STATE_PLAYING != client->current_state) {
SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_INVALID_STATE;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_pause(client->uid);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
return ret;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Set private data");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
if (NULL == tts) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle isnull");
return TTS_ERROR_INVALID_PARAMETER;
}
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_set_private_data(client->uid, key, data);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
return ret;
} else {
}
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, "");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return 0;
}
return TTS_ERROR_NOT_SUPPORTED;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get private data");
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
if (NULL == tts) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
int ret = -1;
int count = 0;
+ bool is_prepared = false;
while (0 != ret) {
ret = tts_dbus_request_get_private_data(client->uid, key, data);
if (0 != ret) {
- if (TTS_ERROR_TIMED_OUT != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
return ret;
} else {
*data = NULL;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, "");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return 0;
}
return TTS_ERROR_INVALID_PARAMETER;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
+ SLOG(LOG_INFO, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
client->utt_id = utt_id;
return TTS_ERROR_INVALID_PARAMETER;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
+ SLOG(LOG_INFO, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
client->utt_id = utt_id;
client->state_changed_cb = callback;
client->state_changed_user_data = user_data;
- SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set state changed cb");
+ SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
return 0;
}
return 0;
}
+int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
+{
+ if (0 != __tts_get_feature_enabled()) {
+ return TTS_ERROR_NOT_SUPPORTED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
+
+ if (NULL == tts) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ tts_client_s* client = tts_client_get(tts);
+
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (TTS_STATE_CREATED == client->current_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ int ret = -1;
+ int count = 0;
+ bool is_prepared = false;
+ while (0 != ret) {
+ ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
+ if (0 != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+ return ret;
+ } else {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add pcm : %s", __tts_get_error_code(ret));
+ usleep(10000);
+ count++;
+ if (TTS_RETRY_COUNT == count) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+ return ret;
+ }
+ }
+ }
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return TTS_ERROR_NONE;
+}
+
+int tts_play_pcm(tts_h tts)
+{
+ if (0 != __tts_get_feature_enabled()) {
+ return TTS_ERROR_NOT_SUPPORTED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
+
+ if (NULL == tts) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ tts_client_s* client = tts_client_get(tts);
+
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ int ret = -1;
+ int count = 0;
+ bool is_prepared = false;
+ while (0 != ret) {
+ ret = tts_dbus_request_play_pcm(client->uid);
+ if (0 != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+ return ret;
+ } else {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play pcm : %s", __tts_get_error_code(ret));
+ usleep(10000);
+ count++;
+ if (TTS_RETRY_COUNT == count) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+ return ret;
+ }
+ }
+ }
+ }
+
+ client->before_state = client->current_state;
+ client->current_state = TTS_STATE_PLAYING;
+
+ if (NULL != client->state_changed_cb) {
+ tts_client_use_callback(client);
+ client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+ tts_client_not_use_callback(client);
+ SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return TTS_ERROR_NONE;
+}
+
+int tts_stop_pcm(tts_h tts)
+{
+ if (0 != __tts_get_feature_enabled()) {
+ return TTS_ERROR_NOT_SUPPORTED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
+
+ if (NULL == tts) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ tts_client_s* client = tts_client_get(tts);
+
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (TTS_STATE_CREATED == client->current_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+ return TTS_ERROR_INVALID_STATE;
+ }
+
+ int ret = -1;
+ int count = 0;
+ bool is_prepared = false;
+ while (0 != ret) {
+ ret = tts_dbus_request_stop_pcm(client->uid);
+ if (0 != ret) {
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+ client->current_state = TTS_STATE_CREATED;
+ if (0 == tts_prepare_sync(tts)) {
+ is_prepared = true;
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+ }
+ } else if (TTS_ERROR_TIMED_OUT != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+ return ret;
+ } else {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop pcm : %s", __tts_get_error_code(ret));
+ usleep(10000);
+ count++;
+ if (TTS_RETRY_COUNT == count) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+ return ret;
+ }
+ }
+ }
+ }
+
+ client->before_state = client->current_state;
+ client->current_state = TTS_STATE_READY;
+
+ if (NULL != client->state_changed_cb) {
+ tts_client_use_callback(client);
+ client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+ tts_client_not_use_callback(client);
+ SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+ return TTS_ERROR_NONE;
+}