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);
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);
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);
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);
276 sttengine_info_s* temp;
277 temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s));
279 /* get engine info */
280 if (0 != get_engine_info(__engine_info_cb, (void*)temp)) {
281 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info from engine");
290 temp->engine_id = g_engine_id_count;
293 temp->engine_path = g_strdup(filepath);
294 temp->is_loaded = false;
296 SLOG(LOG_DEBUG, TAG_STTD, "----- Valid Engine");
297 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine id : %d", temp->engine_id);
298 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", temp->engine_uuid);
299 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", temp->engine_name);
300 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", temp->engine_path);
301 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine setting path : %s", temp->engine_setting_path);
302 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true":"false");
303 SLOG(LOG_DEBUG, TAG_STTD, "-----");
304 SLOG(LOG_DEBUG, TAG_STTD, " ");
311 bool __is_engine(const char* filepath)
314 sttengine_info_s *engine = NULL;
316 if (0 < g_slist_length(g_engine_list)) {
317 /* Get a first item */
318 iter = g_slist_nth(g_engine_list, 0);
320 while (NULL != iter) {
321 /* Get handle data from list */
324 if (0 == strcmp(engine->engine_path, filepath)) {
328 iter = g_slist_next(iter);
335 int sttd_engine_agent_initialize_engine_list()
337 /* Get file name from default engine directory */
341 struct dirent *dirp = NULL;
343 dp = opendir(STT_DEFAULT_ENGINE);
346 ret = readdir_r(dp, &entry, &dirp);
348 SLOG(LOG_ERROR, TAG_STTD, "[File ERROR] Fail to read directory");
353 sttengine_info_s* info;
357 filesize = strlen(STT_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
358 filepath = (char*)calloc(filesize, sizeof(char));
360 if (NULL != filepath) {
361 snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE, dirp->d_name);
363 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!");
367 if (false == __is_engine(filepath)) {
368 /* get its info and update engine list */
369 if (0 == __internal_get_engine_info(filepath, &info)) {
370 /* add engine info to g_engine_list */
371 g_engine_list = g_slist_append(g_engine_list, info);
375 if (NULL != filepath)
378 } while (NULL != dirp);
382 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory");
385 /* Get file name from downloadable engine directory */
386 dp = opendir(STT_DOWNLOAD_ENGINE);
389 ret = readdir_r(dp, &entry, &dirp);
391 SLOG(LOG_ERROR, TAG_STTD, "[File ERROR] Fail to read directory");
396 sttengine_info_s* info;
400 filesize = strlen(STT_DOWNLOAD_ENGINE) + strlen(dirp->d_name) + 5;
401 filepath = (char*)calloc(filesize, sizeof(char));
403 if (NULL != filepath) {
404 snprintf(filepath, filesize, "%s/%s", STT_DOWNLOAD_ENGINE, dirp->d_name);
406 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enouth!!");
410 /* get its info and update engine list */
411 if (0 == __internal_get_engine_info(filepath, &info)) {
412 /* add engine info to g_engine_list */
413 g_engine_list = g_slist_append(g_engine_list, info);
416 if (NULL != filepath)
419 } while (NULL != dirp);
423 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open downloadable directory");
426 if (0 >= g_slist_length(g_engine_list)) {
427 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
428 return STTD_ERROR_ENGINE_NOT_FOUND;
433 /* Set default engine */
435 sttengine_info_s *engine = NULL;
436 char* cur_engine_uuid = NULL;
437 bool is_default_engine = false;
439 /* get current engine from config */
440 if (0 == sttd_config_get_default_engine(&cur_engine_uuid)) {
441 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] current engine from config : %s", cur_engine_uuid);
443 if (0 < g_slist_length(g_engine_list)) {
444 /* Get a first item */
445 iter = g_slist_nth(g_engine_list, 0);
447 while (NULL != iter) {
448 /* Get handle data from list */
451 if (0 == strcmp(engine->engine_uuid, cur_engine_uuid)) {
452 is_default_engine = true;
453 g_default_engine_id = engine->engine_id;
457 iter = g_slist_next(iter);
461 if (cur_engine_uuid != NULL )
462 free(cur_engine_uuid);
464 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is not current engine from config");
467 if (false == is_default_engine) {
468 if (0 < g_slist_length(g_engine_list)) {
469 /* Get a first item */
470 iter = g_slist_nth(g_engine_list, 0);
472 /* Get handle data from list */
475 if (NULL != engine) {
476 is_default_engine = true;
477 g_default_engine_id = engine->engine_id;
482 if (NULL != engine) {
483 if (NULL != engine->engine_uuid) {
484 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine Id(%d) uuid(%s)", engine->engine_id, engine->engine_uuid);
486 if (false == is_default_engine) {
487 if (0 != sttd_config_set_default_engine(engine->engine_uuid))
488 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine ");
492 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is NULL");
493 return STTD_ERROR_ENGINE_NOT_FOUND;
501 sttengine_info_s* __engine_agent_get_engine_by_id(int engine_id)
504 sttengine_info_s *data = NULL;
506 iter = g_slist_nth(g_engine_list, 0);
508 while (NULL != iter) {
512 if (data->engine_id == engine_id)
515 iter = g_slist_next(iter);
521 sttengine_info_s* __engine_agent_get_engine_by_uuid(const char* engine_uuid)
524 sttengine_info_s *data = NULL;
526 iter = g_slist_nth(g_engine_list, 0);
528 while (NULL != iter) {
532 if (0 == strcmp(data->engine_uuid, engine_uuid))
535 iter = g_slist_next(iter);
541 sttengine_client_s* __engine_agent_get_client(int uid)
544 sttengine_client_s *data = NULL;
546 if (0 < g_slist_length(g_engine_client_list)) {
547 iter = g_slist_nth(g_engine_client_list, 0);
549 while (NULL != iter) {
550 /* Get handle data from list */
553 if (uid == data->uid)
556 iter = g_slist_next(iter);
563 sttengine_info_s* __engine_agent_get_engine_by_uid(int uid)
565 sttengine_client_s *data;
567 data = __engine_agent_get_client(uid);
569 return __engine_agent_get_engine_by_id(data->engine_id);
574 int __engine_agent_check_engine_unload(int engine_id)
576 /* Check the count of client to use this engine */
578 int client_count = 0;
579 sttengine_client_s *data = NULL;
581 if (0 < g_slist_length(g_engine_client_list)) {
582 iter = g_slist_nth(g_engine_client_list, 0);
584 while (NULL != iter) {
585 /* Get handle data from list */
588 if (data->engine_id == engine_id)
591 iter = g_slist_next(iter);
595 if (0 == client_count) {
596 sttengine_info_s* engine = NULL;
597 engine = __engine_agent_get_engine_by_id(engine_id);
598 if (NULL == engine) {
599 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine from client(%d)", engine_id);
601 if (engine->is_loaded) {
603 #ifndef AUDIO_CREATE_ON_START
604 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
605 if (0 != sttd_recorder_destroy(engine->engine_id))
606 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
608 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", engine_id);
609 if (0 != stt_engine_deinitialize(engine->engine_id))
610 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id);
612 if (0 != stt_engine_unload(engine->engine_id))
613 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
615 engine->is_loaded = false;
623 int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
625 if (false == g_agent_init) {
626 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
627 return STTD_ERROR_OPERATION_FAILED;
630 sttengine_client_s* client = NULL;
631 sttengine_info_s* engine = NULL;
632 int before_engine = -1;
634 client = __engine_agent_get_client(uid);
636 if (NULL == client) {
637 client = (sttengine_client_s*)calloc(1, sizeof(sttengine_client_s));
641 client->engine_id = -1;
643 g_engine_client_list = g_slist_append(g_engine_client_list, client);
645 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Registered client(%d)", uid);
648 if (NULL == engine_uuid) {
649 /* Set default engine */
650 engine = __engine_agent_get_engine_by_id(g_default_engine_id);
652 if (NULL == engine) {
653 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get default engine : %d", g_default_engine_id);
654 return STTD_ERROR_OPERATION_FAILED;
656 before_engine = client->engine_id;
658 client->engine_id = engine->engine_id;
659 client->use_default_engine = true;
661 /* Set engine by uid */
662 engine = __engine_agent_get_engine_by_uuid(engine_uuid);
664 if (NULL == engine) {
665 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine : %s", engine_uuid);
666 return STTD_ERROR_OPERATION_FAILED;
668 before_engine = client->engine_id;
670 client->engine_id = engine->engine_id;
671 client->use_default_engine = false;
674 if (-1 != before_engine) {
675 /* Unload engine if reference count is 0 */
676 __engine_agent_check_engine_unload(before_engine);
679 if (true == engine->is_loaded) {
680 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine] engine id(%d) is already loaded", engine->engine_id);
686 ret = stt_engine_load(engine->engine_id, engine->engine_path);
688 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
689 return STTD_ERROR_OPERATION_FAILED;
692 ret = stt_engine_initialize(engine->engine_id, __result_cb, __detect_silence_cb);
694 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
695 return STTD_ERROR_OPERATION_FAILED;
698 ret = stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected);
700 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Not support silence detection");
701 engine->support_silence_detection = false;
703 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Silence detection : %s", g_default_silence_detected ? "true" : "false");
704 engine->support_silence_detection = true;
705 engine->silence_detection = g_default_silence_detected;
708 /* Set first language */
709 char* tmp_lang = NULL;
710 ret = stt_engine_get_first_language(engine->engine_id, &tmp_lang);
711 if (0 == ret && NULL != tmp_lang) {
712 engine->first_lang = strdup(tmp_lang);
715 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get first language from engine : %d %s", engine->engine_id, engine->engine_name);
716 return STTD_ERROR_OPERATION_FAILED;
719 #ifndef AUDIO_CREATE_ON_START
721 sttp_audio_type_e atype;
725 ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
727 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
728 return STTD_ERROR_OPERATION_FAILED;
731 ret = sttd_recorder_create(engine->engine_id, atype, channels, rate);
733 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
734 return STTD_ERROR_OPERATION_FAILED;
738 engine->is_loaded = true;
739 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s(%d) has been loaded !!!", engine->engine_name, engine->engine_id);
744 int sttd_engine_agent_unload_current_engine(int uid)
746 if (false == g_agent_init) {
747 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
748 return STTD_ERROR_OPERATION_FAILED;
755 sttengine_client_s *data = NULL;
757 if (0 < g_slist_length(g_engine_client_list)) {
758 iter = g_slist_nth(g_engine_client_list, 0);
760 while (NULL != iter) {
761 /* Get handle data from list */
765 if (uid == data->uid) {
766 g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
767 engine_id = data->engine_id;
773 iter = g_slist_next(iter);
777 if (-1 != engine_id) {
778 __engine_agent_check_engine_unload(engine_id);
784 bool sttd_engine_agent_is_default_engine()
786 if (g_default_engine_id > 0)
792 int sttd_engine_agent_get_engine_list(GSList** engine_list)
794 if (false == g_agent_init) {
795 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
796 return STTD_ERROR_OPERATION_FAILED;
800 sttengine_info_s *data = NULL;
802 iter = g_slist_nth(g_engine_list, 0);
804 SLOG(LOG_DEBUG, TAG_STTD, "----- [Engine Agent] engine list -----");
806 while (NULL != iter) {
807 engine_s* temp_engine;
809 temp_engine = (engine_s*)calloc(1, sizeof(engine_s));
813 temp_engine->engine_id = strdup(data->engine_uuid);
814 temp_engine->engine_name = strdup(data->engine_name);
815 temp_engine->ug_name = strdup(data->engine_setting_path);
817 *engine_list = g_slist_append(*engine_list, temp_engine);
819 iter = g_slist_next(iter);
821 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " -- Engine id(%s)", temp_engine->engine_id);
822 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " Engine name(%s)", temp_engine->engine_name);
823 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " Engine ug name(%s)", temp_engine->ug_name);
826 SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
831 int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
833 if (false == g_agent_init) {
834 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
835 return STTD_ERROR_OPERATION_FAILED;
838 if (NULL == engine_uuid) {
839 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid parameter" );
840 return STTD_ERROR_INVALID_PARAMETER;
843 sttengine_info_s* engine;
844 engine = __engine_agent_get_engine_by_uid(uid);
846 if (NULL == engine) {
847 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
848 return STTD_ERROR_INVALID_PARAMETER;
851 if (false == engine->is_loaded) {
852 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
853 return STTD_ERROR_OPERATION_FAILED;
856 *engine_uuid = strdup(engine->engine_uuid);
861 bool sttd_engine_agent_need_network(int uid)
863 if (false == g_agent_init) {
864 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
865 return STTD_ERROR_OPERATION_FAILED;
868 sttengine_info_s* engine;
869 engine = __engine_agent_get_engine_by_uid(uid);
872 return engine->use_network;
877 int sttd_engine_agent_supported_langs(int uid, GSList** lang_list)
879 if (false == g_agent_init) {
880 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
881 return STTD_ERROR_OPERATION_FAILED;
884 if (NULL == lang_list) {
885 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL");
886 return STTD_ERROR_INVALID_PARAMETER;
889 sttengine_info_s* engine = NULL;
890 engine = __engine_agent_get_engine_by_uid(uid);
892 if (NULL == engine) {
893 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
894 return STTD_ERROR_INVALID_PARAMETER;
897 if (false == engine->is_loaded) {
898 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
899 return STTD_ERROR_OPERATION_FAILED;
902 int ret = stt_engine_get_supported_langs(engine->engine_id, lang_list);
904 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
905 return STTD_ERROR_OPERATION_FAILED;
911 int sttd_engine_agent_get_default_lang(int uid, char** lang)
913 if (false == g_agent_init) {
914 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
915 return STTD_ERROR_OPERATION_FAILED;
919 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
920 return STTD_ERROR_INVALID_PARAMETER;
923 sttengine_info_s* engine = NULL;
924 engine = __engine_agent_get_engine_by_uid(uid);
926 if (NULL == engine) {
927 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
928 return STTD_ERROR_INVALID_PARAMETER;
931 if (false == engine->is_loaded) {
932 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
933 return STTD_ERROR_OPERATION_FAILED;
936 /* get default language */
937 bool is_valid = false;
938 if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
939 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
940 return STTD_ERROR_OPERATION_FAILED;
943 if (true == is_valid) {
944 *lang = strdup(g_default_language);
946 *lang = strdup(engine->first_lang);
951 int sttd_engine_agent_get_option_supported(int uid, bool* silence)
953 if (false == g_agent_init) {
954 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
955 return STTD_ERROR_OPERATION_FAILED;
958 if (NULL == silence) {
959 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
960 return STTD_ERROR_INVALID_PARAMETER;
963 sttengine_info_s* engine = NULL;
964 engine = __engine_agent_get_engine_by_uid(uid);
966 if (NULL == engine) {
967 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] uid(%d) is not valid", uid);
968 return STTD_ERROR_INVALID_PARAMETER;
971 if (false == engine->is_loaded) {
972 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
973 return STTD_ERROR_OPERATION_FAILED;
976 *silence = engine->support_silence_detection;
981 int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support)
983 if (false == g_agent_init) {
984 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
985 return STTD_ERROR_OPERATION_FAILED;
988 if (NULL == type || NULL == support) {
989 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
990 return STTD_ERROR_INVALID_PARAMETER;
993 sttengine_info_s* engine = NULL;
994 engine = __engine_agent_get_engine_by_uid(uid);
996 if (NULL == engine) {
997 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
998 return STTD_ERROR_INVALID_PARAMETER;
1001 if (false == engine->is_loaded) {
1002 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1003 return STTD_ERROR_OPERATION_FAILED;
1009 ret = stt_engine_support_recognition_type(engine->engine_id, type, &temp);
1011 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
1012 return STTD_ERROR_OPERATION_FAILED;
1021 * STT Engine Interfaces for client
1024 int __set_option(sttengine_info_s* engine, int silence)
1029 /* Check silence detection */
1030 if (engine->support_silence_detection) {
1032 /* default option set */
1033 if (g_default_silence_detected != engine->silence_detection) {
1034 if (0 != stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected)) {
1035 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", g_default_silence_detected ? "true" : "false");
1037 engine->silence_detection = g_default_silence_detected;
1038 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_default_silence_detected ? "true" : "false");
1042 if (silence != engine->silence_detection) {
1043 if (0 != stt_engine_set_silence_detection(engine->engine_id, silence)) {
1044 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", silence ? "true" : "false");
1046 engine->silence_detection = silence;
1047 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", silence ? "true" : "false");
1056 int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
1057 int silence, void* user_param)
1059 if (false == g_agent_init) {
1060 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1061 return STTD_ERROR_OPERATION_FAILED;
1064 if (NULL == lang || NULL == recognition_type) {
1065 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1066 return STTD_ERROR_INVALID_PARAMETER;
1069 sttengine_info_s* engine = NULL;
1070 engine = __engine_agent_get_engine_by_uid(uid);
1072 if (NULL == engine) {
1073 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1074 return STTD_ERROR_INVALID_PARAMETER;
1077 if (false == engine->is_loaded) {
1078 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1079 return STTD_ERROR_OPERATION_FAILED;
1082 if (0 != __set_option(engine, silence)) {
1083 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options");
1084 return STTD_ERROR_OPERATION_FAILED;
1087 SLOG(LOG_DEBUG, TAG_STTD, "g_default_language %s", g_default_language);
1091 if (0 == strncmp(lang, "default", strlen("default"))) {
1092 bool is_valid = false;
1093 if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
1094 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
1095 return STTD_ERROR_OPERATION_FAILED;
1098 if (true == is_valid) {
1099 temp = strdup(g_default_language);
1100 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is %s", temp);
1102 temp = strdup(engine->first_lang);
1103 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is engine first lang : %s", temp);
1106 temp = strdup(lang);
1109 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start engine");
1111 ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, user_param);
1112 if (NULL != temp) free(temp);
1114 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Recognition start error(%d)", ret);
1115 sttd_recorder_destroy(engine->engine_id);
1116 return STTD_ERROR_OPERATION_FAILED;
1119 #ifdef AUDIO_CREATE_ON_START
1120 /* Ready recorder */
1121 sttp_audio_type_e atype;
1125 ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
1127 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
1128 return STTD_ERROR_OPERATION_FAILED;
1131 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Create recorder");
1133 ret = sttd_recorder_create(engine->engine_id, atype, channels, rate);
1135 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
1136 return STTD_ERROR_OPERATION_FAILED;
1141 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
1143 ret = sttd_recorder_start(engine->engine_id);
1145 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
1149 g_recording_engine_id = engine->engine_id;
1150 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
1156 int sttd_engine_agent_recognize_start_recorder(int uid)
1158 sttengine_info_s* engine = NULL;
1159 engine = __engine_agent_get_engine_by_uid(uid);
1161 if (NULL == engine) {
1162 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1163 return STTD_ERROR_INVALID_PARAMETER;
1166 if (false == engine->is_loaded) {
1167 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1168 return STTD_ERROR_OPERATION_FAILED;
1171 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
1174 ret = sttd_recorder_start(engine->engine_id);
1176 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
1177 stt_engine_recognize_cancel(engine->engine_id);
1178 sttd_recorder_stop(engine->engine_id);
1182 g_recording_engine_id = engine->engine_id;
1183 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
1188 int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int length)
1190 if (false == g_agent_init) {
1191 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1192 return STTD_ERROR_OPERATION_FAILED;
1195 if (NULL == data || 0 == length) {
1196 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1197 return STTD_ERROR_INVALID_PARAMETER;
1200 sttengine_info_s* engine = NULL;
1201 engine = __engine_agent_get_engine_by_uid(uid);
1203 if (NULL == engine) {
1204 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1205 return STTD_ERROR_INVALID_PARAMETER;
1208 if (false == engine->is_loaded) {
1209 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1210 return STTD_ERROR_OPERATION_FAILED;
1213 int ret = stt_engine_set_recording_data(engine->engine_id, data, length);
1215 SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
1216 return STTD_ERROR_OPERATION_FAILED;
1222 int sttd_engine_agent_recognize_stop_recorder(int uid)
1224 if (false == g_agent_init) {
1225 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1226 return STTD_ERROR_OPERATION_FAILED;
1229 sttengine_info_s* engine = NULL;
1230 engine = __engine_agent_get_engine_by_uid(uid);
1232 if (NULL == engine) {
1233 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1234 return STTD_ERROR_INVALID_PARAMETER;
1237 if (false == engine->is_loaded) {
1238 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1239 return STTD_ERROR_OPERATION_FAILED;
1242 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
1244 ret = sttd_recorder_stop(engine->engine_id);
1246 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
1247 return STTD_ERROR_OPERATION_FAILED;
1250 #ifdef AUDIO_CREATE_ON_START
1251 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1252 if (0 != sttd_recorder_destroy(engine->engine_id))
1253 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
1256 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop recorder");
1260 int sttd_engine_agent_recognize_stop_engine(int uid)
1262 if (false == g_agent_init) {
1263 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1264 return STTD_ERROR_OPERATION_FAILED;
1267 sttengine_info_s* engine = NULL;
1268 engine = __engine_agent_get_engine_by_uid(uid);
1270 if (NULL == engine) {
1271 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1272 return STTD_ERROR_INVALID_PARAMETER;
1275 if (false == engine->is_loaded) {
1276 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1277 return STTD_ERROR_OPERATION_FAILED;
1280 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop engine");
1283 ret = stt_engine_recognize_stop(engine->engine_id);
1285 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
1286 return STTD_ERROR_OPERATION_FAILED;
1289 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop engine");
1294 int sttd_engine_agent_recognize_cancel(int uid)
1296 if (false == g_agent_init) {
1297 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1298 return STTD_ERROR_OPERATION_FAILED;
1301 sttengine_info_s* engine = NULL;
1302 engine = __engine_agent_get_engine_by_uid(uid);
1304 if (NULL == engine) {
1305 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1306 return STTD_ERROR_INVALID_PARAMETER;
1309 if (false == engine->is_loaded) {
1310 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1311 return STTD_ERROR_OPERATION_FAILED;
1314 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Cancel engine");
1317 ret = stt_engine_recognize_cancel(engine->engine_id);
1319 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
1320 return STTD_ERROR_OPERATION_FAILED;
1323 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
1325 ret = sttd_recorder_stop(engine->engine_id);
1327 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
1328 return STTD_ERROR_OPERATION_FAILED;
1331 #ifdef AUDIO_CREATE_ON_START
1332 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1333 if (0 != sttd_recorder_destroy(engine->engine_id))
1334 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
1337 g_recording_engine_id = -1;
1339 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Cancel recognition");
1346 * STT Engine Interfaces for configure
1349 int sttd_engine_agent_set_default_engine(const char* engine_uuid)
1351 if (false == g_agent_init) {
1352 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1353 return STTD_ERROR_OPERATION_FAILED;
1356 if (NULL == engine_uuid) {
1357 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1358 return STTD_ERROR_INVALID_PARAMETER;
1363 sttengine_info_s* engine;
1364 engine = __engine_agent_get_engine_by_uuid(engine_uuid);
1365 if (NULL == engine) {
1366 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is not valid");
1367 return STTD_ERROR_ENGINE_NOT_FOUND;
1370 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine id(%d) engine uuid(%s)", engine->engine_id, engine->engine_uuid);
1372 g_default_engine_id = engine->engine_id;
1374 /* Update default engine of client */
1375 GSList *iter = NULL;
1376 sttengine_client_s *data = NULL;
1378 if (0 < g_slist_length(g_engine_client_list)) {
1379 iter = g_slist_nth(g_engine_client_list, 0);
1381 while (NULL != iter) {
1382 /* Get handle data from list */
1385 if (true == data->use_default_engine) {
1386 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] uid(%d) change engine from id(%d) to id(%d)",
1387 data->uid, data->engine_id, engine->engine_id);
1389 if (0 != sttd_engine_agent_load_current_engine(data->uid, NULL)) {
1390 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load current engine : uid(%d)", data->uid);
1394 iter = g_slist_next(iter);
1401 int sttd_engine_agent_set_default_language(const char* language)
1403 if (false == g_agent_init) {
1404 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1405 return STTD_ERROR_OPERATION_FAILED;
1408 if (NULL == language) {
1409 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
1410 return STTD_ERROR_INVALID_PARAMETER;
1413 if (NULL != g_default_language)
1414 free(g_default_language);
1416 g_default_language = strdup(language);
1421 int sttd_engine_agent_set_silence_detection(bool value)
1423 if (false == g_agent_init) {
1424 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1425 return STTD_ERROR_OPERATION_FAILED;
1428 g_default_silence_detected = value;
1433 int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result)
1435 if (false == g_agent_init) {
1436 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
1437 return STTD_ERROR_OPERATION_FAILED;
1440 sttengine_info_s* engine = NULL;
1441 engine = __engine_agent_get_engine_by_uid(uid);
1443 if (NULL == engine) {
1444 SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
1445 return STTD_ERROR_INVALID_PARAMETER;
1448 if (false == engine->is_loaded) {
1449 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
1450 return STTD_ERROR_OPERATION_FAILED;
1454 ret = stt_engine_check_app_agreed(engine->engine_id, appid, result);
1456 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
1457 return STTD_ERROR_OPERATION_FAILED;
1461 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Get engine right : %s", *result ? "true" : "false");
1466 * STT Engine Callback Functions ` *
1469 void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
1470 const char* msg, void* time_info, void *user_data)
1472 if (false == g_agent_init) {
1473 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized");
1477 SLOG(LOG_DEBUG, TAG_STTD, "[Server] === Result time callback ===");
1479 if (NULL != time_info) {
1480 /* Get the time info */
1481 int ret = stt_engine_foreach_result_time(g_recording_engine_id, time_info, __result_time_cb, NULL);
1483 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get time info : %d", ret);
1487 SLOG(LOG_DEBUG, TAG_STTD, "[Server] ============================");
1489 g_result_cb(event, type, data, data_count, msg, user_data);
1491 #ifdef AUDIO_CREATE_ON_START
1492 if (event == STTP_RESULT_EVENT_ERROR) {
1493 SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
1494 if (0 != sttd_recorder_destroy(g_recording_engine_id))
1495 SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", g_recording_engine_id);
1499 if (event == STTP_RESULT_EVENT_FINAL_RESULT || event == STTP_RESULT_EVENT_ERROR) {
1500 g_recording_engine_id = -1;
1506 bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
1508 return g_result_time_cb(index, event, text, start_time, end_time, user_data);
1511 void __detect_silence_cb(sttp_silence_type_e type, void* user_data)
1513 if (false == g_agent_init) {
1514 SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
1518 g_silence_cb(type, user_data);
1522 /* A function forging */
1523 int __log_enginelist()
1525 GSList *iter = NULL;
1526 sttengine_info_s *data = NULL;
1528 if (0 < g_slist_length(g_engine_list)) {
1530 /* Get a first item */
1531 iter = g_slist_nth(g_engine_list, 0);
1533 SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
1536 while (NULL != iter) {
1537 /* Get handle data from list */
1540 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[%dth]", i);
1541 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine uuid : %s", data->engine_uuid);
1542 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine name : %s", data->engine_name);
1543 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine path : %s", data->engine_path);
1544 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " use network : %s", data->use_network ? "true" : "false");
1545 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " is loaded : %s", data->is_loaded ? "true" : "false");
1546 if (NULL != data->first_lang)
1547 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " default lang : %s", data->first_lang);
1549 iter = g_slist_next(iter);
1552 SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
1554 SLOG(LOG_DEBUG, TAG_STTD, "-------------- engine list -------------------");
1555 SLOG(LOG_DEBUG, TAG_STTD, " No Engine in engine directory");
1556 SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");