From 255fdb423aa34a3c8d4817cf893689191b15295f Mon Sep 17 00:00:00 2001 From: "sungwook79.park" Date: Fri, 2 Aug 2024 13:40:16 +0900 Subject: [PATCH] Add logic to check duplicate when personal voice is updated with ttse_send_personal_voice api Change-Id: I1a905c9a281c96256a6852bb47c7d5b1d2b51715 Signed-off-by: sungwook79.park --- common/tts_config_mgr.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ common/tts_config_mgr.h | 2 +- server/ttsd_config.c | 15 +++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index fbe5dc0..09663a9 100644 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -2514,3 +2514,52 @@ int tts_config_mgr_get_personal_voice_list(const char* engine_id, tts_config_sup return TTS_CONFIG_ERROR_NONE; } + + +int tts_config_mgr_check_duplicate_personal_voice(const char* engine_id, const char* unique_id, bool* matched) +{ + SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] engine id = %s", engine_id); + if (NULL == engine_id) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input Parameter is null"); + return TTS_CONFIG_ERROR_INVALID_PARAMETER; + } + + char filepath[512] = {'\0',}; + memset(filepath, '\0', 512); + snprintf(filepath, 512, "%s/%s-%s", TTS_DOWNLOAD_PERSONAL_INFO, engine_id, "personal.xml"); + + tts_personal_info_s* info = NULL; + int ret = tts_parser_get_personal_info(filepath, &info); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] There is no personal info file. It can be first time or fail."); + return 0; + } + + GSList *iter_personal_voice = NULL; + tts_config_personal_s* personal_voice = NULL; + *matched = false; + if (g_slist_length(info->personal_voices) > 0) { + /* Get a first item */ + iter_personal_voice = g_slist_nth(info->personal_voices, 0); + + int j = 1; + while (NULL != iter_personal_voice) { + /*Get handle data from list*/ + personal_voice = iter_personal_voice->data; + + SLOG(LOG_DEBUG, TAG_TTSCONFIG, " [%dth] unique_id(%s)", j, personal_voice->unique_id); + if (0 == strncmp(unique_id, personal_voice->unique_id, strlen(unique_id))) { + *matched = true; + break; + } + + /*Get next item*/ + iter_personal_voice = g_slist_next(iter_personal_voice); + j++; + } + } else { + return -1; + } + + return 0; +} \ No newline at end of file diff --git a/common/tts_config_mgr.h b/common/tts_config_mgr.h index ae3eeb7..a9df5f2 100644 --- a/common/tts_config_mgr.h +++ b/common/tts_config_mgr.h @@ -133,7 +133,7 @@ int tts_config_mgr_set_instant_reprepare_client(const unsigned int uid); int tts_config_mgr_update_personal_voice(const char* engine_id, const char* language, const char* unique_id, const char* display_name, const char* device_name); int tts_config_mgr_get_personal_voice_list(const char* engine_id, tts_config_supported_personal_voice_cb callback, void* user_data); - +int tts_config_mgr_check_duplicate_personal_voice(const char* engine_id, const char* unique_id, bool* matched); #ifdef __cplusplus } diff --git a/server/ttsd_config.c b/server/ttsd_config.c index 13cbbbc..7bf7ccb 100644 --- a/server/ttsd_config.c +++ b/server/ttsd_config.c @@ -274,12 +274,23 @@ int ttsd_config_update_personal_voice(const char* language, const char* unique_i SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS Current Engine(%s)", current_engine); int ret = tts_config_mgr_update_personal_voice(current_engine, language, unique_id, display_name, device_name); + + bool matched = false; + ret = tts_config_mgr_check_duplicate_personal_voice(current_engine, unique_id, &matched); if (0 != ret) { - SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to update personal voice to xml"); + SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to check duplicate personal voice"); return TTSD_ERROR_OPERATION_FAILED; } - return 0; + if (!matched) { + ret = tts_config_mgr_update_personal_voice(current_engine, language, unique_id, display_name, device_name); + if (0 != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to update personal voice to xml"); + return TTSD_ERROR_OPERATION_FAILED; + } + } + + return ret; } bool __ttsd_config_personal_voices(const char* language, const char* unique_id, const char* display_name, const char* device_name, void* user_data) -- 2.7.4