2 * Copyright (c) 2012, 2013 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, get_tag(), "[Engine Agent ERROR] invalid parameter");
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, get_tag(), "[Server WARNING] There is No default voice in config");
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, get_tag(), "[Server WARNING] There is No default speed in config");
132 ttsd_config_set_default_speed((int)TTSP_SPEED_NORMAL);
133 g_cur_engine.default_speed = TTSP_SPEED_NORMAL;
136 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Initialize Engine Agent");
141 int ttsd_engine_agent_release()
143 if (false == g_agent_init) {
144 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized");
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);
158 while (NULL != iter) {
159 /* Get data from item */
161 iter = g_list_remove(iter, data);
165 /* release current engine data */
166 if (g_cur_engine.pefuncs != NULL)
167 g_free(g_cur_engine.pefuncs);
169 if (g_cur_engine.pdfuncs != NULL)
170 g_free(g_cur_engine.pdfuncs);
173 g_agent_init = false;
175 if (g_cur_engine.default_lang != NULL)
176 g_free(g_cur_engine.default_lang);
179 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Release Engine Agent");
184 int ttsd_engine_agent_initialize_current_engine()
186 if (false == g_agent_init) {
187 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
188 return TTSD_ERROR_OPERATION_FAILED;
191 /* update engine list */
192 if (0 != __internal_update_engine_list()) {
193 SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] No engine error");
194 return TTSD_ERROR_OPERATION_FAILED;
197 /* 2. get current engine from config */
198 char* cur_engine_uuid = NULL;
199 bool is_get_engineid_from_config = false;
201 if (0 != ttsd_config_get_default_engine(&cur_engine_uuid)) {
202 /*not set current engine */
203 /*set system default engine*/
205 ttsengine_info_s *data = NULL;
207 if (g_list_length(g_engine_list) > 0) {
208 iter = g_list_first(g_engine_list);
209 char* default_engine = "27F277E9-BBC4-4dca-B553-D9884A3CDAA0";
211 while (NULL != iter) {
214 if (0 == strncmp(data->engine_uuid, default_engine, strlen(default_engine))) {
215 /* current data is default engine */
219 iter = g_list_next(iter);
222 SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to set a engine of engine list");
223 return TTSD_ERROR_OPERATION_FAILED;
226 if (NULL != data->engine_uuid) {
227 cur_engine_uuid = strdup(data->engine_uuid);
229 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Data of current engine is corrupt");
230 return TTSD_ERROR_OPERATION_FAILED;
233 is_get_engineid_from_config = false;
235 is_get_engineid_from_config = true;
238 /* check whether cur engine uuid is valid or not. */
239 if (0 != __internal_check_engine_id(cur_engine_uuid)) {
240 SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] It is not valid engine id from config");
244 if (g_list_length(g_engine_list) > 0)
245 iter = g_list_first(g_engine_list);
247 SLOG(LOG_WARN, get_tag(), "[Engine Agent ERROR] NO TTS Engine !!");
248 return TTSD_ERROR_OPERATION_FAILED;
251 if (cur_engine_uuid != NULL)
252 g_free(cur_engine_uuid);
254 ttsengine_info_s *data = NULL;
257 cur_engine_uuid = g_strdup(data->engine_uuid);
259 is_get_engineid_from_config = false;
262 if (NULL != cur_engine_uuid)
263 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
265 return TTSD_ERROR_OPERATION_FAILED;
267 /* set current engine */
268 if (0 != __internal_set_current_engine(cur_engine_uuid)) {
269 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set current engine ");
270 return TTSD_ERROR_OPERATION_FAILED;
273 if (false == is_get_engineid_from_config) {
274 if (0 != ttsd_config_set_default_engine(cur_engine_uuid))
275 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set id to config");
278 if (NULL != cur_engine_uuid)
279 g_free(cur_engine_uuid);
281 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set current engine");
286 int __internal_check_engine_id(const char* engine_uuid)
289 ttsengine_s *data = NULL;
291 if (g_list_length(g_engine_list) > 0) {
292 iter = g_list_first(g_engine_list);
294 while (NULL != iter) {
297 if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid)))
300 iter = g_list_next(iter);
307 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
308 bool use_network, void* user_data)
310 ttsengine_info_s* temp = (ttsengine_info_s*)user_data;
312 temp->engine_uuid = g_strdup(engine_uuid);
313 temp->engine_name = g_strdup(engine_name);
314 temp->setting_ug_path = g_strdup(setting_ug_name);
315 temp->use_network = use_network;
318 int __internal_get_engine_info(const char* filepath, ttsengine_info_s** info)
323 handle = dlopen (filepath, RTLD_LAZY );
326 SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine : %s", filepath);
327 return TTSD_ERROR_OPERATION_FAILED;
330 /* link engine to daemon */
331 dlsym(handle, "ttsp_load_engine");
332 if ((error = dlerror()) != NULL) {
333 SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine. Fail to open ttsp_load_engine : %s", filepath);
335 return TTSD_ERROR_OPERATION_FAILED;
338 dlsym(handle, "ttsp_unload_engine");
339 if ((error = dlerror()) != NULL) {
340 SLOG(LOG_WARN, get_tag(), "[Engine Agent] Invalid engine. Fail to open ttsp_unload_engine : %s", filepath);
342 return TTSD_ERROR_OPERATION_FAILED;
345 int (*get_engine_info)(ttsp_engine_info_cb callback, void* user_data);
347 get_engine_info = (int (*)(ttsp_engine_info_cb, void*))dlsym(handle, "ttsp_get_engine_info");
348 if (NULL != (error = dlerror()) || NULL == get_engine_info) {
349 SLOG(LOG_WARN, get_tag(), "[Engine Agent] ttsp_get_engine_info() link error");
351 return TTSD_ERROR_OPERATION_FAILED;
354 ttsengine_info_s* temp;
355 temp = (ttsengine_info_s*)g_malloc0(sizeof(ttsengine_info_s));
357 /* get engine info */
358 if (0 != get_engine_info(&__engine_info_cb, (void*)temp)) {
359 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get engine info");
362 return TTSD_ERROR_OPERATION_FAILED;
368 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
369 if (true == temp->use_network) {
371 SLOG(LOG_ERROR, get_tag(), "[Engine Agent WARNING] %s is invalid because of network based engine.", temp->engine_name);
372 return TTSD_ERROR_OPERATION_FAILED;
376 temp->engine_path = g_strdup(filepath);
378 SLOG(LOG_DEBUG, get_tag(), "----- Valid engine");
379 SLOG(LOG_DEBUG, get_tag(), "Engine uuid : %s", temp->engine_uuid);
380 SLOG(LOG_DEBUG, get_tag(), "Engine name : %s", temp->engine_name);
381 SLOG(LOG_DEBUG, get_tag(), "Setting ug path : %s", temp->setting_ug_path);
382 SLOG(LOG_DEBUG, get_tag(), "Engine path : %s", temp->engine_path);
383 SLOG(LOG_DEBUG, get_tag(), "Use network : %s", temp->use_network ? "true":"false");
384 SLOG(LOG_DEBUG, get_tag(), "-----");
385 SLOG(LOG_DEBUG, get_tag(), " ");
392 int __internal_update_engine_list()
394 /* relsease engine list */
396 ttsengine_info_s *data = NULL;
398 if (g_list_length(g_engine_list) > 0) {
399 iter = g_list_first(g_engine_list);
401 while (NULL != iter) {
407 g_engine_list = g_list_remove_link(g_engine_list, iter);
408 iter = g_list_first(g_engine_list);
412 /* get file name from engine directory and get engine information from each filename */
415 dp = opendir(ENGINE_DIRECTORY_DEFAULT);
418 while ((dirp = readdir(dp)) != NULL) {
419 ttsengine_info_s* info;
420 char* filepath = NULL;
423 file_size = strlen(ENGINE_DIRECTORY_DEFAULT) + strlen(dirp->d_name) + 5;
424 filepath = (char*)g_malloc0( sizeof(char) * file_size);
426 if (NULL != filepath) {
427 strncpy(filepath, ENGINE_DIRECTORY_DEFAULT, strlen(ENGINE_DIRECTORY_DEFAULT) );
428 strncat(filepath, "/", strlen("/") );
429 strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
431 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
435 /* get its info and update engine list */
436 if (0 == __internal_get_engine_info(filepath, &info)) {
437 /* add engine info to g_engine_list */
438 g_engine_list = g_list_append(g_engine_list, info);
441 if (NULL != filepath)
448 dp = opendir(ENGINE_DIRECTORY_DOWNLOAD);
451 while ((dirp = readdir(dp)) != NULL) {
452 ttsengine_info_s* info;
453 char* filepath = NULL;
456 file_size = strlen(ENGINE_DIRECTORY_DOWNLOAD) + strlen(dirp->d_name) + 5;
457 filepath = (char*)g_malloc0( sizeof(char) * file_size);
459 if (NULL != filepath) {
460 strcpy(filepath, ENGINE_DIRECTORY_DOWNLOAD);
461 strcat(filepath, "/");
462 strcat(filepath, dirp->d_name);
464 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
468 /* get its info and update engine list */
469 if (0 == __internal_get_engine_info(filepath, &info)) {
470 /* add engine info to g_engine_list */
471 g_engine_list = g_list_append(g_engine_list, info);
474 if (NULL != filepath)
481 if (g_list_length(g_engine_list) <= 0) {
482 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No Engine");
483 return TTSD_ERROR_OPERATION_FAILED;
486 #ifdef ENGINE_AGENT_DEBUG
487 ttsd_print_enginelist();
493 int __internal_set_current_engine(const char* engine_uuid)
495 /* check whether engine id is valid or not. */
497 ttsengine_info_s *data = NULL;
500 if (g_list_length(g_engine_list) > 0) {
501 iter = g_list_first(g_engine_list);
503 while (NULL != iter) {
506 if (0 == strncmp(data->engine_uuid, engine_uuid, strlen(engine_uuid))) {
512 iter = g_list_next(iter);
516 /* If current engine does not exist, return error */
518 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] __internal_set_current_engine : Cannot find engine id");
519 return TTSD_ERROR_OPERATION_FAILED;
521 if (g_cur_engine.engine_uuid != NULL) {
522 /*compare current engine uuid */
523 if (0 == strncmp(g_cur_engine.engine_uuid, data->engine_uuid, strlen(engine_uuid))) {
524 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] tts engine has already been set");
530 /* set data from g_engine_list */
531 if (g_cur_engine.engine_uuid != NULL) g_free(g_cur_engine.engine_uuid);
532 if (g_cur_engine.engine_name != NULL) g_free(g_cur_engine.engine_name);
533 if (g_cur_engine.engine_path != NULL) g_free(g_cur_engine.engine_path);
535 if (NULL == data->engine_uuid || NULL == data->engine_name || NULL == data->engine_path) {
536 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] __internal_set_current_engine : Engine data is NULL");
537 return TTSD_ERROR_OPERATION_FAILED;
540 g_cur_engine.engine_uuid = g_strdup(data->engine_uuid);
541 g_cur_engine.engine_name = g_strdup(data->engine_name);
542 g_cur_engine.engine_path = g_strdup(data->engine_path);
544 g_cur_engine.handle = NULL;
545 g_cur_engine.is_loaded = false;
546 g_cur_engine.is_set = true;
547 g_cur_engine.need_network = data->use_network;
549 SLOG(LOG_DEBUG, get_tag(), "-----");
550 SLOG(LOG_DEBUG, get_tag(), "Current engine uuid : %s", g_cur_engine.engine_uuid);
551 SLOG(LOG_DEBUG, get_tag(), "Current engine name : %s", g_cur_engine.engine_name);
552 SLOG(LOG_DEBUG, get_tag(), "Current engine path : %s", g_cur_engine.engine_path);
553 SLOG(LOG_DEBUG, get_tag(), "-----");
558 int ttsd_engine_agent_load_current_engine()
560 if (false == g_agent_init) {
561 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
562 return TTSD_ERROR_OPERATION_FAILED;
565 if (false == g_cur_engine.is_set) {
566 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : No Current Engine ");
567 return TTSD_ERROR_OPERATION_FAILED;
570 /* check whether current engine is loaded or not */
571 if (true == g_cur_engine.is_loaded ) {
572 SLOG(LOG_ERROR, get_tag(), "[Engine Agent] ttsd_engine_agent_load_current_engine : Engine has already been loaded " );
576 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] current engine path : %s", g_cur_engine.engine_path);
580 g_cur_engine.handle = dlopen(g_cur_engine.engine_path, RTLD_LAZY); /* RTLD_LAZY RTLD_NOW*/
582 if (NULL != (error = dlerror()) || NULL == g_cur_engine.handle) {
583 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get current engine handle : dlopen error ($s)", error);
587 g_cur_engine.ttsp_unload_engine = (int (*)())dlsym(g_cur_engine.handle, "ttsp_unload_engine");
588 if (NULL != (error = dlerror()) || NULL == g_cur_engine.ttsp_unload_engine) {
589 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to link daemon to ttsp_unload_engine() of current engine : (%s)", error);
593 g_cur_engine.ttsp_load_engine = (int (*)(const ttspd_funcs_s* , ttspe_funcs_s*) )dlsym(g_cur_engine.handle, "ttsp_load_engine");
594 if (NULL != (error = dlerror()) || NULL == g_cur_engine.ttsp_load_engine) {
595 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to link daemon to ttsp_load_engine() of current engine : %s", error);
600 g_cur_engine.pdfuncs->version = 1;
601 g_cur_engine.pdfuncs->size = sizeof(ttspd_funcs_s);
604 ret = g_cur_engine.ttsp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs);
606 printf("Fail load '%s' engine", g_cur_engine.engine_path);
607 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to load engine : result(%d)");
608 return TTSD_ERROR_OPERATION_FAILED;
611 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] engine info : version(%d), size(%d)",g_cur_engine.pefuncs->version, g_cur_engine.pefuncs->size );
613 /* engine error check */
614 if (g_cur_engine.pefuncs->size != sizeof(ttspe_funcs_s)) {
615 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ttsd_engine_agent_load_current_engine : current engine is not valid");
616 return TTSD_ERROR_OPERATION_FAILED;
619 /* initalize engine */
620 if (NULL == g_cur_engine.pefuncs->initialize) {
621 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] init function of engine is NULL!!");
622 return TTSD_ERROR_OPERATION_FAILED;
625 ret = g_cur_engine.pefuncs->initialize(__result_cb);
627 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to initialize current engine : result(%d)", ret);
628 return TTSD_ERROR_OPERATION_FAILED;
631 /* select default voice */
632 bool set_voice = false;
633 if (NULL != g_cur_engine.default_lang) {
634 if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
635 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] is_valid_voice() of engine is NULL!!");
636 return TTSD_ERROR_OPERATION_FAILED;
639 if (true == g_cur_engine.pefuncs->is_valid_voice(g_cur_engine.default_lang, g_cur_engine.default_vctype)) {
641 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s), type(%d)",
642 g_cur_engine.default_lang, g_cur_engine.default_vctype);
644 SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail set origin default voice : lang(%s), type(%d)",
645 g_cur_engine.default_lang, g_cur_engine.default_vctype);
649 if (false == set_voice) {
650 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
651 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
652 return TTSD_ERROR_OPERATION_FAILED;
655 /* get language list */
657 GList* voice_list = NULL;
659 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
661 if (0 == ret && 0 < g_list_length(voice_list)) {
665 iter = g_list_first(voice_list);
668 while (NULL != iter) {
672 if (0 == strcmp("en_US", voice->language))
676 iter = g_list_next(iter);
679 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to find voice in list");
680 return TTSD_ERROR_OPERATION_FAILED;
683 /* Set selected language and type */
684 if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
685 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail voice is NOT valid");
686 return TTSD_ERROR_OPERATION_FAILED;
689 ttsd_config_set_default_voice(voice->language, (int)voice->type);
691 g_cur_engine.default_lang = g_strdup(voice->language);
692 g_cur_engine.default_vctype = voice->type;
694 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Select default voice : lang(%s), type(%d)",
695 voice->language, voice->type);
697 __free_voice_list(voice_list);
699 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)", ret);
700 return TTSD_ERROR_OPERATION_FAILED;
704 g_cur_engine.is_loaded = true;
709 int ttsd_engine_agent_unload_current_engine()
711 if (false == g_agent_init) {
712 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
713 return TTSD_ERROR_OPERATION_FAILED;
716 if (false == g_cur_engine.is_set) {
717 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] No Current Engine ");
718 return TTSD_ERROR_OPERATION_FAILED;
721 if (false == g_cur_engine.is_loaded) {
722 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Engine has already been unloaded " );
726 /* shutdown engine */
727 if (NULL == g_cur_engine.pefuncs->deinitialize) {
728 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The deinitialize() of engine is NULL!!");
731 ret = g_cur_engine.pefuncs->deinitialize();
733 SLOG(LOG_ERROR, get_tag(), "[Engine Agent] Fail deinitialize() : result(%d)", ret);
738 g_cur_engine.ttsp_unload_engine();
740 dlclose(g_cur_engine.handle);
742 /* reset current engine data */
743 g_cur_engine.handle = NULL;
744 g_cur_engine.is_loaded = false;
749 bool ttsd_engine_agent_need_network()
751 if (false == g_agent_init) {
752 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
753 return TTSD_ERROR_OPERATION_FAILED;
756 if (false == g_cur_engine.is_loaded) {
757 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
758 return TTSD_ERROR_OPERATION_FAILED;
761 return g_cur_engine.need_network;
764 bool ttsd_engine_select_valid_voice(const char* lang, int type, char** out_lang, ttsp_voice_type_e* out_type)
766 if (NULL == lang || NULL == out_lang || NULL == out_type) {
770 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Select voice : input lang(%s) , input type(%d), default lang(%s), default type(%d)",
771 lang, type, g_cur_engine.default_lang, g_cur_engine.default_vctype);
774 /* case 1 : Both are default */
775 if (0 == strncmp(lang, "default", strlen("default")) && 0 == type) {
776 *out_lang = strdup(g_cur_engine.default_lang);
777 *out_type = g_cur_engine.default_vctype;
782 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
783 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] foreach_voices of engine is NULL!!");
784 return TTSD_ERROR_OPERATION_FAILED;
787 GList* voice_list = NULL;
790 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
791 if (0 != ret || 0 >= g_list_length(voice_list)) {
792 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get voice list : result(%d)", ret);
802 /* lang and type are not default type */
803 if (0 != strncmp(lang, "default", strlen("default")) && 0 != type) {
804 iter = g_list_first(voice_list);
806 while (NULL != iter) {
807 /* Get handle data from list */
810 if (0 == strncmp(voice->language, lang, strlen(lang)) && voice->type == type) {
811 *out_lang = strdup(voice->language);
812 *out_type = voice->type;
817 iter = g_list_next(iter);
820 } else if (0 != strncmp(lang, "default", strlen("default")) && 0 == type) {
821 /* Only type is default */
822 if (0 == strncmp(lang, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang))) {
823 *out_lang = strdup(g_cur_engine.default_lang);
824 *out_type = g_cur_engine.default_vctype;
827 voice_s* voice_selected = NULL;
828 iter = g_list_first(voice_list);
829 while (NULL != iter) {
830 /* Get handle data from list */
833 if (0 == strncmp(voice->language, lang, strlen(lang))) {
834 voice_selected = voice;
835 if (voice->type == g_cur_engine.default_vctype) {
836 voice_selected = voice;
840 iter = g_list_next(iter);
843 if (NULL != voice_selected) {
844 *out_lang = strdup(voice_selected->language);
845 *out_type = voice_selected->type;
849 } else if (0 == strncmp(lang, "default", strlen("default")) && 0 != type) {
850 /* Only lang is default */
851 if (type == g_cur_engine.default_vctype) {
852 *out_lang = strdup(g_cur_engine.default_lang);
853 *out_type = g_cur_engine.default_vctype;
856 voice_s* voice_selected = NULL;
857 iter = g_list_first(voice_list);
858 while (NULL != iter) {
859 /* Get handle data from list */
862 if (0 == strncmp(voice->language, g_cur_engine.default_lang, strlen(g_cur_engine.default_lang)) ) {
863 voice_selected = voice;
864 if (voice->type == type) {
865 voice_selected = voice;
869 iter = g_list_next(iter);
872 if (NULL != voice_selected) {
873 *out_lang = strdup(voice->language);
874 *out_type = voice_selected->type;
880 if (true == result) {
881 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Selected voice : lang(%s), type(%d)", *out_lang, *out_type);
884 __free_voice_list(voice_list);
889 bool ttsd_engine_agent_is_same_engine(const char* engine_id)
891 if (false == g_agent_init) {
892 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
896 if (false == g_cur_engine.is_loaded) {
897 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
901 /* compare current engine and engine id.*/
902 if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
909 int ttsd_engine_agent_set_default_voice(const char* language, ttsp_voice_type_e vctype)
911 if (false == g_agent_init) {
912 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
913 return TTSD_ERROR_OPERATION_FAILED;
916 if (false == g_cur_engine.is_loaded) {
917 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
918 return TTSD_ERROR_OPERATION_FAILED;
921 if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
922 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
923 return TTSD_ERROR_OPERATION_FAILED;
927 if(false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
928 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice is NOT valid !!");
929 return TTSD_ERROR_INVALID_VOICE;
932 if (NULL != g_cur_engine.default_lang)
933 free(g_cur_engine.default_lang);
935 g_cur_engine.default_lang = strdup(language);
936 g_cur_engine.default_vctype = vctype;
938 ret = ttsd_config_set_default_voice(language, (int)vctype);
940 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d)",
941 g_cur_engine.default_lang, g_cur_engine.default_vctype);
943 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret);
944 return TTSD_ERROR_OPERATION_FAILED;
950 /******************************************************************************************
951 * TTS Engine Interfaces for client
952 *******************************************************************************************/
954 int ttsd_engine_start_synthesis(const char* lang, const ttsp_voice_type_e vctype, const char* text, const int speed, void* user_param)
956 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] start ttsd_engine_start_synthesis()");
958 if (false == g_agent_init) {
959 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
960 return TTSD_ERROR_OPERATION_FAILED;
963 if (false == g_cur_engine.is_loaded) {
964 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
965 return TTSD_ERROR_OPERATION_FAILED;
968 /* select voice for default */
969 char* temp_lang = NULL;
970 ttsp_voice_type_e temp_type;
971 if (true != ttsd_engine_select_valid_voice(lang, vctype, &temp_lang, &temp_type)) {
972 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to select default voice");
973 return TTSD_ERROR_INVALID_VOICE;
975 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s)",
976 temp_lang, temp_type, speed, text);
979 if (NULL == g_cur_engine.pefuncs->start_synth) {
980 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] start_synth() of engine is NULL!!");
981 return TTSD_ERROR_OPERATION_FAILED;
984 ttsp_speed_e temp_speed;
987 temp_speed = g_cur_engine.default_speed;
992 /* synthesize text */
994 ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, user_param);
996 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************", ret);
997 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] * synthesize error : result(%6d) *", ret);
998 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************", ret);
999 return TTSD_ERROR_OPERATION_FAILED;
1002 if (NULL == temp_lang)
1009 int ttsd_engine_cancel_synthesis()
1011 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] start ttsd_engine_cancel_synthesis()");
1013 if (false == g_agent_init) {
1014 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1015 return TTSD_ERROR_OPERATION_FAILED;
1018 if (false == g_cur_engine.is_loaded) {
1019 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1020 return TTSD_ERROR_OPERATION_FAILED;
1023 if (NULL == g_cur_engine.pefuncs->cancel_synth) {
1024 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] cancel_synth() of engine is NULL!!");
1025 return TTSD_ERROR_OPERATION_FAILED;
1028 /* stop synthesis */
1030 ret = g_cur_engine.pefuncs->cancel_synth();
1032 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail cancel synthesis : result(%d)", ret);
1033 return TTSD_ERROR_OPERATION_FAILED;
1039 int ttsd_engine_get_audio_format( ttsp_audio_type_e* type, int* rate, int* channels)
1041 if (false == g_agent_init) {
1042 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1043 return TTSD_ERROR_OPERATION_FAILED;
1046 if (false == g_cur_engine.is_loaded) {
1047 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1048 return TTSD_ERROR_OPERATION_FAILED;
1051 if (NULL == g_cur_engine.pefuncs->get_audio_format) {
1052 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_audio_format() of engine is NULL!!");
1053 return TTSD_ERROR_OPERATION_FAILED;
1057 ret = g_cur_engine.pefuncs->get_audio_format(type, rate, channels);
1059 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get audio format : result(%d)", ret);
1060 return TTSD_ERROR_OPERATION_FAILED;
1062 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] get audio format : type(%d), rate(%d), channel(%d)", *type, *rate, *channels);
1067 bool __supported_voice_cb(const char* language, ttsp_voice_type_e type, void* user_data)
1069 GList** voice_list = (GList**)user_data;
1071 if (NULL == language || NULL == voice_list) {
1072 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in voice list callback!!!!");
1076 SLOG(LOG_DEBUG, get_tag(), "-- Language(%s), Type(%d)", language, type);
1078 voice_s* voice = g_malloc0(sizeof(voice_s));
1079 voice->language = strdup(language);
1082 *voice_list = g_list_append(*voice_list, voice);
1087 int ttsd_engine_get_voice_list(GList** voice_list)
1089 if (false == g_agent_init) {
1090 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1091 return TTSD_ERROR_OPERATION_FAILED;
1094 if (false == g_cur_engine.is_loaded) {
1095 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1096 return TTSD_ERROR_OPERATION_FAILED;
1099 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
1100 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
1101 return TTSD_ERROR_OPERATION_FAILED;
1105 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, (void*)voice_list);
1107 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to get voice list : result(%d)", ret);
1108 return TTSD_ERROR_OPERATION_FAILED;
1114 int ttsd_engine_get_default_voice( char** lang, ttsp_voice_type_e* vctype )
1116 if (false == g_agent_init) {
1117 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1118 return TTSD_ERROR_OPERATION_FAILED;
1121 if (false == g_cur_engine.is_loaded) {
1122 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1123 return TTSD_ERROR_OPERATION_FAILED;
1126 if (NULL == lang || NULL == vctype) {
1127 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] BAD Parameter");
1128 return TTSD_ERROR_INVALID_PARAMETER;
1131 if (NULL != g_cur_engine.default_lang) {
1132 *lang = g_strdup(g_cur_engine.default_lang);
1133 *vctype = g_cur_engine.default_vctype;
1135 SLOG(LOG_DEBUG, get_tag(), "[Engine] Get default voice : language(%s), type(%d)", *lang, *vctype);
1137 if (NULL == g_cur_engine.pefuncs->foreach_voices) {
1138 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] get_voice_list of engine is NULL!!");
1139 return TTSD_ERROR_OPERATION_FAILED;
1142 /* get language list */
1144 GList* voice_list = NULL;
1146 ret = g_cur_engine.pefuncs->foreach_voices(__supported_voice_cb, &voice_list);
1148 if (0 == ret && 0 < g_list_length(voice_list)) {
1152 iter = g_list_first(voice_list);
1157 if (true != g_cur_engine.pefuncs->is_valid_voice(voice->language, voice->type)) {
1158 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail voice is NOT valid ");
1159 return TTSD_ERROR_OPERATION_FAILED;
1162 ttsd_config_set_default_voice(voice->language, (int)voice->type);
1164 if (NULL != g_cur_engine.default_lang)
1165 g_free(g_cur_engine.default_lang);
1167 g_cur_engine.default_lang = g_strdup(voice->language);
1168 g_cur_engine.default_vctype = voice->type;
1170 *lang = g_strdup(g_cur_engine.default_lang);
1171 *vctype = g_cur_engine.default_vctype = voice->type;
1173 SLOG(LOG_DEBUG, get_tag(), "[Engine] Get default voice (New selected) : language(%s), type(%d)", *lang, *vctype);
1175 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)", ret);
1176 return TTSD_ERROR_OPERATION_FAILED;
1179 __free_voice_list(voice_list);
1181 SLOG(LOG_ERROR, get_tag(), "[Engine ERROR] Fail to get language list : result(%d)", ret);
1182 return TTSD_ERROR_OPERATION_FAILED;
1190 * TTS Engine Interfaces for setting
1192 int ttsd_engine_setting_get_engine_list(GList** engine_list)
1194 if (false == g_agent_init) {
1195 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1196 return TTSD_ERROR_OPERATION_FAILED;
1199 if (NULL == engine_list) {
1200 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL" );
1201 return TTSD_ERROR_INVALID_PARAMETER;
1204 /* update engine list */
1205 if (0 != __internal_update_engine_list()) {
1206 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail __internal_update_engine_list()");
1207 return TTSD_ERROR_OPERATION_FAILED;
1211 ttsengine_info_s *data = NULL;
1213 iter = g_list_first(g_engine_list);
1215 SLOG(LOG_DEBUG, get_tag(), "----- [Engine Agent] engine list -----");
1217 while (NULL != iter) {
1218 engine_s* temp_engine;
1220 temp_engine = (engine_s*)g_malloc0(sizeof(engine_s));
1224 temp_engine->engine_id = strdup(data->engine_uuid);
1225 temp_engine->engine_name = strdup(data->engine_name);
1226 temp_engine->ug_name = strdup(data->setting_ug_path);
1228 *engine_list = g_list_append(*engine_list, temp_engine);
1230 iter = g_list_next(iter);
1232 SLOG(LOG_DEBUG, get_tag(), " -- engine id(%s) engine name(%s) ug name(%s)",
1233 temp_engine->engine_id, temp_engine->engine_name, temp_engine->ug_name);
1237 SLOG(LOG_DEBUG, get_tag(), "--------------------------------------");
1242 int ttsd_engine_setting_get_engine(char** engine_id)
1244 if (false == g_agent_init) {
1245 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1246 return TTSD_ERROR_OPERATION_FAILED;
1249 if (false == g_cur_engine.is_loaded) {
1250 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1251 return TTSD_ERROR_ENGINE_NOT_FOUND;
1254 *engine_id = strdup(g_cur_engine.engine_uuid);
1259 int ttsd_engine_setting_set_engine(const char* engine_id)
1261 if (false == g_agent_init) {
1262 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1263 return TTSD_ERROR_OPERATION_FAILED;
1266 /* compare current engine and new engine.*/
1267 if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(engine_id))) {
1268 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] new engine(%s) is the same as current engine(%s)", engine_id, g_cur_engine.engine_uuid);
1272 char* tmp_uuid = NULL;
1273 tmp_uuid = strdup(g_cur_engine.engine_uuid);
1276 if (0 != ttsd_engine_agent_unload_current_engine()) {
1277 SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] fail to unload current engine");
1279 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] unload current engine");
1282 /* change current engine */
1283 if (0 != __internal_set_current_engine(engine_id)) {
1284 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail __internal_set_current_engine()");
1286 /* roll back to old current engine. */
1287 __internal_set_current_engine(tmp_uuid);
1288 ttsd_engine_agent_load_current_engine();
1290 if (tmp_uuid != NULL)
1293 return TTSD_ERROR_OPERATION_FAILED;
1297 if (0 != ttsd_engine_agent_load_current_engine()) {
1298 SLOG(LOG_ERROR, get_tag(), "[Engine Agent Error] fail to load new engine");
1300 if( tmp_uuid != NULL )
1303 return TTSD_ERROR_OPERATION_FAILED;
1305 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] load new engine");
1308 /* save engine id to config */
1309 if (0 != ttsd_config_set_default_engine(engine_id)) {
1310 SLOG(LOG_WARN, get_tag(), "[Engine Agent WARNING] Fail to save engine id to config");
1313 if (tmp_uuid != NULL)
1319 int ttsd_engine_setting_get_voice_list(char** engine_id, GList** voice_list)
1321 if (false == g_agent_init) {
1322 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1323 return TTSD_ERROR_OPERATION_FAILED;
1326 if (false == g_cur_engine.is_loaded) {
1327 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1328 return TTSD_ERROR_OPERATION_FAILED;
1333 /* get language list from engine*/
1334 ret = ttsd_engine_get_voice_list(voice_list);
1336 SLOG(LOG_ERROR, get_tag(), "[Server Error] fail ttsd_engine_get_voice_list() ");
1340 *engine_id = strdup(g_cur_engine.engine_uuid);
1345 int ttsd_engine_setting_get_default_voice(char** language, ttsp_voice_type_e* vctype)
1347 if (false == g_agent_init) {
1348 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1349 return TTSD_ERROR_OPERATION_FAILED;
1352 if (false == g_cur_engine.is_loaded) {
1353 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1354 return TTSD_ERROR_OPERATION_FAILED;
1357 /* get current language from engine*/
1360 ttsp_voice_type_e temp_int;
1362 ret = ttsd_engine_get_default_voice(&temp_lang, &temp_int);
1364 SLOG(LOG_ERROR, get_tag(), "[Server Error] fail ttsd_engine_get_default_voice()");
1368 if (NULL != temp_lang) {
1369 *language = strdup(temp_lang);
1373 SLOG(LOG_ERROR, get_tag(), "[Server Error] fail to get default language");
1374 return TTSD_ERROR_OPERATION_FAILED;
1380 int ttsd_engine_setting_set_default_voice(const char* language, ttsp_voice_type_e vctype)
1382 if (false == g_agent_init) {
1383 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1384 return TTSD_ERROR_OPERATION_FAILED;
1387 if (false == g_cur_engine.is_loaded) {
1388 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1389 return TTSD_ERROR_OPERATION_FAILED;
1392 if (NULL == g_cur_engine.pefuncs->is_valid_voice) {
1393 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] The function of engine is NULL!!");
1394 return TTSD_ERROR_OPERATION_FAILED;
1398 if(false == g_cur_engine.pefuncs->is_valid_voice(language, vctype)) {
1399 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Voice is NOT valid !!");
1400 return TTSD_ERROR_INVALID_VOICE;
1403 if (NULL != g_cur_engine.default_lang)
1404 free(g_cur_engine.default_lang);
1406 g_cur_engine.default_lang = strdup(language);
1407 g_cur_engine.default_vctype = vctype;
1409 ret = ttsd_config_set_default_voice(language, (int)vctype);
1411 SLOG(LOG_DEBUG, get_tag(), "[Engine Agent SUCCESS] Set default voice : lang(%s), type(%d)",
1412 g_cur_engine.default_lang, g_cur_engine.default_vctype);
1414 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret);
1420 int ttsd_engine_setting_get_default_speed(ttsp_speed_e* speed)
1422 if (false == g_agent_init) {
1423 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1424 return TTSD_ERROR_OPERATION_FAILED;
1427 if (false == g_cur_engine.is_loaded) {
1428 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1429 return TTSD_ERROR_OPERATION_FAILED;
1432 /* get current language */
1433 *speed = g_cur_engine.default_speed;
1438 int ttsd_engine_setting_set_default_speed(const ttsp_speed_e speed)
1440 if (false == g_agent_init) {
1441 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1442 return TTSD_ERROR_OPERATION_FAILED;
1445 if (false == g_cur_engine.is_loaded) {
1446 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1447 return TTSD_ERROR_OPERATION_FAILED;
1450 g_cur_engine.default_speed = speed;
1452 if (0 != ttsd_config_set_default_speed(speed)) {
1453 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set default speed to config");
1459 bool __engine_setting_cb(const char* key, const char* value, void* user_data)
1461 GList** engine_setting_list = (GList**)user_data;
1463 if (NULL == engine_setting_list || NULL == key || NULL == value) {
1464 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL in engine setting callback!!!!");
1468 engine_setting_s* temp = g_malloc0(sizeof(engine_setting_s));
1469 temp->key = g_strdup(key);
1470 temp->value = g_strdup(value);
1472 *engine_setting_list = g_list_append(*engine_setting_list, temp);
1478 int ttsd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list)
1480 if (false == g_agent_init) {
1481 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1482 return TTSD_ERROR_OPERATION_FAILED;
1485 if (false == g_cur_engine.is_loaded) {
1486 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1487 return TTSD_ERROR_OPERATION_FAILED;
1490 if (NULL == setting_list) {
1491 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Input parameter is NULL");
1492 return TTSD_ERROR_INVALID_PARAMETER;
1495 if (NULL == g_cur_engine.pefuncs->foreach_engine_setting) {
1496 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] foreach_engine_setting() of engine is NULL!!");
1497 return TTSD_ERROR_OPERATION_FAILED;
1500 /* get setting info and move setting info to input parameter */
1503 result = g_cur_engine.pefuncs->foreach_engine_setting(__engine_setting_cb, setting_list);
1505 if (0 == result && 0 < g_list_length(*setting_list)) {
1506 *engine_id = strdup(g_cur_engine.engine_uuid);
1508 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to get setting info : result(%d)", result);
1509 result = TTSD_ERROR_OPERATION_FAILED;
1515 int ttsd_engine_setting_set_engine_setting(const char* key, const char* value)
1517 if (false == g_agent_init) {
1518 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized" );
1519 return TTSD_ERROR_OPERATION_FAILED;
1522 if (false == g_cur_engine.is_loaded) {
1523 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine");
1524 return TTSD_ERROR_OPERATION_FAILED;
1527 if (NULL == g_cur_engine.pefuncs->set_engine_setting) {
1528 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] set_setting_info of engine is NULL!!");
1529 return TTSD_ERROR_OPERATION_FAILED;
1532 /* get setting info and move setting info to input parameter */
1534 ret = g_cur_engine.pefuncs->set_engine_setting(key, value);
1537 SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to set engine setting : result(%d)", ret);
1538 return TTSD_ERROR_OPERATION_FAILED;
1544 void __free_voice_list(GList* voice_list)
1547 voice_s* data = NULL;
1549 /* if list have item */
1550 if (g_list_length(voice_list) > 0) {
1551 /* Get a first item */
1552 iter = g_list_first(voice_list);
1554 while (NULL != iter) {
1558 if (NULL != data->language)
1559 g_free(data->language);
1564 voice_list = g_list_remove_link(voice_list, iter);
1566 iter = g_list_first(voice_list);
1572 * TTS Engine Callback Functions ` *
1574 bool __result_cb(ttsp_result_event_e event, const void* data, unsigned int data_size, void *user_data)
1576 g_result_cb(event, data, data_size, user_data);
1581 /* function for debugging */
1582 int ttsd_print_enginelist()
1585 ttsengine_info_s *data = NULL;
1587 if (g_list_length(g_engine_list) > 0) {
1588 iter = g_list_first(g_engine_list);
1590 SLOG(LOG_DEBUG, get_tag(), "----- engine list -----");
1593 while (NULL != iter) {
1596 SLOG(LOG_DEBUG, get_tag(), "[%dth]", i);
1597 SLOG(LOG_DEBUG, get_tag(), "engine uuid : %s", data->engine_uuid);
1598 SLOG(LOG_DEBUG, get_tag(), "engine name : %s", data->engine_name);
1599 SLOG(LOG_DEBUG, get_tag(), "engine path : %s", data->engine_path);
1600 SLOG(LOG_DEBUG, get_tag(), "setting ug path : %s", data->setting_ug_path);
1602 iter = g_list_next(iter);
1605 SLOG(LOG_DEBUG, get_tag(), "-----------------------");
1606 SLOG(LOG_DEBUG, get_tag(), " ");
1608 SLOG(LOG_DEBUG, get_tag(), "----- engine list -----");
1609 SLOG(LOG_DEBUG, get_tag(), "No Engine in directory");
1610 SLOG(LOG_DEBUG, get_tag(), "-----------------------");