}
}
+inline static bool __is_agent_initialized()
+{
+ if (false == g_agent_init) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+ return false;
+ }
+
+ if (NULL == g_engine_info) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No engine info");
+ return false;
+ }
+
+ return true;
+}
+
+inline static bool __is_engine_loaded()
+{
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
+ return false;
+ }
+
+ return true;
+}
+
+inline static int __check_engine_initialized_and_loaded()
+{
+ if (false == __is_agent_initialized()) {
+ return TTSD_ERROR_INVALID_STATE;
+ }
+
+ if (false == __is_engine_loaded()) {
+ return TTSD_ERROR_ENGINE_NOT_FOUND;
+ }
+
+ return TTSD_ERROR_NONE;
+}
+
int ttsd_engine_agent_init()
{
- if (true == g_agent_init) {
+ if (__is_agent_initialized()) {
SLOG(LOG_WARN, tts_tag(), "[Engine Agent] Already initialized");
return TTSD_ERROR_NONE;
}
int ttsd_engine_agent_release()
{
- if (false == g_agent_init) {
+ if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return TTSD_ERROR_INVALID_STATE;
}
/* unload current engine */
- if (g_engine_info->is_loaded) {
+ if (__is_engine_loaded()) {
ttsd_engine_agent_unload_current_engine();
}
return true;
}
-static int __update_voice_list()
+static void __clear_voice_list()
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
+ if (NULL == g_cur_voices) {
+ return;
}
- /* Get voice list */
- if (NULL != g_cur_voices) {
- GSList *iter = NULL;
- ttsvoice_s* data = NULL;
-
- iter = g_slist_nth(g_cur_voices, 0);
- while (NULL != iter) {
- data = iter->data;
-
- if (NULL != data) {
- if (NULL != data->lang) {
- free(data->lang);
- data->lang = NULL;
- }
+ GSList *iter = g_slist_nth(g_cur_voices, 0);
+ while (NULL != iter) {
+ ttsvoice_s* data = iter->data;
- g_cur_voices = g_slist_remove(g_cur_voices, data);
- free(data);
- data = NULL;
+ if (NULL != data) {
+ if (NULL != data->lang) {
+ free(data->lang);
+ data->lang = NULL;
}
- iter = g_slist_nth(g_cur_voices, 0);
+ g_cur_voices = g_slist_remove(g_cur_voices, data);
+ free(data);
+ data = NULL;
}
+
+ iter = g_slist_nth(g_cur_voices, 0);
}
+ g_slist_free(g_cur_voices);
g_cur_voices = NULL;
+}
+
+static int __update_voice_list()
+{
+ if (false == __is_agent_initialized()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+ return TTSD_ERROR_INVALID_STATE;
+ }
+
+ __clear_voice_list();
int ret = -1;
ret = g_engine_info->callbacks->foreach_voices(__set_voice_info_cb, NULL);
{
SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent DEBUG] load current engine START");
-
- if (false == g_agent_init) {
+ if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return TTSD_ERROR_INVALID_STATE;
}
}
/* check whether current engine is loaded or not */
- if (true == g_engine_info->is_loaded) {
+ if (__is_engine_loaded()) {
SLOG(LOG_INFO, tts_tag(), "[Engine Agent] Engine has already been loaded ");
return TTSD_ERROR_NONE;
}
int ttsd_engine_agent_unload_current_engine()
{
- if (false == g_agent_init) {
+ if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return TTSD_ERROR_INVALID_STATE;
}
- if (false == g_engine_info->is_loaded) {
+ if (false == __is_engine_loaded()) {
SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent] Engine has already been unloaded ");
return TTSD_ERROR_NONE;
}
/* reset current engine data */
g_engine_info->is_loaded = false;
- GSList *iter = NULL;
- ttsvoice_s* data = NULL;
-
- iter = g_slist_nth(g_cur_voices, 0);
- while (NULL != iter) {
- data = iter->data;
-
- if (NULL != data) {
- if (NULL != data->lang) {
- free(data->lang);
- data->lang = NULL;
- }
- g_cur_voices = g_slist_remove(g_cur_voices, data);
- free(data);
- data = NULL;
- }
-
- iter = g_slist_nth(g_cur_voices, 0);
- }
+ __clear_voice_list();
SLOG(LOG_DEBUG, tts_tag(), "[Engine Agent Success] Unload current engine");
bool ttsd_engine_agent_need_network()
{
- if (false == g_agent_init) {
+ if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return false;
}
bool ttsd_engine_agent_is_same_engine(const char* engine_id)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return false;
- }
-
if (NULL == engine_id) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] engine_id is NULL");
return false;
}
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] g_engine_info is NULL");
- return false;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not loaded engine");
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
return false;
}
return false;
}
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] g_engine_info is NULL");
- return false;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_WARN, tts_tag(), "[Engine Agent WARNING] Not loaded engine");
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
return false;
}
/* Get voice list */
GList* voice_list = NULL;
- int ret = 0;
ret = g_engine_info->callbacks->foreach_voices(__supported_voice_cb, &voice_list);
if (0 != ret || 0 >= g_list_length(voice_list)) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] fail to get voice list : result(%d)", ret);
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] g_engine_info is NULL");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
- int ret = -1;
bool is_valid = false;
ret = g_engine_info->callbacks->is_valid_voice(language, vctype, &is_valid);
if (0 == ret) {
int ttsd_engine_agent_set_default_speed(int speed)
{
- if (false == g_agent_init) {
+ if (false == __is_agent_initialized()) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
return TTSD_ERROR_INVALID_STATE;
}
int ttsd_engine_agent_set_default_pitch(int pitch)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No engine info");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
- int ret = g_engine_info->callbacks->set_pitch(pitch);
+ ret = g_engine_info->callbacks->set_pitch(pitch);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to set pitch : pitch(%d), result(%s)",
pitch, __ttsd_get_engine_error_code(ret));
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not loaded engine");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == g_engine_info->callbacks->need_app_credential) {
int ttsd_engine_load_voice(const char* lang, const int vctype)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == lang) {
}
/* 1. Find voice info */
- int ret = -1;
ttsvoice_s* data = __get_ttsvoice(lang, vctype);
if (NULL == data) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] This voice is not supported voice : lang(%s) type(%d)", lang, vctype);
int ttsd_engine_unload_voice(const char* lang, const int vctype)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == lang) {
}
/* 1. Find voice info */
- int ret = -1;
ttsvoice_s* data = __get_ttsvoice(lang, vctype);
if (NULL == data) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] This voice is not supported voice : lang(%s) type(%d)", lang, vctype);
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
/* select voice for default */
}
/* synthesize text */
- int ret = 0;
ret = g_engine_info->callbacks->start_synth(temp_lang, temp_type, text, temp_speed, appid, credential, user_param);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] ***************************************");
int ttsd_engine_cancel_synthesis()
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
SLOG(LOG_INFO, tts_tag(), "[Engine Agent] Cancel synth");
/* stop synthesis */
- int ret = 0;
ret = g_engine_info->callbacks->cancel_synth();
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] fail cancel synthesis : %s", __ttsd_get_engine_error_code(ret));
return TTSD_ERROR_INVALID_PARAMETER;
}
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
- int ret = 0;
ret = g_engine_info->callbacks->foreach_voices(__supported_voice_cb, (void*)voice_list);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get voice list : %s", __ttsd_get_engine_error_code(ret));
int ttsd_engine_get_default_voice(char** lang, int* vctype)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == lang || NULL == vctype) {
int ttsd_engine_set_private_data(const char* key, const char* data)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == key) {
return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
}
- int ret = g_engine_info->callbacks->private_data_set(key, data);
-
+ ret = g_engine_info->callbacks->private_data_set(key, data);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to set private data(%d)", ret);
}
int ttsd_engine_get_private_data(const char* key, char** data)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == key || NULL == data) {
}
char* temp = NULL;
- int ret = 0;
ret = g_engine_info->callbacks->private_data_requested(key, &temp);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to get private data(%d)", ret);
int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
- return TTSD_ERROR_ENGINE_NOT_FOUND;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
if (NULL == appid || NULL == is_agreed) {
return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
}
- int ret = 0;
bool tmp = true; // default value is true until now
ret = g_engine_info->callbacks->check_app_agreed(appid, &tmp);
if (0 != ret) {
/** Set callbacks of the current engine */
int ttsd_engine_agent_set_private_data_set_cb(ttse_private_data_set_cb callback)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] The engine is not valid");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not loaded engine");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
g_engine_info->callbacks->private_data_set = callback;
int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (NULL == g_engine_info) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] The engine is not valid");
- return TTSD_ERROR_INVALID_STATE;
- }
-
- if (false == g_engine_info->is_loaded) {
- SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not loaded engine");
- return TTSD_ERROR_OPERATION_FAILED;
+ int ret = __check_engine_initialized_and_loaded();
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Precondition is not met(%s)", get_error_message(ret));
+ return ret;
}
g_engine_info->callbacks->private_data_requested = callback;