Fix bugs
[platform/core/uifw/stt.git] / server / sttd_engine_agent.c
index c4ac20b..a00e33e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -46,11 +46,12 @@ typedef struct _sttengine_info {
        bool    use_network;
 
        bool    is_loaded;
-       
+
        /* engine base setting */
        char*   first_lang;
        bool    silence_detection;
        bool    support_silence_detection;
+       bool    need_credential;
 } sttengine_info_s;
 
 /** stt engine agent init */
@@ -77,23 +78,23 @@ static silence_dectection_callback g_silence_cb;
 
 
 /** callback functions */
-void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count, 
+void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
                 const char* msg, void* time_info, void *user_data);
 
-bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text, 
+bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text,
                      long start_time, long end_time, void* user_data);
 
 void __detect_silence_cb(sttp_silence_type_e type, void* user_data);
 
 bool __supported_language_cb(const char* language, void* user_data);
 
-void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
                      bool use_network, void* user_data);
 
 /*
-* Internal Interfaces 
+* Internal Interfaces
 */
+
 /** get engine info */
 int __internal_get_engine_info(const char* filepath, sttengine_info_s** info);
 
@@ -102,12 +103,12 @@ int __log_enginelist();
 /*
 * STT Engine Agent Interfaces
 */
-int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb, 
+int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb,
                           silence_dectection_callback silence_cb)
 {
        /* initialize static data */
        if (NULL == result_cb || NULL == time_cb || NULL == silence_cb) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] Invalid parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] Invalid parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -121,7 +122,7 @@ int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_
        g_recording_engine_id = -1;
 
        if (0 != sttd_config_get_default_language(&(g_default_language))) {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is No default voice in config"); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is No default voice in config");
                /* Set default voice */
                g_default_language = strdup("en_US");
        } else {
@@ -130,7 +131,7 @@ int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_
 
        int temp;
        if (0 != sttd_config_get_default_silence_detection(&temp)) {
-               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config"); 
+               SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config");
                g_default_silence_detected = true;
        } else {
                g_default_silence_detected = (bool)temp;
@@ -171,7 +172,7 @@ int sttd_engine_agent_release()
                        client = iter->data;
                        g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
 
-                       if (NULL != client) 
+                       if (NULL != client)
                                free(client);
 
                        iter = g_slist_nth(g_engine_client_list, 0);
@@ -191,12 +192,12 @@ int sttd_engine_agent_release()
                        /* Get handle data from list */
                        engine = iter->data;
                        g_engine_list = g_slist_remove_link(g_engine_list, iter);
-                       
+
                        /* Check engine unload */
                        if (engine->is_loaded) {
                                SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", engine->engine_id);
 
-                               if (0 != stt_engine_deinitialize(engine->engine_id)) 
+                               if (0 != stt_engine_deinitialize(engine->engine_id))
                                        SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id);
 
                                if (0 != stt_engine_unload(engine->engine_id))
@@ -220,10 +221,10 @@ int sttd_engine_agent_release()
        return 0;
 }
 
-void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name, 
+void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
                      bool use_network, void* user_data)
 {
-       sttengine_info_s* temp = (sttengine_info_s*)user_data; 
+       sttengine_info_s* temp = (sttengine_info_s*)user_data;
 
        temp->engine_uuid = g_strdup(engine_uuid);
        temp->engine_name = g_strdup(engine_name);
@@ -234,7 +235,7 @@ void __engine_info_cb(const char* engine_uuid, const char* engine_name, const ch
 int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
 {
        if (NULL == filepath || NULL == info) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -242,24 +243,24 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
        char *error;
        void* handle;
 
-       handle = dlopen (filepath, RTLD_LAZY);
+       handle = dlopen(filepath, RTLD_LAZY);
 
        if (!handle) {
-               SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath);
+               SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s, error(%s)", filepath, (NULL == dlerror()) ? "NULL" : dlerror());
                return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        /* link engine to daemon */
        dlsym(handle, "sttp_load_engine");
        if ((error = dlerror()) != NULL) {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error);
                dlclose(handle);
                return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        dlsym(handle, "sttp_unload_engine");
        if ((error = dlerror()) != NULL) {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine. Fail to open sttp_unload_engine : %s", error);
                dlclose(handle);
                return STTD_ERROR_ENGINE_NOT_FOUND;
        }
@@ -268,7 +269,7 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
 
        get_engine_info = (int (*)(sttpe_engine_info_cb, void*))dlsym(handle, "sttp_get_engine_info");
        if ((error = dlerror()) != NULL || NULL == get_engine_info) {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error);
                dlclose(handle);
                return STTD_ERROR_ENGINE_NOT_FOUND;
        }
@@ -283,7 +284,7 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
 
        /* get engine info */
        if (0 != get_engine_info(__engine_info_cb, (void*)temp)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info from engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info from engine");
                dlclose(handle);
                free(temp);
                return STTD_ERROR_ENGINE_NOT_FOUND;
@@ -304,7 +305,7 @@ int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
        SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", temp->engine_name);
        SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", temp->engine_path);
        SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine setting path : %s", temp->engine_setting_path);
-       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true":"false");
+       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true" : "false");
        SLOG(LOG_DEBUG, TAG_STTD, "-----");
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
 
@@ -329,7 +330,7 @@ bool __is_engine(const char* filepath)
                        if (0 == strcmp(engine->engine_path, filepath)) {
                                return true;
                        }
-               
+
                        iter = g_slist_next(iter);
                }
        }
@@ -384,53 +385,12 @@ int sttd_engine_agent_initialize_engine_list()
 
                closedir(dp);
        } else {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory"); 
-       }
-
-       /* Get file name from downloadable engine directory */
-       dp  = opendir(STT_DOWNLOAD_ENGINE);
-       if (NULL != dp) {
-               do {
-                       ret = readdir_r(dp, &entry, &dirp);
-                       if (0 != ret) {
-                               SLOG(LOG_ERROR, TAG_STTD, "[File ERROR] Fail to read directory");
-                               break;
-                       }
-
-                       if (NULL != dirp) {
-                               sttengine_info_s* info;
-                               char* filepath;
-                               int filesize;
-
-                               filesize = strlen(STT_DOWNLOAD_ENGINE) + strlen(dirp->d_name) + 5;
-                               filepath = (char*)calloc(filesize, sizeof(char));
-
-                               if (NULL != filepath) {
-                                       snprintf(filepath, filesize, "%s/%s", STT_DOWNLOAD_ENGINE, dirp->d_name);
-                               } else {
-                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enouth!!");
-                                       continue;
-                               }
-
-                               /* get its info and update engine list */
-                               if (0 == __internal_get_engine_info(filepath, &info)) {
-                                       /* add engine info to g_engine_list */
-                                       g_engine_list = g_slist_append(g_engine_list, info);
-                               }
-
-                               if (NULL != filepath)
-                                       free(filepath);
-                       }
-               } while (NULL != dirp);
-
-               closedir(dp);
-       } else {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open downloadable directory"); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory");
        }
 
        if (0 >= g_slist_length(g_engine_list)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine"); 
-               return STTD_ERROR_ENGINE_NOT_FOUND;     
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
+               return STTD_ERROR_ENGINE_NOT_FOUND;
        }
 
        __log_enginelist();
@@ -463,10 +423,10 @@ int sttd_engine_agent_initialize_engine_list()
                        }
                }
 
-               if (cur_engine_uuid != NULL )
+               if (cur_engine_uuid != NULL)
                        free(cur_engine_uuid);
        } else {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is not current engine from config"); 
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is not current engine from config");
        }
 
        if (false == is_default_engine) {
@@ -490,7 +450,7 @@ int sttd_engine_agent_initialize_engine_list()
 
                        if (false == is_default_engine) {
                                if (0 != sttd_config_set_default_engine(engine->engine_uuid))
-                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine "); 
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine ");
                        }
                }
        } else {
@@ -514,7 +474,7 @@ sttengine_info_s* __engine_agent_get_engine_by_id(int engine_id)
 
                data = iter->data;
 
-               if (data->engine_id == engine_id) 
+               if (data->engine_id == engine_id)
                        return data;
 
                iter = g_slist_next(iter);
@@ -534,7 +494,7 @@ sttengine_info_s* __engine_agent_get_engine_by_uuid(const char* engine_uuid)
 
                data = iter->data;
 
-               if (0 == strcmp(data->engine_uuid, engine_uuid)) 
+               if (0 == strcmp(data->engine_uuid, engine_uuid))
                        return data;
 
                iter = g_slist_next(iter);
@@ -555,7 +515,7 @@ sttengine_client_s* __engine_agent_get_client(int uid)
                        /* Get handle data from list */
                        data = iter->data;
 
-                       if (uid == data->uid) 
+                       if (uid == data->uid)
                                return data;
 
                        iter = g_slist_next(iter);
@@ -570,7 +530,7 @@ sttengine_info_s* __engine_agent_get_engine_by_uid(int uid)
        sttengine_client_s *data;
 
        data = __engine_agent_get_client(uid);
-       if (NULL != data) 
+       if (NULL != data)
                return __engine_agent_get_engine_by_id(data->engine_id);
 
        return NULL;
@@ -582,7 +542,7 @@ int __engine_agent_check_engine_unload(int engine_id)
        GSList *iter = NULL;
        int client_count = 0;
        sttengine_client_s *data = NULL;
-       
+
        if (0 < g_slist_length(g_engine_client_list)) {
                iter = g_slist_nth(g_engine_client_list, 0);
 
@@ -628,7 +588,7 @@ int __engine_agent_check_engine_unload(int engine_id)
 int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -637,7 +597,7 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
        int before_engine = -1;
 
        client = __engine_agent_get_client(uid);
-       
+
        if (NULL == client) {
                client = (sttengine_client_s*)calloc(1, sizeof(sttengine_client_s));
                if (NULL == client) {
@@ -648,11 +608,11 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
                /* initialize */
                client->uid = uid;
                client->engine_id = -1;
-       
+
                g_engine_client_list = g_slist_append(g_engine_client_list, client);
 
                SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Registered client(%d)", uid);
-       } 
+       }
 
        if (NULL == engine_uuid) {
                /* Set default engine */
@@ -695,13 +655,13 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
        ret = stt_engine_load(engine->engine_id, engine->engine_path);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        ret = stt_engine_initialize(engine->engine_id, __result_cb, __detect_silence_cb);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        ret = stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected);
@@ -722,7 +682,7 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
                free(tmp_lang);
        } else {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get first language from engine : %d %s", engine->engine_id, engine->engine_name);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
 #ifndef AUDIO_CREATE_ON_START
@@ -734,18 +694,18 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
        ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
-       ret = sttd_recorder_create(engine->engine_id, atype, channels, rate);
+       ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 #endif
 
        engine->is_loaded = true;
-       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s(%d) has been loaded !!!", engine->engine_name, engine->engine_id); 
+       SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s(%d) has been loaded !!!", engine->engine_name, engine->engine_id);
 
        return 0;
 }
@@ -753,7 +713,7 @@ int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid)
 int sttd_engine_agent_unload_current_engine(int uid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized "); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -792,7 +752,7 @@ int sttd_engine_agent_unload_current_engine(int uid)
 
 bool sttd_engine_agent_is_default_engine()
 {
-       if (g_default_engine_id > 0) 
+       if (g_default_engine_id > 0)
                return true;
 
        return false;
@@ -801,7 +761,7 @@ bool sttd_engine_agent_is_default_engine()
 int sttd_engine_agent_get_engine_list(GSList** engine_list)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -831,7 +791,7 @@ int sttd_engine_agent_get_engine_list(GSList** engine_list)
 
                iter = g_slist_next(iter);
 
-               SECURE_SLOG(LOG_DEBUG, TAG_STTD, " -- Engine id(%s)", temp_engine->engine_id); 
+               SECURE_SLOG(LOG_DEBUG, TAG_STTD, " -- Engine id(%s)", temp_engine->engine_id);
                SECURE_SLOG(LOG_DEBUG, TAG_STTD, "    Engine name(%s)", temp_engine->engine_name);
                SECURE_SLOG(LOG_DEBUG, TAG_STTD, "    Engine ug name(%s)", temp_engine->ug_name);
        }
@@ -844,12 +804,12 @@ int sttd_engine_agent_get_engine_list(GSList** engine_list)
 int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == engine_uuid) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid parameter" );
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -862,7 +822,7 @@ int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -874,13 +834,13 @@ int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
 bool sttd_engine_agent_need_network(int uid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        sttengine_info_s* engine;
        engine = __engine_agent_get_engine_by_uid(uid);
-       
+
        if (NULL != engine)
                return engine->use_network;
 
@@ -908,28 +868,27 @@ int sttd_engine_agent_supported_langs(int uid, GSList** lang_list)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        int ret = stt_engine_get_supported_langs(engine->engine_id, lang_list);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
        }
 
-       return 0;
+       return ret;
 }
 
 int sttd_engine_agent_get_default_lang(int uid, char** lang)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == lang) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -942,25 +901,97 @@ int sttd_engine_agent_get_default_lang(int uid, char** lang)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        /* get default language */
        bool is_valid = false;
-       if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
+       int ret = -1;
+       ret = stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid);
+       if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        if (true == is_valid) {
                *lang = strdup(g_default_language);
-       } else 
+       } else
                *lang = strdup(engine->first_lang);
 
        return 0;
 }
 
+int sttd_engine_agent_set_private_data(int uid, const char* key, const char* data)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == key || NULL == data) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       sttengine_info_s* engine = NULL;
+       engine = __engine_agent_get_engine_by_uid(uid);
+
+       if (NULL == engine) {
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (false == engine->is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* set private data */
+       int ret = -1;
+       ret = stt_engine_set_private_data(engine->engine_id, key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set private data");
+       }
+
+       return ret;
+}
+
+int sttd_engine_agent_get_private_data(int uid, const char* key, char** data)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == key || NULL == data) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       sttengine_info_s* engine = NULL;
+       engine = __engine_agent_get_engine_by_uid(uid);
+
+       if (NULL == engine) {
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of uid(%d) is not valid", uid);
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (false == engine->is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       /* get default language */
+       int ret = -1;
+       ret = stt_engine_get_private_data(engine->engine_id, key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get private data");
+       }
+
+       return ret;
+}
+
 int sttd_engine_agent_get_option_supported(int uid, bool* silence)
 {
        if (false == g_agent_init) {
@@ -969,7 +1000,7 @@ int sttd_engine_agent_get_option_supported(int uid, bool* silence)
        }
 
        if (NULL == silence) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -982,7 +1013,7 @@ int sttd_engine_agent_get_option_supported(int uid, bool* silence)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -991,15 +1022,53 @@ int sttd_engine_agent_get_option_supported(int uid, bool* silence)
        return 0;
 }
 
+int sttd_engine_agent_is_credential_needed(int uid, bool* credential)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       if (NULL == credential) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       sttengine_info_s* engine = NULL;
+       engine = __engine_agent_get_engine_by_uid(uid);
+
+       if (NULL == engine) {
+               SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] uid(%d) is not valid", uid);
+               return STTD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (false == engine->is_loaded) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+               return STTD_ERROR_OPERATION_FAILED;
+       }
+
+       bool temp = false;
+       int ret;
+
+       ret = stt_engine_need_app_credential(engine->engine_id, &temp);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
+               return ret;
+       }
+
+       *credential = temp;
+       return 0;
+}
+
 int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == type || NULL == support) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1012,7 +1081,7 @@ int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, b
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1021,8 +1090,8 @@ int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, b
 
        ret = stt_engine_support_recognition_type(engine->engine_id, type, &temp);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
+               return ret;
        }
 
        *support = temp;
@@ -1062,20 +1131,20 @@ int __set_option(sttengine_info_s* engine, int silence)
                        }
                }
        }
-       
+
        return 0;
 }
 
-int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type, 
-                                     int silence, void* user_param)
+int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
+                                     int silence, const char* credential, void* user_param)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
-       
+
        if (NULL == lang || NULL == recognition_type) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1088,12 +1157,12 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (0 != __set_option(engine, silence)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1103,9 +1172,10 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
        char* temp = NULL;
        if (0 == strncmp(lang, "default", strlen("default"))) {
                bool is_valid = false;
-               if (0 != stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid)) {
+               ret = stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid);
+               if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
-                       return STTD_ERROR_OPERATION_FAILED;
+                       return ret;
                }
 
                if (true == is_valid) {
@@ -1121,12 +1191,12 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start engine");
 
-       ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, user_param);
+       ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, credential, user_param);
        if (NULL != temp)       free(temp);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Recognition start error(%d)", ret);
                sttd_recorder_destroy(engine->engine_id);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
 #ifdef AUDIO_CREATE_ON_START
@@ -1138,15 +1208,15 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
        ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", engine->engine_id, engine->engine_name);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Create recorder");
 
-       ret = sttd_recorder_create(engine->engine_id, atype, channels, rate);
+       ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
        if (0 != ret) {
                SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %d %s", engine->engine_id, engine->engine_name);
-               return STTD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 #endif
 
@@ -1160,7 +1230,7 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch
        }
 
        g_recording_engine_id = engine->engine_id;
-       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id); 
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
 #endif
 
        return 0;
@@ -1177,7 +1247,7 @@ int sttd_engine_agent_recognize_start_recorder(int uid)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1193,7 +1263,7 @@ int sttd_engine_agent_recognize_start_recorder(int uid)
        }
 
        g_recording_engine_id = engine->engine_id;
-       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id); 
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
 
        return 0;
 }
@@ -1201,12 +1271,12 @@ int sttd_engine_agent_recognize_start_recorder(int uid)
 int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int length)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == data || 0 == length) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1219,23 +1289,22 @@ int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        int ret = stt_engine_set_recording_data(engine->engine_id, data, length);
        if (0 != ret) {
-               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
        }
 
-       return 0;
+       return ret;
 }
 
 int sttd_engine_agent_recognize_stop_recorder(int uid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1248,7 +1317,7 @@ int sttd_engine_agent_recognize_stop_recorder(int uid)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1256,8 +1325,8 @@ int sttd_engine_agent_recognize_stop_recorder(int uid)
        int ret;
        ret = sttd_recorder_stop(engine->engine_id);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
+               return ret;
        }
 
 #ifdef AUDIO_CREATE_ON_START
@@ -1273,7 +1342,7 @@ int sttd_engine_agent_recognize_stop_recorder(int uid)
 int sttd_engine_agent_recognize_stop_engine(int uid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1286,7 +1355,7 @@ int sttd_engine_agent_recognize_stop_engine(int uid)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1295,8 +1364,8 @@ int sttd_engine_agent_recognize_stop_engine(int uid)
        int ret;
        ret = stt_engine_recognize_stop(engine->engine_id);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop engine");
@@ -1307,7 +1376,7 @@ int sttd_engine_agent_recognize_stop_engine(int uid)
 int sttd_engine_agent_recognize_cancel(int uid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1320,7 +1389,7 @@ int sttd_engine_agent_recognize_cancel(int uid)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1329,16 +1398,16 @@ int sttd_engine_agent_recognize_cancel(int uid)
        int ret;
        ret = stt_engine_recognize_cancel(engine->engine_id);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
+               return ret;
        }
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
 
        ret = sttd_recorder_stop(engine->engine_id);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
+               return ret;
        }
 
 #ifdef AUDIO_CREATE_ON_START
@@ -1362,12 +1431,12 @@ int sttd_engine_agent_recognize_cancel(int uid)
 int sttd_engine_agent_set_default_engine(const char* engine_uuid)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == engine_uuid) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1396,11 +1465,11 @@ int sttd_engine_agent_set_default_engine(const char* engine_uuid)
                        data = iter->data;
 
                        if (true == data->use_default_engine) {
-                               SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] uid(%d) change engine from id(%d) to id(%d)", 
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] uid(%d) change engine from id(%d) to id(%d)",
                                        data->uid, data->engine_id, engine->engine_id);
 
                                if (0 != sttd_engine_agent_load_current_engine(data->uid, NULL)) {
-                                       SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load current engine : uid(%d)", data->uid);
+                                       SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load current engine : uid(%d)", data->uid);
                                }
                        }
 
@@ -1414,12 +1483,12 @@ int sttd_engine_agent_set_default_engine(const char* engine_uuid)
 int sttd_engine_agent_set_default_language(const char* language)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL == language) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1434,7 +1503,7 @@ int sttd_engine_agent_set_default_language(const char* language)
 int sttd_engine_agent_set_silence_detection(bool value)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1446,7 +1515,7 @@ int sttd_engine_agent_set_silence_detection(bool value)
 int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
@@ -1459,27 +1528,43 @@ int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result)
        }
 
        if (false == engine->is_loaded) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
                return STTD_ERROR_OPERATION_FAILED;
        }
 
        int ret;
        ret = stt_engine_check_app_agreed(engine->engine_id, appid, result);
        if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret); 
-               return STTD_ERROR_OPERATION_FAILED;
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
+               return ret;
        }
 
-       
+
        SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Get engine right : %s", *result ? "true" : "false");
        return 0;
 }
 
+static void __recorder_destroy(void* data)
+{
+       sttp_result_event_e event = (sttp_result_event_e)data;
+
+       SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder by ecore_thread_safe func");
+
+       if (0 != sttd_recorder_destroy(g_recording_engine_id)) {
+               SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", g_recording_engine_id);
+       }
+       
+       if (event == STTP_RESULT_EVENT_FINAL_RESULT || event == STTP_RESULT_EVENT_ERROR) {
+               g_recording_engine_id = -1;
+       }
+}
+
+
 /*
 * STT Engine Callback Functions                                                                                        `                                 *
 */
 
-void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count, 
+void __result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
                 const char* msg, void* time_info, void *user_data)
 {
        if (false == g_agent_init) {
@@ -1503,16 +1588,21 @@ void __result_cb(sttp_result_event_e event, const char* type, const char** data,
 
 #ifdef AUDIO_CREATE_ON_START
        if (event == STTP_RESULT_EVENT_ERROR) {
+#if 1
+               ecore_main_loop_thread_safe_call_async(__recorder_destroy, (void*)event);
+#else
                SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
                if (0 != sttd_recorder_destroy(g_recording_engine_id))
                        SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", g_recording_engine_id);
+#endif
        }
 #endif
 
+#ifndef AUDIO_CREATE_ON_START
        if (event == STTP_RESULT_EVENT_FINAL_RESULT || event == STTP_RESULT_EVENT_ERROR) {
                g_recording_engine_id = -1;
        }
-
+#endif
        return;
 }
 
@@ -1524,7 +1614,7 @@ bool __result_time_cb(int index, sttp_result_time_event_e event, const char* tex
 void __detect_silence_cb(sttp_silence_type_e type, void* user_data)
 {
        if (false == g_agent_init) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized"); 
+               SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
                return;
        }
 
@@ -1545,7 +1635,7 @@ int __log_enginelist()
 
                SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
 
-               int i = 1;      
+               int i = 1;
                while (NULL != iter) {
                        /* Get handle data from list */
                        data = iter->data;
@@ -1570,4 +1660,4 @@ int __log_enginelist()
        }
 
        return 0;
-}
\ No newline at end of file
+}