2 * Copyright (c) 2011 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.
18 #include "ttsd_main.h"
19 #include "ttsd_engine_agent.h"
20 #include "ttsd_config.h"
22 #define ENGINE_PATH_SIZE 256
25 * Internal data structure
33 /* info for using engine load*/
39 /* engine base setting */
44 ttspe_funcs_s* pefuncs;
45 ttspd_funcs_s* pdfuncs;
47 int (*ttsp_load_engine)(const ttspd_funcs_s* pdfuncs, ttspe_funcs_s* pefuncs);
48 int (*ttsp_unload_engine)();
55 char* setting_ug_path;
61 static bool g_agent_init;
63 /** TTS engine list */
64 static GList *g_engine_list;
66 /** Current engine information */
67 static ttsengine_s g_cur_engine;
69 /** Result callback function */
70 static synth_result_callback g_result_cb;
73 /** Set current engine */
74 int __internal_set_current_engine(const char* engine_uuid);
76 /** Check engine id */
77 int __internal_check_engine_id(const char* engine_uuid);
79 /** Update engine list */
80 int __internal_update_engine_list();
82 /** Get engine info */
83 int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info);
85 /** Callback function for result */
86 bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data);
88 /** Callback function for voice list */
89 bool __supported_voice_cb(const char* language, ttsp_voice_type_e type, void* user_data);
91 /** Free voice list */
92 void __free_voice_list(GList* voice_list);
94 /** Callback function for engine info */
95 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
96 bool use_network, void* user_data);
98 /** Callback fucntion for engine setting */
99 bool __engine_setting_cb(const char* key, const char* value, void* user_data);
102 int ttsd_engine_agent_init(synth_result_callback result_cb)
104 /* initialize static data */
105 if (result_cb == NULL) {
106 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] invalid parameter \n");
107 return TTSD_ERROR_INVALID_PARAMETER;
110 g_result_cb = result_cb;
112 g_cur_engine.engine_uuid = NULL;
113 g_cur_engine.engine_name = NULL;
114 g_cur_engine.engine_path = NULL;
116 g_cur_engine.is_set = false;
117 g_cur_engine.handle = NULL;
118 g_cur_engine.pefuncs = (ttspe_funcs_s*)g_malloc0( sizeof(ttspe_funcs_s) );
119 g_cur_engine.pdfuncs = (ttspd_funcs_s*)g_malloc0( sizeof(ttspd_funcs_s) );
123 if (0 != ttsd_config_get_default_voice(&(g_cur_engine.default_lang), &(g_cur_engine.default_vctype))) {
124 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] There is No default voice in config\n");
125 /* Set default voice */
126 g_cur_engine.default_lang = strdup("en_US");
127 g_cur_engine.default_vctype = TTSP_VOICE_TYPE_FEMALE;
130 if (0 != ttsd_config_get_default_speed(&(g_cur_engine.default_speed))) {
131 SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] There is No default speed in config\n");
132 ttsd_config_set_default_speed((int)TTSP_SPEED_NORMAL);
133 g_cur_engine.default_speed = TTSP_SPEED_NORMAL;
136 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Initialize Engine Agent ");
141 int ttsd_engine_agent_release()
143 if (false == g_agent_init) {
144 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
145 return TTSD_ERROR_OPERATION_FAILED;
148 /* unload current engine */
149 ttsd_engine_agent_unload_current_engine();
151 /* release engine list */
153 ttsengine_s *data = NULL;
155 if (g_list_length(g_engine_list) > 0) {
156 /* Get a first item */
157 iter = g_list_first(g_engine_list);
159 while (NULL != iter) {
160 /* Get data from item */
162 dlclose(data->handle);
164 iter = g_list_remove(iter, data);
170 /* release current engine data */
171 if (g_cur_engine.pefuncs != NULL)
172 g_free(g_cur_engine.pefuncs);
174 if (g_cur_engine.pdfuncs != NULL)
175 g_free(g_cur_engine.pdfuncs);
178 g_agent_init = false;
180 if (g_cur_engine.default_lang != NULL)
181 g_free(g_cur_engine.default_lang);
184 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Release Engine Agent\n");
189 int ttsd_engine_agent_initialize_current_engine()
191 if (false == g_agent_init) {
192 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
193 return TTSD_ERROR_OPERATION_FAILED;
196 /* update engine list */
197 if (0 != __internal_update_engine_list()) {
198 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent WARNING] No engine error \n");
199 return TTSD_ERROR_OPERATION_FAILED;
202 /* 2. get current engine from config */
203 char* cur_engine_uuid = NULL;
204 bool is_get_engineid_from_config = false;
206 if (0 != ttsd_config_get_default_engine(&cur_engine_uuid)) {
207 /*not set current engine */
208 /*set system default engine*/
210 ttsengine_info_s *data = NULL;
212 if (g_list_length(g_engine_list) > 0) {
213 iter = g_list_first(g_engine_list);
214 char* default_engine = "27F277E9-BBC4-4dca-B553-D9884A3CDAA0";
216 while (NULL != iter) {
219 if (0 == strncmp(data->engine_uuid, default_engine, strlen(default_engine))) {
220 /* current data is default engine */
224 iter = g_list_next(iter);
227 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent WARNING] Fail to set a engine of engine list\n");
228 return TTSD_ERROR_OPERATION_FAILED;
231 if (NULL != data->engine_uuid) {
232 cur_engine_uuid = strdup(data->engine_uuid);
234 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Data of current engine is corrupt\n");
235 return TTSD_ERROR_OPERATION_FAILED;
238 is_get_engineid_from_config = false;
240 is_get_engineid_from_config = true;
243 /* check whether cur engine uuid is valid or not. */
244 if (0 != __internal_check_engine_id(cur_engine_uuid)) {
245 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent WARNING] It is not valid engine id from config \n");
249 if (g_list_length(g_engine_list) > 0)
250 iter = g_list_first(g_engine_list);
252 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent ERROR] NO TTS Engine !! \n");
253 return TTSD_ERROR_OPERATION_FAILED;
256 if (cur_engine_uuid != NULL)
257 g_free(cur_engine_uuid);
259 ttsengine_info_s *data = NULL;
262 cur_engine_uuid = g_strdup(data->engine_uuid);
264 is_get_engineid_from_config = false;
267 if (NULL != cur_engine_uuid)
268 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Current Engine Id : %s \n", cur_engine_uuid);
270 return TTSD_ERROR_OPERATION_FAILED;
272 /* set current engine */
273 if (0 != __internal_set_current_engine(cur_engine_uuid)) {
274 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to set current engine ");
275 return TTSD_ERROR_OPERATION_FAILED;
278 if (false == is_get_engineid_from_config) {
279 if (0 != ttsd_config_set_default_engine(cur_engine_uuid))
280 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to set id to config \n");
283 if (NULL != cur_engine_uuid)
284 g_free(cur_engine_uuid);
286 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Set current engine");
291 int __internal_check_engine_id(const char* engine_uuid)
294 ttsengine_s *data = NULL;
296 if (g_list_length(g_engine_list) > 0) {
297 iter = g_list_first(g_engine_list);
299 while (NULL != iter) {
302 if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid)))
305 iter = g_list_next(iter);
312 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
313 bool use_network, void* user_data)
315 ttsengine_info_s* temp = (ttsengine_info_s*)user_data;
317 temp->engine_uuid = g_strdup(engine_uuid);
318 temp->engine_name = g_strdup(engine_name);
319 temp->setting_ug_path = g_strdup(setting_ug_name);
320 temp->use_network = use_network;
323 int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
328 handle = dlopen (filepath, RTLD_LAZY );
331 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent] Invalid engine : %s", filepath);
332 return TTSD_ERROR_OPERATION_FAILED;
335 /* link engine to daemon */
336 dlsym(handle, "ttsp_load_engine");
337 if ((error = dlerror()) != NULL) {
338 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent] Invalid engine. Fail to open ttsp_load_engine : %s", filepath);
340 return TTSD_ERROR_OPERATION_FAILED;
343 dlsym(handle, "ttsp_unload_engine");
344 if ((error = dlerror()) != NULL) {
345 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent] Invalid engine. Fail to open ttsp_unload_engine : %s", filepath);
347 return TTSD_ERROR_OPERATION_FAILED;
350 int (*get_engine_info)(ttsp_engine_info_cb callback, void* user_data);
352 get_engine_info = (int (*)(ttsp_engine_info_cb, void*))dlsym(handle, "ttsp_get_engine_info");
353 if (NULL != (error = dlerror()) || NULL == get_engine_info) {
354 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent] ttsp_get_engine_info() link error");
356 return TTSD_ERROR_OPERATION_FAILED;
359 ttsengine_info_s* temp;
360 temp = (ttsengine_info_s*)g_malloc0(sizeof(ttsengine_info_s));
362 /* get engine info */
363 if (0 != get_engine_info(&__engine_info_cb, (void*)temp)) {
364 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to get engine info");
367 return TTSD_ERROR_OPERATION_FAILED;
373 temp->engine_path = g_strdup(filepath);
375 SLOG(LOG_DEBUG, TAG_TTSD, "----- Valid engine");
376 SLOG(LOG_DEBUG, TAG_TTSD, "Engine uuid : %s", temp->engine_uuid);
377 SLOG(LOG_DEBUG, TAG_TTSD, "Engine name : %s", temp->engine_name);
378 SLOG(LOG_DEBUG, TAG_TTSD, "Setting ug path : %s", temp->setting_ug_path);
379 SLOG(LOG_DEBUG, TAG_TTSD, "Engine path : %s", temp->engine_path);
380 SLOG(LOG_DEBUG, TAG_TTSD, "Use network : %s", temp->use_network ? "true":"false");
381 SLOG(LOG_DEBUG, TAG_TTSD, "-----");
382 SLOG(LOG_DEBUG, TAG_TTSD, " ");
389 int __internal_update_engine_list()
391 /* relsease engine list */
393 ttsengine_info_s *data = NULL;
395 if (g_list_length(g_engine_list) > 0) {
396 iter = g_list_first(g_engine_list);
398 while (NULL != iter) {
404 g_engine_list = g_list_remove_link(g_engine_list, iter);
405 iter = g_list_first(g_engine_list);
409 /* get file name from engine directory and get engine information from each filename */
412 dp = opendir(ENGINE_DIRECTORY_DEFAULT);
415 while ((dirp = readdir(dp)) != NULL) {
416 ttsengine_info_s* info;
417 char* filepath = NULL;
420 file_size = strlen(ENGINE_DIRECTORY_DEFAULT) + strlen(dirp->d_name) + 5;
421 filepath = (char*)g_malloc0( sizeof(char) * file_size);
423 if (NULL != filepath) {
424 strncpy(filepath, ENGINE_DIRECTORY_DEFAULT, strlen(ENGINE_DIRECTORY_DEFAULT) );
425 strncat(filepath, "/", strlen("/") );
426 strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
428 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not enough memory!! \n" );
432 /* get its info and update engine list */
433 if (0 == __internal_get_engine_info(filepath, &info)) {
434 /* add engine info to g_engine_list */
435 g_engine_list = g_list_append(g_engine_list, info);
438 if (NULL != filepath)
445 dp = opendir(ENGINE_DIRECTORY_DOWNLOAD);
448 while ((dirp = readdir(dp)) != NULL) {
449 ttsengine_info_s* info;
450 char* filepath = NULL;
453 file_size = strlen(ENGINE_DIRECTORY_DOWNLOAD) + strlen(dirp->d_name) + 5;
454 filepath = (char*)g_malloc0( sizeof(char) * file_size);
456 if (NULL != filepath) {
457 strcpy(filepath, ENGINE_DIRECTORY_DOWNLOAD);
458 strcat(filepath, "/");
459 strcat(filepath, dirp->d_name);
461 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not enough memory!! \n" );
465 /* get its info and update engine list */
466 if (0 == __internal_get_engine_info(filepath, &info)) {
467 /* add engine info to g_engine_list */
468 g_engine_list = g_list_append(g_engine_list, info);
471 if (NULL != filepath)
478 if (g_list_length(g_engine_list) <= 0) {
479 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] No Engine\n");
480 return TTSD_ERROR_OPERATION_FAILED;
483 #ifdef ENGINE_AGENT_DEBUG
484 ttsd_print_enginelist();
490 int __internal_set_current_engine(const char* engine_uuid)
492 /* check whether engine id is valid or not. */
494 ttsengine_info_s *data = NULL;
497 if (g_list_length(g_engine_list) > 0) {
498 iter = g_list_first(g_engine_list);
500 while (NULL != iter) {
503 if (0 == strncmp(data->engine_uuid, engine_uuid, strlen(engine_uuid))) {
509 iter = g_list_next(iter);
513 /* If current engine does not exist, return error */
515 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] __internal_set_current_engine : Cannot find engine id \n");
516 return TTSD_ERROR_OPERATION_FAILED;
518 if (g_cur_engine.engine_uuid != NULL) {
519 /*compare current engine uuid */
520 if (0 == strncmp(g_cur_engine.engine_uuid, data->engine_uuid, strlen(engine_uuid))) {
521 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] tts engine has already been set \n");
527 /* set data from g_engine_list */
528 if (g_cur_engine.engine_uuid != NULL) g_free(g_cur_engine.engine_uuid);
529 if (g_cur_engine.engine_name != NULL) g_free(g_cur_engine.engine_name);
530 if (g_cur_engine.engine_path != NULL) g_free(g_cur_engine.engine_path);
532 if (NULL == data->engine_uuid || NULL == data->engine_name || NULL == data->engine_path) {
533 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] __internal_set_current_engine : Engine data is NULL");
534 return TTSD_ERROR_OPERATION_FAILED;
537 g_cur_engine.engine_uuid = g_strdup(data->engine_uuid);
538 g_cur_engine.engine_name = g_strdup(data->engine_name);
539 g_cur_engine.engine_path = g_strdup(data->engine_path);
541 g_cur_engine.handle = NULL;
542 g_cur_engine.is_loaded = false;
543 g_cur_engine.is_set = true;
544 g_cur_engine.need_network = data->use_network;
546 SLOG(LOG_DEBUG, TAG_TTSD, "-----");
547 SLOG(LOG_DEBUG, TAG_TTSD, "Current engine uuid : %s \n", g_cur_engine.engine_uuid);
548 SLOG(LOG_DEBUG, TAG_TTSD, "Current engine name : %s \n", g_cur_engine.engine_name);
549 SLOG(LOG_DEBUG, TAG_TTSD, "Current engine path : %s \n", g_cur_engine.engine_path);
550 SLOG(LOG_DEBUG, TAG_TTSD, "-----");
555 int ttsd_engine_agent_load_current_engine()
557 if (false == g_agent_init) {
558 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
559 return TTSD_ERROR_OPERATION_FAILED;
562 if (false == g_cur_engine.is_set) {
563 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : No Current Engine \n");
564 return TTSD_ERROR_OPERATION_FAILED;
567 /* check whether current engine is loaded or not */
568 if (true == g_cur_engine.is_loaded ) {
569 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent] ttsd_engine_agent_load_current_engine : Engine has already been loaded \n" );
573 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] current engine path : %s\n", g_cur_engine.engine_path);
577 g_cur_engine.handle = dlopen(g_cur_engine.engine_path, RTLD_LAZY); /* RTLD_LAZY RTLD_NOW*/
579 if ((error = dlerror()) != NULL || !g_cur_engine.handle) {
580 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to get current engine handle : dlopen error \n");
584 g_cur_engine.ttsp_unload_engine = (int (*)())dlsym(g_cur_engine.handle, "ttsp_unload_engine");
585 if ((error = dlerror()) != NULL) {
586 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to link daemon to ttsp_unload_engine() of current engine\n");
590 g_cur_engine.ttsp_load_engine = (int (*)(const ttspd_funcs_s* , ttspe_funcs_s*) )dlsym(g_cur_engine.handle, "ttsp_load_engine");
591 if (NULL != (error = dlerror()) || NULL == g_cur_engine.ttsp_load_engine) {
592 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to link daemon to ttsp_load_engine() of current engine \n");
597 g_cur_engine.pdfuncs->version = 1;
598 g_cur_engine.pdfuncs->size = sizeof(ttspd_funcs_s);
601 ret = g_cur_engine.ttsp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs);
603 printf("Fail load '%s' engine\n", g_cur_engine.engine_path);
604 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to load engine : result(%d) \n");
605 return TTSD_ERROR_OPERATION_FAILED;
608 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] engine info : version(%d), size(%d)\n",g_cur_engine.pefuncs->version, g_cur_engine.pefuncs->size );
610 /* engine error check */
611 if (g_cur_engine.pefuncs->size != sizeof(ttspe_funcs_s)) {
612 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : current engine is not valid \n");
613 return TTSD_ERROR_OPERATION_FAILED;
616 /* initalize engine */
617 if (NULL == g_cur_engine.pefuncs->initialize) {
618 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] init function of engine is NULL!!");
619 return TTSD_ERROR_OPERATION_FAILED;
622 ret = g_cur_engine.pefuncs->initialize(__result_cb);
624 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to initialize current engine : result(%d)\n", ret);
625 return TTSD_ERROR_OPERATION_FAILED;
628 /* select default voice */
629 bool set_voice = false;
630 if (NULL != g_cur_engine.default_lang) {
631 if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
632 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] is_valid_voice() of engine is NULL!!");
633 return TTSD_ERROR_OPERATION_FAILED;
636 if (true == g_cur_engine.pefuncs->is_valid_voice(g_cur_engine.default_lang, g_cur_engine.default_vctype)) {
638 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s), type(%d) \n",
639 g_cur_engine.default_lang, g_cur_engine.default_vctype);
641 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent WARNING] Fail set origin default voice : lang(%s), type(%d)\n",
642 g_cur_engine.default_lang, g_cur_engine.default_vctype);
646 if (false == set_voice) {
647 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
648 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
649 return TTSD_ERROR_OPERATION_FAILED;
652 /* get language list */
654 GList* voice_list = NULL;
656 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
658 if (0 == ret && 0 < g_list_length(voice_list)) {
662 iter = g_list_first(voice_list);
667 if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
668 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail voice is NOT valid");
669 return TTSD_ERROR_OPERATION_FAILED;
672 ttsd_config_set_default_voice(voice->language, (int)voice->type);
674 g_cur_engine.default_lang = g_strdup(voice->language);
675 g_cur_engine.default_vctype = voice->type;
677 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Select default voice : lang(%s), type(%d) \n",
678 voice->language, voice->type);
682 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
683 return TTSD_ERROR_OPERATION_FAILED;
686 __free_voice_list(voice_list);
688 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
689 return TTSD_ERROR_OPERATION_FAILED;
693 g_cur_engine.is_loaded = true;
698 int ttsd_engine_agent_unload_current_engine()
700 if (false == g_agent_init) {
701 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
702 return TTSD_ERROR_OPERATION_FAILED;
705 if (false == g_cur_engine.is_set) {
706 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] No Current Engine \n");
707 return TTSD_ERROR_OPERATION_FAILED;
710 if (false == g_cur_engine.is_loaded) {
711 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Engine has already been unloaded \n" );
715 /* shutdown engine */
716 if (NULL == g_cur_engine.pefuncs->deinitialize) {
717 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] The deinitialize() of engine is NULL!!");
720 ret = g_cur_engine.pefuncs->deinitialize();
722 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent] Fail deinitialize() : result(%d)\n", ret);
727 g_cur_engine.ttsp_unload_engine();
729 dlclose(g_cur_engine.handle);
731 /* reset current engine data */
732 g_cur_engine.handle = NULL;
733 g_cur_engine.is_loaded = false;
738 bool ttsd_engine_agent_need_network()
740 if (false == g_agent_init) {
741 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
742 return TTSD_ERROR_OPERATION_FAILED;
745 if (false == g_cur_engine.is_loaded) {
746 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
747 return TTSD_ERROR_OPERATION_FAILED;
750 return g_cur_engine.need_network;
753 bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang, ttsp_voice_type_e* out_type)
755 if (NULL == lang || NULL == out_lang || NULL == out_type) {
759 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Select voice : input lang(%s) , input type(%d), default lang(%s), default type(%d)",
760 lang, type, g_cur_engine.default_lang, g_cur_engine.default_vctype);
763 /* case 1 : Both are default */
764 if (0 == strncmp(lang, "default", strlen("default")) && 0 == type) {
765 *out_lang = strdup(g_cur_engine.default_lang);
766 *out_type = g_cur_engine.default_vctype;
772 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
773 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] foreach_voices of engine is NULL!!");
774 return TTSD_ERROR_OPERATION_FAILED;
777 GList* voice_list = NULL;
780 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
781 if (0 != ret || 0 >= g_list_length(voice_list)) {
782 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to get voice list : result(%d) \n", ret);
792 /* lang and type are not default type */
793 if (0 != strncmp(lang, "default", strlen("default")) && 0 != type) {
794 iter = g_list_first(voice_list);
796 while (NULL != iter) {
797 /* Get handle data from list */
800 if (0 == strncmp(voice->language, lang, strlen(lang)) && voice->type == type) {
801 *out_lang = strdup(voice->language);
802 *out_type = voice->type;
807 iter = g_list_next(iter);
810 } else if (0 != strncmp(lang, "default", strlen("default")) && 0 == type) {
811 /* Only type is default */
812 if (0 == strncmp(lang, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang))) {
813 *out_lang = strdup(g_cur_engine.default_lang);
814 *out_type = g_cur_engine.default_vctype;
817 voice_s* voice_selected = NULL;
818 iter = g_list_first(voice_list);
819 while (NULL != iter) {
820 /* Get handle data from list */
823 if (0 == strncmp(voice->language, lang, strlen(lang))) {
824 voice_selected = voice;
825 if (voice->type == g_cur_engine.default_vctype) {
826 voice_selected = voice;
830 iter = g_list_next(iter);
833 if (NULL != voice_selected) {
834 *out_lang = strdup(voice_selected->language);
835 *out_type = voice_selected->type;
839 } else if (0 == strncmp(lang, "default", strlen("default")) && 0 != type) {
840 /* Only lang is default */
841 if (type == g_cur_engine.default_vctype) {
842 *out_lang = strdup(g_cur_engine.default_lang);
843 *out_type = g_cur_engine.default_vctype;
846 voice_s* voice_selected = NULL;
847 iter = g_list_first(voice_list);
848 while (NULL != iter) {
849 /* Get handle data from list */
852 if (0 == strncmp(voice->language, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang)) ) {
853 voice_selected = voice;
854 if (voice->type == type) {
855 voice_selected = voice;
859 iter = g_list_next(iter);
862 if (NULL != voice_selected) {
863 *out_lang = strdup(voice->language);
864 *out_type = voice_selected->type;
870 if (true == result) {
871 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Selected voice : lang(%s), type(%d) \n", *out_lang, *out_type);
874 __free_voice_list(voice_list);
879 bool ttsd_engine_agent_is_same_engine(const char* engine_id)
881 if (false == g_agent_init) {
882 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
886 if (false == g_cur_engine.is_loaded) {
887 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
891 /* compare current engine and engine id.*/
892 if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
899 /******************************************************************************************
900 * TTS Engine Interfaces for client
901 *******************************************************************************************/
903 int ttsd_engine_start_synthesis(const char* lang, const ttsp_voice_type_e vctype, const char* text, const int speed, void* user_param)
905 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] start ttsd_engine_start_synthesis() \n");
907 if (false == g_agent_init) {
908 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
909 return TTSD_ERROR_OPERATION_FAILED;
912 if (false == g_cur_engine.is_loaded) {
913 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
914 return TTSD_ERROR_OPERATION_FAILED;
917 /* select voice for default */
918 char* temp_lang = NULL;
919 ttsp_voice_type_e temp_type;
920 if (true != ttsd_engine_select_valid_voice(lang, vctype, &temp_lang, &temp_type)) {
921 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Fail to select default voice \n");
922 return TTSD_ERROR_INVALID_VOICE;
924 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s) \n",
925 temp_lang, temp_type, speed, text);
928 if (NULL == g_cur_engine.pefuncs->start_synth) {
929 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] start_synth() of engine is NULL!!");
930 return TTSD_ERROR_OPERATION_FAILED;
933 ttsp_speed_e temp_speed;
936 temp_speed = g_cur_engine.default_speed;
941 /* synthesize text */
943 ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, user_param);
945 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] ***************************************", ret);
946 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] * synthesize error : result(%6d) *", ret);
947 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] ***************************************", ret);
948 return TTSD_ERROR_OPERATION_FAILED;
951 if (NULL == temp_lang)
958 int ttsd_engine_cancel_synthesis()
960 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] start ttsd_engine_cancel_synthesis() \n");
962 if (false == g_agent_init) {
963 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
964 return TTSD_ERROR_OPERATION_FAILED;
967 if (false == g_cur_engine.is_loaded) {
968 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
969 return TTSD_ERROR_OPERATION_FAILED;
972 if (NULL == g_cur_engine.pefuncs->cancel_synth) {
973 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] cancel_synth() of engine is NULL!!");
974 return TTSD_ERROR_OPERATION_FAILED;
979 ret = g_cur_engine.pefuncs->cancel_synth();
981 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail cancel synthesis : result(%d) \n", ret);
982 return TTSD_ERROR_OPERATION_FAILED;
988 int ttsd_engine_get_audio_format( ttsp_audio_type_e* type, int* rate, int* channels)
990 if (false == g_agent_init) {
991 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
992 return TTSD_ERROR_OPERATION_FAILED;
995 if (false == g_cur_engine.is_loaded) {
996 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
997 return TTSD_ERROR_OPERATION_FAILED;
1000 if (NULL == g_cur_engine.pefuncs->get_audio_format) {
1001 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] get_audio_format() of engine is NULL!!");
1002 return TTSD_ERROR_OPERATION_FAILED;
1006 ret = g_cur_engine.pefuncs->get_audio_format(type, rate, channels);
1008 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to get audio format : result(%d) \n", ret);
1009 return TTSD_ERROR_OPERATION_FAILED;
1011 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] get audio format : type(%d), rate(%d), channel(%d) \n", *type, *rate, *channels);
1016 bool __supported_voice_cb(const char* language, ttsp_voice_type_e type, void* user_data)
1018 GList** voice_list = (GList**)user_data;
1020 if (NULL == language || NULL == voice_list) {
1021 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Input parameter is NULL in voice list callback!!!!");
1025 SLOG(LOG_DEBUG, TAG_TTSD, "-- Language(%s), Type(%d)", language, type);
1027 voice_s* voice = g_malloc0(sizeof(voice_s));
1028 voice->language = strdup(language);
1031 *voice_list = g_list_append(*voice_list, voice);
1036 int ttsd_engine_get_voice_list(GList** voice_list)
1038 if (false == g_agent_init) {
1039 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1040 return TTSD_ERROR_OPERATION_FAILED;
1043 if (false == g_cur_engine.is_loaded) {
1044 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1045 return TTSD_ERROR_OPERATION_FAILED;
1048 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
1049 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] The function of engine is NULL!!");
1050 return TTSD_ERROR_OPERATION_FAILED;
1054 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, (void*)voice_list);
1056 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Fail to get voice list : result(%d) \n", ret);
1057 return TTSD_ERROR_OPERATION_FAILED;
1063 int ttsd_engine_get_default_voice( char** lang, ttsp_voice_type_e* vctype )
1065 if (false == g_agent_init) {
1066 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1067 return TTSD_ERROR_OPERATION_FAILED;
1070 if (false == g_cur_engine.is_loaded) {
1071 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1072 return TTSD_ERROR_OPERATION_FAILED;
1075 if (NULL == lang || NULL == vctype) {
1076 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] BAD Parameter \n");
1077 return TTSD_ERROR_INVALID_PARAMETER;
1080 if (NULL != g_cur_engine.default_lang) {
1081 *lang = g_strdup(g_cur_engine.default_lang);
1082 *vctype = g_cur_engine.default_vctype;
1084 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine] Get default voice : language(%s), type(%d)\n", *lang, *vctype);
1086 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
1087 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
1088 return TTSD_ERROR_OPERATION_FAILED;
1091 /* get language list */
1093 GList* voice_list = NULL;
1095 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
1097 if (0 == ret && 0 < g_list_length(voice_list)) {
1101 iter = g_list_first(voice_list);
1106 if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
1107 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail voice is NOT valid ");
1108 return TTSD_ERROR_OPERATION_FAILED;
1111 ttsd_config_set_default_voice(voice->language, (int)voice->type);
1113 if (NULL != g_cur_engine.default_lang)
1114 g_free(g_cur_engine.default_lang);
1116 g_cur_engine.default_lang = g_strdup(voice->language);
1117 g_cur_engine.default_vctype = voice->type;
1119 *lang = g_strdup(g_cur_engine.default_lang);
1120 *vctype = g_cur_engine.default_vctype = voice->type;
1122 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine] Get default voice (New selected) : language(%s), type(%d)\n", *lang, *vctype);
1124 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
1125 return TTSD_ERROR_OPERATION_FAILED;
1128 __free_voice_list(voice_list);
1130 SLOG(LOG_ERROR, TAG_TTSD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
1131 return TTSD_ERROR_OPERATION_FAILED;
1139 * TTS Engine Interfaces for setting
1141 int ttsd_engine_setting_get_engine_list(GList** engine_list)
1143 if (false == g_agent_init) {
1144 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1145 return TTSD_ERROR_OPERATION_FAILED;
1148 if (NULL == engine_list) {
1149 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Input parameter is NULL" );
1150 return TTSD_ERROR_INVALID_PARAMETER;
1153 /* update engine list */
1154 if (0 != __internal_update_engine_list()) {
1155 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail __internal_update_engine_list() \n");
1156 return TTSD_ERROR_OPERATION_FAILED;
1160 ttsengine_info_s *data = NULL;
1162 iter = g_list_first(g_engine_list);
1164 SLOG(LOG_DEBUG, TAG_TTSD, "----- [Engine Agent] engine list -----");
1166 while (NULL != iter) {
1167 engine_s* temp_engine;
1169 temp_engine = (engine_s*)g_malloc0(sizeof(engine_s));
1173 temp_engine->engine_id = strdup(data->engine_uuid);
1174 temp_engine->engine_name = strdup(data->engine_name);
1175 temp_engine->ug_name = strdup(data->setting_ug_path);
1177 *engine_list = g_list_append(*engine_list, temp_engine);
1179 iter = g_list_next(iter);
1181 SLOG(LOG_DEBUG, TAG_TTSD, " -- engine id(%s) engine name(%s) ug name(%s) \n",
1182 temp_engine->engine_id, temp_engine->engine_name, temp_engine->ug_name);
1186 SLOG(LOG_DEBUG, TAG_TTSD, "--------------------------------------");
1191 int ttsd_engine_setting_get_engine(char** engine_id)
1193 if (false == g_agent_init) {
1194 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1195 return TTSD_ERROR_OPERATION_FAILED;
1198 if (false == g_cur_engine.is_loaded) {
1199 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1200 return TTSD_ERROR_ENGINE_NOT_FOUND;
1203 *engine_id = strdup(g_cur_engine.engine_uuid);
1208 int ttsd_engine_setting_set_engine(const char* engine_id)
1210 if (false == g_agent_init) {
1211 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1212 return TTSD_ERROR_OPERATION_FAILED;
1215 /* compare current engine and new engine.*/
1216 if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
1217 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] new engine(%s) is the same as current engine(%s) \n", engine_id, g_cur_engine.engine_uuid);
1221 char* tmp_uuid = NULL;
1222 tmp_uuid = strdup(g_cur_engine.engine_uuid);
1225 if (0 != ttsd_engine_agent_unload_current_engine()) {
1226 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent Error] fail to unload current engine \n");
1228 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] unload current engine \n");
1231 /* change current engine */
1232 if (0 != __internal_set_current_engine(engine_id)) {
1233 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail __internal_set_current_engine() \n");
1235 /* roll back to old current engine. */
1236 __internal_set_current_engine(tmp_uuid);
1237 ttsd_engine_agent_load_current_engine();
1239 if (tmp_uuid != NULL)
1242 return TTSD_ERROR_OPERATION_FAILED;
1246 if (0 != ttsd_engine_agent_load_current_engine()) {
1247 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent Error] fail to load new engine \n");
1249 if( tmp_uuid != NULL )
1252 return TTSD_ERROR_OPERATION_FAILED;
1254 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] load new engine \n");
1257 /* save engine id to config */
1258 if (0 != ttsd_config_set_default_engine(engine_id)) {
1259 SLOG(LOG_WARN, TAG_TTSD, "[Engine Agent WARNING] Fail to save engine id to config \n");
1262 if (tmp_uuid != NULL)
1268 int ttsd_engine_setting_get_voice_list(char** engine_id, GList** voice_list)
1270 if (false == g_agent_init) {
1271 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1272 return TTSD_ERROR_OPERATION_FAILED;
1275 if (false == g_cur_engine.is_loaded) {
1276 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1277 return TTSD_ERROR_OPERATION_FAILED;
1282 /* get language list from engine*/
1283 ret = ttsd_engine_get_voice_list(voice_list);
1285 SLOG(LOG_ERROR, TAG_TTSD, "[Server Error] fail ttsd_engine_get_voice_list() \n");
1289 *engine_id = strdup(g_cur_engine.engine_uuid);
1294 int ttsd_engine_setting_get_default_voice(char** language, ttsp_voice_type_e* vctype)
1296 if (false == g_agent_init) {
1297 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1298 return TTSD_ERROR_OPERATION_FAILED;
1301 if (false == g_cur_engine.is_loaded) {
1302 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1303 return TTSD_ERROR_OPERATION_FAILED;
1306 /* get current language from engine*/
1309 ttsp_voice_type_e temp_int;
1311 ret = ttsd_engine_get_default_voice(&temp_lang, &temp_int);
1313 SLOG(LOG_ERROR, TAG_TTSD, "[Server Error] fail ttsd_engine_get_default_voice() \n");
1317 if (NULL != temp_lang) {
1318 *language = strdup(temp_lang);
1322 SLOG(LOG_ERROR, TAG_TTSD, "[Server Error] fail to get default language \n");
1323 return TTSD_ERROR_OPERATION_FAILED;
1329 int ttsd_engine_setting_set_default_voice(const char* language, ttsp_voice_type_e vctype)
1331 if (false == g_agent_init) {
1332 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1333 return TTSD_ERROR_OPERATION_FAILED;
1336 if (false == g_cur_engine.is_loaded) {
1337 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1338 return TTSD_ERROR_OPERATION_FAILED;
1341 if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
1342 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] The function of engine is NULL!!");
1343 return TTSD_ERROR_OPERATION_FAILED;
1347 if(false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
1348 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Voice is NOT valid !!");
1349 return TTSD_ERROR_INVALID_VOICE;
1352 if (NULL != g_cur_engine.default_lang)
1353 free(g_cur_engine.default_lang);
1355 g_cur_engine.default_lang = strdup(language);
1356 g_cur_engine.default_vctype = vctype;
1358 ret = ttsd_config_set_default_voice(language, (int)vctype);
1360 SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d) \n",
1361 g_cur_engine.default_lang, g_cur_engine.default_vctype);
1363 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to write default voice to config (%d) \n", ret);
1369 int ttsd_engine_setting_get_default_speed(ttsp_speed_e* speed)
1371 if (false == g_agent_init) {
1372 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1373 return TTSD_ERROR_OPERATION_FAILED;
1376 if (false == g_cur_engine.is_loaded) {
1377 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1378 return TTSD_ERROR_OPERATION_FAILED;
1381 /* get current language */
1382 *speed = g_cur_engine.default_speed;
1387 int ttsd_engine_setting_set_default_speed(const ttsp_speed_e speed)
1389 if (false == g_agent_init) {
1390 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1391 return TTSD_ERROR_OPERATION_FAILED;
1394 if (false == g_cur_engine.is_loaded) {
1395 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1396 return TTSD_ERROR_OPERATION_FAILED;
1399 g_cur_engine.default_speed = speed;
1401 if (0 != ttsd_config_set_default_speed(speed)) {
1402 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to set default speed to config");
1408 bool __engine_setting_cb(const char* key, const char* value, void* user_data)
1410 GList** engine_setting_list = (GList**)user_data;
1412 if (NULL == engine_setting_list || NULL == key || NULL == value) {
1413 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Input parameter is NULL in engine setting callback!!!!");
1417 engine_setting_s* temp = g_malloc0(sizeof(engine_setting_s));
1418 temp->key = g_strdup(key);
1419 temp->value = g_strdup(value);
1421 *engine_setting_list = g_list_append(*engine_setting_list, temp);
1427 int ttsd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list)
1429 if (false == g_agent_init) {
1430 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized" );
1431 return TTSD_ERROR_OPERATION_FAILED;
1434 if (false == g_cur_engine.is_loaded) {
1435 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine");
1436 return TTSD_ERROR_OPERATION_FAILED;
1439 if (NULL == setting_list) {
1440 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Input parameter is NULL");
1441 return TTSD_ERROR_INVALID_PARAMETER;
1444 if (NULL == g_cur_engine.pefuncs->foreach_engine_setting) {
1445 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] foreach_engine_setting() of engine is NULL!!");
1446 return TTSD_ERROR_OPERATION_FAILED;
1449 /* get setting info and move setting info to input parameter */
1452 result = g_cur_engine.pefuncs->foreach_engine_setting(__engine_setting_cb, setting_list);
1454 if (0 == result && 0 < g_list_length(*setting_list)) {
1455 *engine_id = strdup(g_cur_engine.engine_uuid);
1457 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to get setting info : result(%d)\n", result);
1458 result = TTSD_ERROR_OPERATION_FAILED;
1464 int ttsd_engine_setting_set_engine_setting(const char* key, const char* value)
1466 if (false == g_agent_init) {
1467 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not Initialized \n" );
1468 return TTSD_ERROR_OPERATION_FAILED;
1471 if (false == g_cur_engine.is_loaded) {
1472 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not loaded engine \n");
1473 return TTSD_ERROR_OPERATION_FAILED;
1476 if (NULL == g_cur_engine.pefuncs->set_engine_setting) {
1477 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] set_setting_info of engine is NULL!! \n");
1478 return TTSD_ERROR_OPERATION_FAILED;
1481 /* get setting info and move setting info to input parameter */
1483 ret = g_cur_engine.pefuncs->set_engine_setting(key, value);
1486 SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] fail to set engine setting : result(%d)\n", ret);
1487 return TTSD_ERROR_OPERATION_FAILED;
1493 void __free_voice_list(GList* voice_list)
1496 voice_s* data = NULL;
1498 /* if list have item */
1499 if (g_list_length(voice_list) > 0) {
1500 /* Get a first item */
1501 iter = g_list_first(voice_list);
1503 while (NULL != iter) {
1507 if (NULL != data->language)
1508 g_free(data->language);
1513 voice_list = g_list_remove_link(voice_list, iter);
1515 iter = g_list_first(voice_list);
1521 * TTS Engine Callback Functions ` *
1523 bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
1525 g_result_cb(event, data, data_size, user_data);
1530 /* function for debugging */
1531 int ttsd_print_enginelist()
1534 ttsengine_info_s *data = NULL;
1536 if (g_list_length(g_engine_list) > 0) {
1537 iter = g_list_first(g_engine_list);
1539 SLOG(LOG_DEBUG, TAG_TTSD, "----- engine list -----");
1542 while (NULL != iter) {
1545 SLOG(LOG_DEBUG, TAG_TTSD, "[%dth]\n", i);
1546 SLOG(LOG_DEBUG, TAG_TTSD, "engine uuid : %s\n", data->engine_uuid);
1547 SLOG(LOG_DEBUG, TAG_TTSD, "engine name : %s\n", data->engine_name);
1548 SLOG(LOG_DEBUG, TAG_TTSD, "engine path : %s\n", data->engine_path);
1549 SLOG(LOG_DEBUG, TAG_TTSD, "setting ug path : %s\n", data->setting_ug_path);
1551 iter = g_list_next(iter);
1554 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------");
1555 SLOG(LOG_DEBUG, TAG_TTSD, " ");
1557 SLOG(LOG_DEBUG, TAG_TTSD, "----- engine list -----");
1558 SLOG(LOG_DEBUG, TAG_TTSD, "No Engine in directory");
1559 SLOG(LOG_DEBUG, TAG_TTSD, "-----------------------");