2 * Copyright (c) 2011-2014 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.
19 #include "stt_engine.h"
20 #include "sttd_main.h"
21 #include "sttd_client_data.h"
22 #include "sttd_config.h"
23 #include "sttd_recorder.h"
24 #include "sttd_engine_agent.h"
27 #define AUDIO_CREATE_ON_START
30 * Internal data structure
36 bool use_default_engine;
39 typedef struct _sttengine_info {
45 char* engine_setting_path;
50 /* engine base setting */
52 bool silence_detection;
53 bool support_silence_detection;
56 /** stt engine agent init */
57 static bool g_agent_init;
60 static GSList* g_engine_client_list;
61 static GSList* g_engine_list;
63 /** default engine info */
64 static int g_default_engine_id;
65 static char* g_default_language;
66 static bool g_default_silence_detected;
68 static int g_engine_id_count;
70 /** current engine id */
71 static int g_recording_engine_id;
73 /** callback functions */
74 static result_callback g_result_cb;
75 static result_time_callback g_result_time_cb;
76 static silence_dectection_callback g_silence_cb;
79 /** callback functions */
80 void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
81 const char* msg, void* time_info, void *user_data);
83 bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text,
84 long start_time, long end_time, void* user_data);
86 void __detect_silence_cb(sttp_silence_type_e type, void* user_data);
88 bool __supported_language_cb(const char* language, void* user_data);
90 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
91 bool use_network, void* user_data);
97 /** get engine info */
98 int __internal_get_engine_info(const char* filepath, sttengine_info_s** info);
100 int __log_enginelist();
103 * STT Engine Agent Interfaces
105 int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb,
106 silence_dectection_callback silence_cb)
108 /* initialize static data */
109 if (NULL == result_cb || NULL == time_cb || NULL == silence_cb) {
110 SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] Invalid parameter");
111 return STTD_ERROR_INVALID_PARAMETER;
114 g_result_cb = result_cb;
115 g_result_time_cb = time_cb;
116 g_silence_cb = silence_cb;
118 g_default_engine_id = -1;
119 g_default_language = NULL;
120 g_engine_id_count = 1;
121 g_recording_engine_id = -1;
123 if (0 != sttd_config_get_default_language(&(g_default_language))) {
124 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is No default voice in config");
125 /* Set default voice */
126 g_default_language = strdup("en_US");
128 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default language is %s", g_default_language);
132 if (0 != sttd_config_get_default_silence_detection(&temp)) {
133 SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config");
134 g_default_silence_detected = true;
136 g_default_silence_detected = (bool)temp;
139 g_agent_init = false;
144 int __engine_agent_clear_engine(sttengine_info_s *engine)
146 if (NULL != engine) {
147 if (NULL != engine->engine_uuid) free(engine->engine_uuid);
148 if (NULL != engine->engine_path) free(engine->engine_path);
149 if (NULL != engine->engine_name) free(engine->engine_name);
150 if (NULL != engine->engine_setting_path)free(engine->engine_setting_path);
151 if (NULL != engine->first_lang) free(engine->first_lang);
159 int sttd_engine_agent_release()
161 /* Release client list */
163 sttengine_client_s *client = NULL;
165 if (g_slist_length(g_engine_client_list) > 0) {
166 /* Get a first item */
167 iter = g_slist_nth(g_engine_client_list, 0);
169 while (NULL != iter) {
170 /* Get handle data from list */
172 g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
177 iter = g_slist_nth(g_engine_client_list, 0);
181 g_slist_free(g_engine_client_list);
183 /* Release engine list */
184 sttengine_info_s *engine = NULL;
186 if (0 < g_slist_length(g_engine_list)) {
187 /* Get a first item */
188 iter = g_slist_nth(g_engine_list, 0);
190 while (NULL != iter) {
191 /* Get handle data from list */
193 g_engine_list = g_slist_remove_link(g_engine_list, iter);
195 /* Check engine unload */
196 if (engine->is_loaded) {
197 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", engine->engine_id);
199 if (0 != stt_engine_deinitialize(engine->engine_id))
200 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id);
202 if (0 != stt_engine_unload(engine->engine_id))
203 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
205 engine->is_loaded = false;
208 __engine_agent_clear_engine(engine);
210 iter = g_slist_nth(g_engine_list, 0);
217 g_agent_init = false;
218 g_default_engine_id = -1;
223 void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
224 bool use_network, void* user_data)
226 sttengine_info_s* temp = (sttengine_info_s*)user_data;
228 temp->engine_uuid = g_strdup(engine_uuid);
229 temp->engine_name = g_strdup(engine_name);
230 temp->engine_setting_path = g_strdup(setting_ug_name);
231 temp->use_network = use_network;
234 int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
236 if (NULL == filepath || NULL == info) {
237 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
238 return STTD_ERROR_INVALID_PARAMETER;
245 handle = dlopen(filepath, RTLD_LAZY);
248 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath);
249 return STTD_ERROR_ENGINE_NOT_FOUND;
252 /* link engine to daemon */
253 dlsym(handle, "sttp_load_engine");
254 if ((error = dlerror()) != NULL) {
255 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error);
257 return STTD_ERROR_ENGINE_NOT_FOUND;
260 dlsym(handle, "sttp_unload_engine");
261 if ((error = dlerror()) != NULL) {
262 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error);
264 return STTD_ERROR_ENGINE_NOT_FOUND;
267 int (*get_engine_info)(sttpe_engine_info_cb callback, void* user_data);
269 get_engine_info = (int (*)(sttpe_engine_info_cb, void*))dlsym(handle, "sttp_get_engine_info");
270 if ((error = dlerror()) != NULL || NULL == get_engine_info) {
271 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error);
273 return STTD_ERROR_ENGINE_NOT_FOUND;
276 sttengine_info_s* temp;
277 temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s));
279 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
281 return STTD_ERROR_OUT_OF_MEMORY;
284 /* get engine info */
285 if (0 != get_engine_info(__engine_info_cb, (void*)temp)) {
286 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info from engine");
289 return STTD_ERROR_ENGINE_NOT_FOUND;
295 temp->engine_id = g_engine_id_count;
298 temp->engine_path = g_strdup(filepath);
299 temp->is_loaded = false;
301 SLOG(LOG_DEBUG, TAG_STTD, "----- Valid Engine");
302 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine id : %d", temp->engine_id);
303 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", temp->engine_uuid);
304 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", temp->engine_name);
305 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", temp->engine_path);
306 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine setting path : %s", temp->engine_setting_path);
307 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true" : "false");
308 SLOG(LOG_DEBUG, TAG_STTD, "-----");
309 SLOG(LOG_DEBUG, TAG_STTD, " ");
313 return STTD_ERROR_NONE;
316 bool __is_engine(const char* filepath)
319 sttengine_info_s *engine = NULL;
321 if (0 < g_slist_length(g_engine_list)) {
322 /* Get a first item */
323 iter = g_slist_nth(g_engine_list, 0);
325 while (NULL != iter) {
326 /* Get handle data from list */
329 if (0 == strcmp(engine->engine_path, filepath)) {
333 iter = g_slist_next(iter);
340 int sttd_engine_agent_initialize_engine_list()
342 /* Get file name from default engine directory */
346 struct dirent *dirp = NULL;
348 dp = opendir(STT_DEFAULT_ENGINE);
351 ret = readdir_r(dp, &entry, &dirp);
353 SLOG(LOG_ERROR, TAG_STTD, "[File ERROR] Fail to read directory");
358 sttengine_info_s* info;
362 filesize = strlen(STT_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
363 filepath = (char*)calloc(filesize, sizeof(char));
365 if (NULL != filepath) {
366 snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE, dirp->d_name);
368 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!");
372 if (false == __is_engine(filepath)) {
373 /* get its info and update engine list */
374 if (0 == __internal_get_engine_info(filepath, &info)) {
375 /* add engine info to g_engine_list */
376 g_engine_list = g_slist_append(g_engine_list, info);
380 if (NULL != filepath)
383 } while (NULL != dirp);
387 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory");
390 if (0 >= g_slist_length(g_engine_list)) {
391 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
392 return STTD_ERROR_ENGINE_NOT_FOUND;
397 /* Set default engine */
399 sttengine_info_s *engine = NULL;
400 char* cur_engine_uuid = NULL;
401 bool is_default_engine = false;
403 /* get current engine from config */
404 if (0 == sttd_config_get_default_engine(&cur_engine_uuid)) {
405 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] current engine from config : %s", cur_engine_uuid);
407 if (0 < g_slist_length(g_engine_list)) {
408 /* Get a first item */
409 iter = g_slist_nth(g_engine_list, 0);
411 while (NULL != iter) {
412 /* Get handle data from list */
415 if (0 == strcmp(engine->engine_uuid, cur_engine_uuid)) {
416 is_default_engine = true;
417 g_default_engine_id = engine->engine_id;
421 iter = g_slist_next(iter);
425 if (cur_engine_uuid != NULL)
426 free(cur_engine_uuid);
428 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is not current engine from config");
431 if (false == is_default_engine) {
432 if (0 < g_slist_length(g_engine_list)) {
433 /* Get a first item */
434 iter = g_slist_nth(g_engine_list, 0);
436 /* Get handle data from list */
439 if (NULL != engine) {
440 is_default_engine = true;
441 g_default_engine_id = engine->engine_id;
446 if (NULL != engine) {
447 if (NULL != engine->engine_uuid) {
448 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine Id(%d) uuid(%s)", engine->engine_id, engine->engine_uuid);
450 if (false == is_default_engine) {
451 if (0 != sttd_config_set_default_engine(engine->engine_uuid))
452 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine ");
456 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is NULL");
457 return STTD_ERROR_ENGINE_NOT_FOUND;
465 sttengine_info_s* __engine_agent_get_engine_by_id(int engine_id)
468 sttengine_info_s *data = NULL;
470 iter = g_slist_nth(g_engine_list, 0);
472 while (NULL != iter) {
476 if (data->engine_id == engine_id)
479 iter = g_slist_next(iter);
485 sttengine_info_s* __engine_agent_get_engine_by_uuid(const char* engine_uuid)
488 sttengine_info_s *data = NULL;
490 iter = g_slist_nth(g_engine_list, 0);
492 while (NULL != iter) {
496 if (0 == strcmp(data->engine_uuid, engine_uuid))
499 iter = g_slist_next(iter);
505 sttengine_client_s* __engine_agent_get_client(int uid)
508 sttengine_client_s *data = NULL;
510 if (0 < g_slist_length(g_engine_client_list)) {
511 iter = g_slist_nth(g_engine_client_list, 0);
513 while (NULL != iter) {
514 /* Get handle data from list */
517 if (uid == data->uid)
520 iter = g_slist_next(iter);
527 sttengine_info_s* __engine_agent_get_engine_by_uid(int uid)
529 sttengine_client_s *data;
531 data = __engine_agent_get_client(uid);
533 return __engine_agent_get_engine_by_id(data->engine_id);
538 int __engine_agent_check_engine_unload(int engine_id)
540 /* Check the count of client to use this engine */
542 int client_count = 0;
543 sttengine_client_s *data = NULL;
545 if (0 < g_slist_length(g_engine_client_list)) {
546 iter = g_slist_nth(g_engine_client_list, 0);
548 while (NULL != iter) {
549 /* Get handle data from list */
552 if (data->engine_id == engine_id)
555 iter = g_slist_next(iter);
559 if (0 == client_count) {
560 sttengine_info_s* engine = NULL;
561 engine = __engine_agent_get_engine_by_id(engine_id);
562 if (NULL == engine) {
563 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine from client(%d)", engine_id);
565 if (engine->is_loaded) {
567 #ifndef AUDIO_CREATE_ON_START
568 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
569 if (0 != sttd_recorder_destroy(engine->engine_id))
570 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
572 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", engine_id);
573 if (0 != stt_engine_deinitialize(engine->engine_id))
574 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id);
576 if (0 != stt_engine_unload(engine->engine_id))
577 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
579 engine->is_loaded = false;
587 int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
589 if (false == g_agent_init) {
590 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
591 return STTD_ERROR_OPERATION_FAILED;
594 sttengine_client_s* client = NULL;
595 sttengine_info_s* engine = NULL;
596 int before_engine = -1;
598 client = __engine_agent_get_client(uid);
600 if (NULL == client) {
601 client = (sttengine_client_s*)calloc(1, sizeof(sttengine_client_s));
602 if (NULL == client) {
603 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
604 return STTD_ERROR_OUT_OF_MEMORY;
609 client->engine_id = -1;
611 g_engine_client_list = g_slist_append(g_engine_client_list, client);
613 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Registered client(%d)", uid);
616 if (NULL == engine_uuid) {
617 /* Set default engine */
618 engine = __engine_agent_get_engine_by_id(g_default_engine_id);
620 if (NULL == engine) {
621 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get default engine : %d", g_default_engine_id);
622 return STTD_ERROR_OPERATION_FAILED;
624 before_engine = client->engine_id;
626 client->engine_id = engine->engine_id;
627 client->use_default_engine = true;
629 /* Set engine by uid */
630 engine = __engine_agent_get_engine_by_uuid(engine_uuid);
632 if (NULL == engine) {
633 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine : %s", engine_uuid);
634 return STTD_ERROR_OPERATION_FAILED;
636 before_engine = client->engine_id;
638 client->engine_id = engine->engine_id;
639 client->use_default_engine = false;
642 if (-1 != before_engine) {
643 /* Unload engine if reference count is 0 */
644 __engine_agent_check_engine_unload(before_engine);
647 if (true == engine->is_loaded) {
648 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine] engine id(%d) is already loaded", engine->engine_id);
654 ret = stt_engine_load(engine->engine_id, engine->engine_path);
656 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
657 return STTD_ERROR_OPERATION_FAILED;
660 ret = stt_engine_initialize(engine->engine_id, __result_cb, __detect_silence_cb);
662 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
663 return STTD_ERROR_OPERATION_FAILED;
666 ret = stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected);
668 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Not support silence detection");
669 engine->support_silence_detection = false;
671 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Silence detection : %s", g_default_silence_detected ? "true" : "false");
672 engine->support_silence_detection = true;
673 engine->silence_detection = g_default_silence_detected;
676 /* Set first language */
677 char* tmp_lang = NULL;
678 ret = stt_engine_get_first_language(engine->engine_id, &tmp_lang);
679 if (0 == ret && NULL != tmp_lang) {
680 engine->first_lang = strdup(tmp_lang);
683 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get first language from engine : %d %s", engine->engine_id, engine->engine_name);
684 return STTD_ERROR_OPERATION_FAILED;
687 #ifndef AUDIO_CREATE_ON_START
689 sttp_audio_type_e atype;
693 ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
695 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
696 return STTD_ERROR_OPERATION_FAILED;
699 ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
701 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
702 return STTD_ERROR_OPERATION_FAILED;
706 engine->is_loaded = true;
707 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s(%d) has been loaded !!!", engine->engine_name, engine->engine_id);
712 int sttd_engine_agent_unload_current_engine(int uid)
714 if (false == g_agent_init) {
715 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
716 return STTD_ERROR_OPERATION_FAILED;
723 sttengine_client_s *data = NULL;
725 if (0 < g_slist_length(g_engine_client_list)) {
726 iter = g_slist_nth(g_engine_client_list, 0);
728 while (NULL != iter) {
729 /* Get handle data from list */
733 if (uid == data->uid) {
734 g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
735 engine_id = data->engine_id;
741 iter = g_slist_next(iter);
745 if (-1 != engine_id) {
746 __engine_agent_check_engine_unload(engine_id);
752 bool sttd_engine_agent_is_default_engine()
754 if (g_default_engine_id > 0)
760 int sttd_engine_agent_get_engine_list(GSList** engine_list)
762 if (false == g_agent_init) {
763 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
764 return STTD_ERROR_OPERATION_FAILED;
768 sttengine_info_s *data = NULL;
770 iter = g_slist_nth(g_engine_list, 0);
772 SLOG(LOG_DEBUG, TAG_STTD, "----- [Engine Agent] engine list -----");
774 while (NULL != iter) {
775 engine_s* temp_engine;
777 temp_engine = (engine_s*)calloc(1, sizeof(engine_s));
778 if (NULL == temp_engine) {
779 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
780 return STTD_ERROR_OUT_OF_MEMORY;
785 temp_engine->engine_id = strdup(data->engine_uuid);
786 temp_engine->engine_name = strdup(data->engine_name);
787 temp_engine->ug_name = strdup(data->engine_setting_path);
789 *engine_list = g_slist_append(*engine_list, temp_engine);
791 iter = g_slist_next(iter);
793 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " -- Engine id(%s)", temp_engine->engine_id);
794 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " Engine name(%s)", temp_engine->engine_name);
795 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " Engine ug name(%s)", temp_engine->ug_name);
798 SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
803 int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
805 if (false == g_agent_init) {
806 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
807 return STTD_ERROR_OPERATION_FAILED;
810 if (NULL == engine_uuid) {
811 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid parameter");
812 return STTD_ERROR_INVALID_PARAMETER;
815 sttengine_info_s* engine;
816 engine = __engine_agent_get_engine_by_uid(uid);
818 if (NULL == engine) {
819 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
820 return STTD_ERROR_INVALID_PARAMETER;
823 if (false == engine->is_loaded) {
824 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
825 return STTD_ERROR_OPERATION_FAILED;
828 *engine_uuid = strdup(engine->engine_uuid);
833 bool sttd_engine_agent_need_network(int uid)
835 if (false == g_agent_init) {
836 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
837 return STTD_ERROR_OPERATION_FAILED;
840 sttengine_info_s* engine;
841 engine = __engine_agent_get_engine_by_uid(uid);
844 return engine->use_network;
849 int sttd_engine_agent_supported_langs(int uid, GSList** lang_list)
851 if (false == g_agent_init) {
852 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
853 return STTD_ERROR_OPERATION_FAILED;
856 if (NULL == lang_list) {
857 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL");
858 return STTD_ERROR_INVALID_PARAMETER;
861 sttengine_info_s* engine = NULL;
862 engine = __engine_agent_get_engine_by_uid(uid);
864 if (NULL == engine) {
865 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
866 return STTD_ERROR_INVALID_PARAMETER;
869 if (false == engine->is_loaded) {
870 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
871 return STTD_ERROR_OPERATION_FAILED;
874 int ret = stt_engine_get_supported_langs(engine->engine_id, lang_list);
876 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
877 return STTD_ERROR_OPERATION_FAILED;
883 int sttd_engine_agent_get_default_lang(int uid, char** lang)
885 if (false == g_agent_init) {
886 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
887 return STTD_ERROR_OPERATION_FAILED;
891 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
892 return STTD_ERROR_INVALID_PARAMETER;
895 sttengine_info_s* engine = NULL;
896 engine = __engine_agent_get_engine_by_uid(uid);
898 if (NULL == engine) {
899 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
900 return STTD_ERROR_INVALID_PARAMETER;
903 if (false == engine->is_loaded) {
904 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
905 return STTD_ERROR_OPERATION_FAILED;
908 /* get default language */
909 bool is_valid = false;
910 if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
911 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
912 return STTD_ERROR_OPERATION_FAILED;
915 if (true == is_valid) {
916 *lang = strdup(g_default_language);
918 *lang = strdup(engine->first_lang);
923 int sttd_engine_agent_get_option_supported(int uid, bool* silence)
925 if (false == g_agent_init) {
926 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
927 return STTD_ERROR_OPERATION_FAILED;
930 if (NULL == silence) {
931 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
932 return STTD_ERROR_INVALID_PARAMETER;
935 sttengine_info_s* engine = NULL;
936 engine = __engine_agent_get_engine_by_uid(uid);
938 if (NULL == engine) {
939 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] uid(%d) is not valid", uid);
940 return STTD_ERROR_INVALID_PARAMETER;
943 if (false == engine->is_loaded) {
944 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
945 return STTD_ERROR_OPERATION_FAILED;
948 *silence = engine->support_silence_detection;
953 int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support)
955 if (false == g_agent_init) {
956 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
957 return STTD_ERROR_OPERATION_FAILED;
960 if (NULL == type || NULL == support) {
961 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
962 return STTD_ERROR_INVALID_PARAMETER;
965 sttengine_info_s* engine = NULL;
966 engine = __engine_agent_get_engine_by_uid(uid);
968 if (NULL == engine) {
969 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
970 return STTD_ERROR_INVALID_PARAMETER;
973 if (false == engine->is_loaded) {
974 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
975 return STTD_ERROR_OPERATION_FAILED;
981 ret = stt_engine_support_recognition_type(engine->engine_id, type, &temp);
983 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
984 return STTD_ERROR_OPERATION_FAILED;
993 * STT Engine Interfaces for client
996 int __set_option(sttengine_info_s* engine, int silence)
1001 /* Check silence detection */
1002 if (engine->support_silence_detection) {
1004 /* default option set */
1005 if (g_default_silence_detected != engine->silence_detection) {
1006 if (0 != stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected)) {
1007 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", g_default_silence_detected ? "true" : "false");
1009 engine->silence_detection = g_default_silence_detected;
1010 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_default_silence_detected ? "true" : "false");
1014 if (silence != engine->silence_detection) {
1015 if (0 != stt_engine_set_silence_detection(engine->engine_id, silence)) {
1016 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", silence ? "true" : "false");
1018 engine->silence_detection = silence;
1019 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", silence ? "true" : "false");
1028 int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
1029 int silence, void* user_param)
1031 if (false == g_agent_init) {
1032 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1033 return STTD_ERROR_OPERATION_FAILED;
1036 if (NULL == lang || NULL == recognition_type) {
1037 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1038 return STTD_ERROR_INVALID_PARAMETER;
1041 sttengine_info_s* engine = NULL;
1042 engine = __engine_agent_get_engine_by_uid(uid);
1044 if (NULL == engine) {
1045 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1046 return STTD_ERROR_INVALID_PARAMETER;
1049 if (false == engine->is_loaded) {
1050 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1051 return STTD_ERROR_OPERATION_FAILED;
1054 if (0 != __set_option(engine, silence)) {
1055 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options");
1056 return STTD_ERROR_OPERATION_FAILED;
1059 SLOG(LOG_DEBUG, TAG_STTD, "g_default_language %s", g_default_language);
1063 if (0 == strncmp(lang, "default", strlen("default"))) {
1064 bool is_valid = false;
1065 if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
1066 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
1067 return STTD_ERROR_OPERATION_FAILED;
1070 if (true == is_valid) {
1071 temp = strdup(g_default_language);
1072 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is %s", temp);
1074 temp = strdup(engine->first_lang);
1075 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is engine first lang : %s", temp);
1078 temp = strdup(lang);
1081 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start engine");
1083 ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, user_param);
1084 if (NULL != temp) free(temp);
1086 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Recognition start error(%d)", ret);
1087 sttd_recorder_destroy(engine->engine_id);
1088 return STTD_ERROR_OPERATION_FAILED;
1091 #ifdef AUDIO_CREATE_ON_START
1092 /* Ready recorder */
1093 sttp_audio_type_e atype;
1097 ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
1099 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
1100 return STTD_ERROR_OPERATION_FAILED;
1103 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Create recorder");
1105 ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
1107 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
1108 return STTD_ERROR_OPERATION_FAILED;
1113 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
1115 ret = sttd_recorder_start(engine->engine_id);
1117 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
1121 g_recording_engine_id = engine->engine_id;
1122 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
1128 int sttd_engine_agent_recognize_start_recorder(int uid)
1130 sttengine_info_s* engine = NULL;
1131 engine = __engine_agent_get_engine_by_uid(uid);
1133 if (NULL == engine) {
1134 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1135 return STTD_ERROR_INVALID_PARAMETER;
1138 if (false == engine->is_loaded) {
1139 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1140 return STTD_ERROR_OPERATION_FAILED;
1143 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
1146 ret = sttd_recorder_start(engine->engine_id);
1148 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
1149 stt_engine_recognize_cancel(engine->engine_id);
1150 sttd_recorder_stop(engine->engine_id);
1154 g_recording_engine_id = engine->engine_id;
1155 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
1160 int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int length)
1162 if (false == g_agent_init) {
1163 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1164 return STTD_ERROR_OPERATION_FAILED;
1167 if (NULL == data || 0 == length) {
1168 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1169 return STTD_ERROR_INVALID_PARAMETER;
1172 sttengine_info_s* engine = NULL;
1173 engine = __engine_agent_get_engine_by_uid(uid);
1175 if (NULL == engine) {
1176 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1177 return STTD_ERROR_INVALID_PARAMETER;
1180 if (false == engine->is_loaded) {
1181 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1182 return STTD_ERROR_OPERATION_FAILED;
1185 int ret = stt_engine_set_recording_data(engine->engine_id, data, length);
1187 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
1188 return STTD_ERROR_OPERATION_FAILED;
1194 int sttd_engine_agent_recognize_stop_recorder(int uid)
1196 if (false == g_agent_init) {
1197 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1198 return STTD_ERROR_OPERATION_FAILED;
1201 sttengine_info_s* engine = NULL;
1202 engine = __engine_agent_get_engine_by_uid(uid);
1204 if (NULL == engine) {
1205 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1206 return STTD_ERROR_INVALID_PARAMETER;
1209 if (false == engine->is_loaded) {
1210 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1211 return STTD_ERROR_OPERATION_FAILED;
1214 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
1216 ret = sttd_recorder_stop(engine->engine_id);
1218 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
1219 return STTD_ERROR_OPERATION_FAILED;
1222 #ifdef AUDIO_CREATE_ON_START
1223 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1224 if (0 != sttd_recorder_destroy(engine->engine_id))
1225 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
1228 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop recorder");
1232 int sttd_engine_agent_recognize_stop_engine(int uid)
1234 if (false == g_agent_init) {
1235 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1236 return STTD_ERROR_OPERATION_FAILED;
1239 sttengine_info_s* engine = NULL;
1240 engine = __engine_agent_get_engine_by_uid(uid);
1242 if (NULL == engine) {
1243 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1244 return STTD_ERROR_INVALID_PARAMETER;
1247 if (false == engine->is_loaded) {
1248 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1249 return STTD_ERROR_OPERATION_FAILED;
1252 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop engine");
1255 ret = stt_engine_recognize_stop(engine->engine_id);
1257 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
1258 return STTD_ERROR_OPERATION_FAILED;
1261 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop engine");
1266 int sttd_engine_agent_recognize_cancel(int uid)
1268 if (false == g_agent_init) {
1269 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1270 return STTD_ERROR_OPERATION_FAILED;
1273 sttengine_info_s* engine = NULL;
1274 engine = __engine_agent_get_engine_by_uid(uid);
1276 if (NULL == engine) {
1277 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1278 return STTD_ERROR_INVALID_PARAMETER;
1281 if (false == engine->is_loaded) {
1282 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1283 return STTD_ERROR_OPERATION_FAILED;
1286 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Cancel engine");
1289 ret = stt_engine_recognize_cancel(engine->engine_id);
1291 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
1292 return STTD_ERROR_OPERATION_FAILED;
1295 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
1297 ret = sttd_recorder_stop(engine->engine_id);
1299 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
1300 return STTD_ERROR_OPERATION_FAILED;
1303 #ifdef AUDIO_CREATE_ON_START
1304 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1305 if (0 != sttd_recorder_destroy(engine->engine_id))
1306 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
1309 g_recording_engine_id = -1;
1311 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Cancel recognition");
1318 * STT Engine Interfaces for configure
1321 int sttd_engine_agent_set_default_engine(const char* engine_uuid)
1323 if (false == g_agent_init) {
1324 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1325 return STTD_ERROR_OPERATION_FAILED;
1328 if (NULL == engine_uuid) {
1329 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1330 return STTD_ERROR_INVALID_PARAMETER;
1335 sttengine_info_s* engine;
1336 engine = __engine_agent_get_engine_by_uuid(engine_uuid);
1337 if (NULL == engine) {
1338 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is not valid");
1339 return STTD_ERROR_ENGINE_NOT_FOUND;
1342 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine id(%d) engine uuid(%s)", engine->engine_id, engine->engine_uuid);
1344 g_default_engine_id = engine->engine_id;
1346 /* Update default engine of client */
1347 GSList *iter = NULL;
1348 sttengine_client_s *data = NULL;
1350 if (0 < g_slist_length(g_engine_client_list)) {
1351 iter = g_slist_nth(g_engine_client_list, 0);
1353 while (NULL != iter) {
1354 /* Get handle data from list */
1357 if (true == data->use_default_engine) {
1358 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] uid(%d) change engine from id(%d) to id(%d)",
1359 data->uid, data->engine_id, engine->engine_id);
1361 if (0 != sttd_engine_agent_load_current_engine(data->uid, NULL)) {
1362 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load current engine : uid(%d)", data->uid);
1366 iter = g_slist_next(iter);
1373 int sttd_engine_agent_set_default_language(const char* language)
1375 if (false == g_agent_init) {
1376 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1377 return STTD_ERROR_OPERATION_FAILED;
1380 if (NULL == language) {
1381 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1382 return STTD_ERROR_INVALID_PARAMETER;
1385 if (NULL != g_default_language)
1386 free(g_default_language);
1388 g_default_language = strdup(language);
1393 int sttd_engine_agent_set_silence_detection(bool value)
1395 if (false == g_agent_init) {
1396 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1397 return STTD_ERROR_OPERATION_FAILED;
1400 g_default_silence_detected = value;
1405 int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result)
1407 if (false == g_agent_init) {
1408 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1409 return STTD_ERROR_OPERATION_FAILED;
1412 sttengine_info_s* engine = NULL;
1413 engine = __engine_agent_get_engine_by_uid(uid);
1415 if (NULL == engine) {
1416 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1417 return STTD_ERROR_INVALID_PARAMETER;
1420 if (false == engine->is_loaded) {
1421 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1422 return STTD_ERROR_OPERATION_FAILED;
1426 ret = stt_engine_check_app_agreed(engine->engine_id, appid, result);
1428 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
1429 return STTD_ERROR_OPERATION_FAILED;
1433 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Get engine right : %s", *result ? "true" : "false");
1438 * STT Engine Callback Functions ` *
1441 void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
1442 const char* msg, void* time_info, void *user_data)
1444 if (false == g_agent_init) {
1445 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized");
1449 SLOG(LOG_DEBUG, TAG_STTD, "[Server] === Result time callback ===");
1451 if (NULL != time_info) {
1452 /* Get the time info */
1453 int ret = stt_engine_foreach_result_time(g_recording_engine_id, time_info, __result_time_cb, NULL);
1455 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get time info : %d", ret);
1459 SLOG(LOG_DEBUG, TAG_STTD, "[Server] ============================");
1461 g_result_cb(event, type, data, data_count, msg, user_data);
1463 #ifdef AUDIO_CREATE_ON_START
1464 if (event == STTP_RESULT_EVENT_ERROR) {
1465 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1466 if (0 != sttd_recorder_destroy(g_recording_engine_id))
1467 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", g_recording_engine_id);
1471 if (event == STTP_RESULT_EVENT_FINAL_RESULT || event == STTP_RESULT_EVENT_ERROR) {
1472 g_recording_engine_id = -1;
1478 bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
1480 return g_result_time_cb(index, event, text, start_time, end_time, user_data);
1483 void __detect_silence_cb(sttp_silence_type_e type, void* user_data)
1485 if (false == g_agent_init) {
1486 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
1490 g_silence_cb(type, user_data);
1494 /* A function forging */
1495 int __log_enginelist()
1497 GSList *iter = NULL;
1498 sttengine_info_s *data = NULL;
1500 if (0 < g_slist_length(g_engine_list)) {
1502 /* Get a first item */
1503 iter = g_slist_nth(g_engine_list, 0);
1505 SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
1508 while (NULL != iter) {
1509 /* Get handle data from list */
1512 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[%dth]", i);
1513 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine uuid : %s", data->engine_uuid);
1514 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine name : %s", data->engine_name);
1515 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine path : %s", data->engine_path);
1516 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " use network : %s", data->use_network ? "true" : "false");
1517 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " is loaded : %s", data->is_loaded ? "true" : "false");
1518 if (NULL != data->first_lang)
1519 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " default lang : %s", data->first_lang);
1521 iter = g_slist_next(iter);
1524 SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
1526 SLOG(LOG_DEBUG, TAG_STTD, "-------------- engine list -------------------");
1527 SLOG(LOG_DEBUG, TAG_STTD, " No Engine in engine directory");
1528 SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");