/*
-* 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
char* first_lang;
bool silence_detection;
bool support_silence_detection;
+ bool need_credential;
} sttengine_info_s;
/** stt engine agent init */
/** 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);
/*
/*
* 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 */
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;
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;
}
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");
- }
-
if (0 >= g_slist_length(g_engine_list)) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
return STTD_ERROR_ENGINE_NOT_FOUND;
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);
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
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
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;
}
- return 0;
+ return ret;
}
int sttd_engine_agent_get_default_lang(int uid, char** lang)
/* 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) {
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) {
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) {
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;
+ return ret;
}
*support = temp;
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");
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) {
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
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
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;
}
- return 0;
+ return ret;
}
int sttd_engine_agent_recognize_stop_recorder(int uid)
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;
+ return ret;
}
#ifdef AUDIO_CREATE_ON_START
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;
+ return ret;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop engine");
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;
+ 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;
+ return ret;
}
#ifdef AUDIO_CREATE_ON_START
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);
}
}
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;
}
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;
+ return ret;
}
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) {
#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;
}
}
return 0;
-}
\ No newline at end of file
+}