SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXEC_PREFIX "${PREFIX}")
-SET(VERSION 0.2.55)
+SET(VERSION 0.2.56)
ADD_DEFINITIONS("-DSTT_LIBDIR=\"${LIBDIR}\"")
ADD_DEFINITIONS("-Werror")
+stt (0.2.56) -- Fri, 1 July 2016
+
+ * Change engine lib to engine process. Daemon will be used as library (Kwangyoun Kim <ky85.kim@samsung.com>)
+
stt (0.2.55) -- Wed, 18 May 2016
* Add to get error message function and to set credential fucntion (Wonnam Jang <wn.jang@samsung.com>)
../common/stt_config_parser.c
../common/stt_engine.c
../common/stt_network.c
+ ../server/sttd_client_data.c
+ ../server/sttd_config.c
+ ../server/sttd_dbus.c
+ ../server/sttd_dbus_server.c
+ ../server/sttd_engine_agent.c
+ ../server/sttd_recorder.c
+ ../server/sttd_server.c
)
set(SETTING_SRCS
char *session = cynara_session_from_pid(pid);
int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
- if (session)
- free(session);
+ if (session) {
+ free(session);
+ session = NULL;
+ }
if (ret != CYNARA_API_ACCESS_ALLOWED)
return false;
if (NULL != client->engine_changed_cb) {
client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
} else {
- SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages");
+ SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
}
return;
}
return STT_ERROR_INVALID_STATE;
}
+ if (NULL != client->credential) {
+ free(client->credential);
+ client->credential = NULL;
+ }
client->credential = strdup(credential);
SLOG(LOG_DEBUG, TAG_STTC, "=====");
}
g_connect_timer = NULL;
- SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon");
+ SLOG(LOG_DEBUG, TAG_STTC, "===== Connect stt-service");
/* request initialization */
bool silence_supported = false;
SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect");
return EINA_TRUE;
} else {
- /* success to connect stt-daemon */
+ /* success to connect stt-service */
client->silence_supported = silence_supported;
client->credential_needed = credential_needed;
SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
if (NULL != data->err_msg) {
free(data->err_msg);
+ data->err_msg = NULL;
}
if (NULL != data->credential) {
free(data->credential);
+ data->credential = NULL;
}
free(data);
free(stt);
+ data = NULL;
+ stt = NULL;
return 0;
}
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_HELLO);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_INITIALIZE);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_FINALIZE);
if (NULL == msg) {
}
if (NULL != result_msg) {
- dbus_message_get_args(result_msg, &err,
+ dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
DBUS_TYPE_INVALID);
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_SET_CURRENT_ENGINE);
if (NULL == msg) {
}
if (NULL != result_msg) {
- dbus_message_get_args(result_msg, &err,
- DBUS_TYPE_INT32, &result,
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
DBUS_TYPE_INT32, silence_supported,
DBUS_TYPE_INT32, credential_needed,
DBUS_TYPE_INVALID);
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_CHECK_APP_AGREED);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_GET_SUPPORT_LANGS);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_GET_CURRENT_LANG);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_IS_TYPE_SUPPORTED);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_SET_START_SOUND);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_UNSET_START_SOUND);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_SET_STOP_SOUND);
if (NULL == msg) {
DBusMessage* msg;
msg = dbus_message_new_method_call(
- STT_SERVER_SERVICE_NAME,
- STT_SERVER_SERVICE_OBJECT_PATH,
- STT_SERVER_SERVICE_INTERFACE,
+ STT_SERVER_SERVICE_NAME,
+ STT_SERVER_SERVICE_OBJECT_PATH,
+ STT_SERVER_SERVICE_INTERFACE,
STT_METHOD_UNSET_STOP_SOUND);
if (NULL == msg) {
SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt stop : uid(%d)", uid);
}
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &uid,
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
DBUS_TYPE_INVALID);
#if 1
if (g_conn_sender) {
SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel : uid(%d)", uid);
}
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &uid,
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
DBUS_TYPE_INVALID);
#if 1
if (g_conn_sender) {
static GSList* g_engine_list;
-static int g_engine_id_count = 0;
-
#define STT_FILE_CONFIG_HANDLE 100000
-const char* stt_tag(void)
-{
- return TAG_STTFC;
-}
-
static const char* __stt_file_get_error_code(stt_file_error_e err)
{
switch (err) {
}
}
-void __stt_file_engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
+void __stt_file_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;
static int __stt_file_get_engine_info(const char* filepath, sttengine_info_s** info)
{
+#ifdef __UNUSED_CODES__
if (NULL == filepath || NULL == info) {
SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Invalid Parameter");
return STT_FILE_ERROR_INVALID_PARAMETER;
return STT_FILE_ERROR_ENGINE_NOT_FOUND;
}
- /* link engine to daemon */
+ /* link engine to stt-service */
dlsym(handle, "sttp_load_engine");
if ((error = dlerror()) != NULL) {
SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Invalid engine. Fail to open sttp_load_engine : %s", error);
SLOG(LOG_DEBUG, TAG_STTFC, " ");
*info = temp;
+#endif
return STT_FILE_ERROR_NONE;
}
if (engine->is_loaded) {
SECURE_SLOG(LOG_DEBUG, TAG_STTFC, "[Engine Agent] Unload engine id(%d)", engine->engine_id);
- if (0 != stt_engine_deinitialize(engine->engine_id))
+ if (0 != stt_engine_deinitialize())
SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Fail to deinitialize engine id(%d)", engine->engine_id);
- if (0 != stt_engine_unload(engine->engine_id))
+ if (0 != stt_engine_unload())
SECURE_SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
engine->is_loaded = false;
return NULL;
}
-void __stt_file_result_cb(sttp_result_event_e event, const char* type, const char** data, int data_count,
+void __stt_file_result_cb(stte_result_event_e event, const char* type, const char** data, int data_count,
const char* msg, void* time_info, void *user_data)
{
client->time_info = NULL;
- if (STTP_RESULT_EVENT_FINAL_RESULT == event || STTP_RESULT_EVENT_ERROR == event) {
+ if (STTE_RESULT_EVENT_FINAL_RESULT == event || STTE_RESULT_EVENT_ERROR == event) {
SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] State change : 'Ready'");
client->before_state = client->current_state;
return;
}
-void __stt_file_silence_cb(sttp_silence_type_e type, void *user_data)
+void __stt_file_speech_status_cb(stte_speech_status_e status, void *user_data)
{
+ /* it seems to be no necessity yet */
SLOG(LOG_WARN, TAG_STTFC, "[WARNING] This callback should NOT be called.");
return;
}
+void __stt_file_error_cb(stte_error_e error, const char* msg)
+{
+ /* it seems to be no necessity yet */
+ SLOG(LOG_DEBUG, TAG_STTFC, "[STT FILE] Error callback is called");
+ return;
+}
+
static int __stt_file_load_engine(sttengine_info_s* engine)
{
if (NULL == engine) {
return STT_FILE_ERROR_INVALID_PARAMETER;
}
- if (0 != stt_engine_load(engine->engine_id, engine->engine_path)) {
+ if (0 != stt_engine_load(engine->engine_path, NULL)) {
SLOG(LOG_ERROR, TAG_STTFC, "[STT FILE ERROR] Fail to load engine(%s)", engine->engine_path);
return STT_FILE_ERROR_OPERATION_FAILED;
}
- int ret = stt_engine_initialize(engine->engine_id, __stt_file_result_cb, __stt_file_silence_cb);
+ int ret = stt_engine_initialize(true);
if (0 != ret) {
SECURE_SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine : id(%d) path(%s)", engine->engine_id, engine->engine_path);
return STT_FILE_ERROR_OPERATION_FAILED;
}
if (NULL != dirp) {
- sttengine_info_s* info;
+ sttengine_info_s* info = NULL;
char* filepath;
int filesize;
switch (client->current_state) {
case STT_FILE_STATE_PROCESSING:
/* Cancel file recognition */
- stt_engine_recognize_cancel_file(client->current_engine_id);
+ stt_engine_recognize_cancel_file();
case STT_FILE_STATE_READY:
/* Unload engine */
client->current_engine_id = engine->engine_id;
if (-1 != temp_old_engine) {
- stt_engine_deinitialize(temp_old_engine);
- stt_engine_unload(temp_old_engine);
+ stt_engine_deinitialize();
+ stt_engine_unload();
}
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
client->current_engine_id, language, type, filepath, audio_type, sample_rate);
int ret = -1;
- ret = stt_engine_recognize_start_file(client->current_engine_id, language, type, filepath, audio_type, sample_rate, NULL);
+ ret = stt_engine_recognize_start_file(language, type, filepath, audio_type, sample_rate, NULL);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to start file recognition");
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
}
int ret = -1;
- ret = stt_engine_recognize_cancel_file(client->current_engine_id);
+ ret = stt_engine_recognize_cancel_file();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to cancel file recognition");
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
return STT_FILE_ERROR_NONE;
}
-bool __stt_file_result_time_cb(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
+bool __stt_file_result_time_cb(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
{
SLOG(LOG_DEBUG, TAG_STTFC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
index, event, text, start_time, end_time);
client->result_time_cb = callback;
client->result_time_user_data = user_data;
- stt_engine_foreach_result_time(client->current_engine_id, client->time_info, __stt_file_result_time_cb, NULL);
+ stt_engine_foreach_result_time(client->time_info, __stt_file_result_time_cb, NULL);
client->result_time_cb = NULL;
client->result_time_user_data = NULL;
return STT_FILE_ERROR_INVALID_STATE;
}
+ int ret = stt_engine_set_recognition_result_cb(__stt_file_result_cb, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to set recognition result cb");
+ }
+
client->recognition_result_cb = callback;
client->recognition_result_user_data = user_data;
- return 0;
+ return ret;
}
int stt_file_unset_recognition_result_cb(void)
return STT_FILE_ERROR_INVALID_STATE;
}
+ int ret = stt_engine_set_recognition_result_cb(NULL, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to set recognition result cb");
+ }
+
client->recognition_result_cb = NULL;
client->recognition_result_user_data = NULL;
- return 0;
+ return ret;
}
int stt_file_set_state_changed_cb(stt_file_state_changed_cb callback, void* user_data)
g_config_info->language = strdup(tmp_language);
free(tmp_language);
+ tmp_language = NULL;
}
return 0;
return STT_CONFIG_ERROR_NONE;
}
+static void __get_engine_list(const char* directory)
+{
+ DIR *dp = NULL;
+ int ret = -1;
+ struct dirent entry;
+ struct dirent *dirp = NULL;
+
+ if (NULL == directory) {
+ SLOG(LOG_ERROR, stt_tag(), "[Directory ERROR] Directory is NULL");
+ return;
+ }
+
+ dp = opendir(directory);
+ if (NULL != dp) {
+ do {
+ ret = readdir_r(dp, &entry, &dirp);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[File ERROR] Fail to read directory");
+ break;
+ }
+
+ if (NULL != dirp) {
+ if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
+ continue;
+
+ stt_engine_info_s* info;
+ char* filepath = NULL;
+ int filesize;
+
+ filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5;
+ filepath = (char*)calloc(filesize, sizeof(char));
+
+ if (NULL != filepath) {
+ snprintf(filepath, filesize, "%s/%s", directory, dirp->d_name);
+ } else {
+ SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Memory not enough!!");
+ continue;
+ }
+
+ if (0 == stt_parser_get_engine_info(filepath, &info)) {
+ g_engine_list = g_slist_append(g_engine_list, info);
+ }
+
+ if (NULL != filepath) {
+ free(filepath);
+ filepath = NULL;
+ }
+ }
+ } while (NULL != dirp);
+
+ closedir(dp);
+ } else {
+ SLOG(LOG_WARN, stt_tag(), "[Config WARNING] Fail to open directory");
+ }
+
+ return;
+}
+
int stt_config_mgr_initialize(int uid)
{
GSList *iter = NULL;
}
/* Get file name from default engine directory */
- DIR *dp = NULL;
- int ret = -1;
- struct dirent entry;
- struct dirent *dirp = NULL;
-
g_engine_list = NULL;
SLOG(LOG_WARN, stt_tag(), "[CONFIG] default engine info(%s)", STT_DEFAULT_ENGINE_INFO);
- dp = opendir(STT_DEFAULT_ENGINE_INFO);
- if (NULL != dp) {
- do {
- ret = readdir_r(dp, &entry, &dirp);
- if (0 != ret) {
- SLOG(LOG_ERROR, stt_tag(), "[File ERROR] Fail to read directory");
- break;
- }
-
- if (NULL != dirp) {
- if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
- continue;
-
- stt_engine_info_s* info;
- char* filepath;
- int filesize;
-
- filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5;
- filepath = (char*)calloc(filesize, sizeof(char));
-
- if (NULL != filepath) {
- snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE_INFO, dirp->d_name);
- } else {
- SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Memory not enough!!");
- continue;
- }
- if (0 == stt_parser_get_engine_info(filepath, &info)) {
- g_engine_list = g_slist_append(g_engine_list, info);
- }
-
- if (NULL != filepath)
- free(filepath);
- }
- } while (NULL != dirp);
-
- closedir(dp);
- } else {
- SLOG(LOG_WARN, stt_tag(), "[Config WARNING] Fail to open default directory");
- }
+ SLOG(LOG_DEBUG, stt_tag(), "[CONFIG] Get default engine list");
+ __get_engine_list(STT_DEFAULT_ENGINE_INFO);
+ SLOG(LOG_DEBUG, stt_tag(), "[CONFIG] Get download engine list");
+ __get_engine_list(STT_DOWNLOAD_ENGINE_INFO);
__stt_config_mgr_print_engine_info();
}
}
- /* print daemon config */
- SLOG(LOG_DEBUG, stt_tag(), "== Daemon config ==");
+ /* print stt-service config */
+ SLOG(LOG_DEBUG, stt_tag(), "== STT service config ==");
SLOG(LOG_DEBUG, stt_tag(), " engine : %s", g_config_info->engine_id);
SLOG(LOG_DEBUG, stt_tag(), " setting : %s", g_config_info->setting);
SLOG(LOG_DEBUG, stt_tag(), " auto language : %s", g_config_info->auto_lang ? "on" : "off");
return STT_CONFIG_ERROR_OPERATION_FAILED;
}
- if (false == callback(engine_info->uuid, engine_info->name,
+ if (false == callback(engine_info->uuid, engine_info->name,
engine_info->setting, engine_info->support_silence_detection, user_data)) {
break;
}
} else {
SLOG(LOG_ERROR, stt_tag(), " language is NONE");
}
- SLOG(LOG_DEBUG, stt_tag(), " silence support : %s",
+ SLOG(LOG_DEBUG, stt_tag(), " silence support : %s",
engine_info->support_silence_detection ? "true" : "false");
iter = g_slist_next(iter);
i++;
while (NULL != iter) {
data = iter->data;
- if (false == callback(data->index, data->event, data->text,
+ if (false == callback(data->index, data->event, data->text,
data->start_time, data->end_time, user_data)) {
break;
}
#define STT_DEFAULT_ENGINE_INFO tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/stt/1.0/engine-info")
#define STT_DEFAULT_ENGINE_SETTING tzplatform_mkpath(TZ_SYS_RO_SHARE, "/voice/stt/1.0/engine-setting")
+#define STT_HOME tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt")
+#define STT_DOWNLOAD_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt/1.0")
+#define STT_DOWNLOAD_ENGINE_INFO tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt/1.0/engine-info")
+
#define STT_BASE_LANGUAGE "en_US"
#define STT_RETRY_COUNT 5
#include <stdbool.h>
#include "stt_engine.h"
+#include "sttd_engine_agent.h"
/*
* Internal data structure
*/
typedef struct {
- int engine_id;
char* engine_path;
- void *handle;
-
- sttpe_funcs_s* pefuncs;
- sttpd_funcs_s* pdfuncs;
-
- int (*sttp_load_engine)(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
- int (*sttp_unload_engine)();
+ stte_request_callback_s *callback;
} sttengine_s;
extern const char* stt_tag();
-/** stt engine list */
-static GSList *g_engine_list;
+/** stt engine */
+static sttengine_s *g_engine = NULL;
-static const char* __stt_get_engine_error_code(sttp_error_e err)
-{
- switch (err) {
- case STTP_ERROR_NONE: return "STTP_ERROR_NONE";
- case STTP_ERROR_OUT_OF_MEMORY: return "STTP_ERROR_OUT_OF_MEMORY";
- case STTP_ERROR_IO_ERROR: return "STTP_ERROR_IO_ERROR";
- case STTP_ERROR_INVALID_PARAMETER: return "STTP_ERROR_INVALID_PARAMETER";
- case STTP_ERROR_TIMED_OUT: return "STTP_ERROR_TIMED_OUT";
- case STTP_ERROR_RECORDER_BUSY: return "STTP_ERROR_RECORDER_BUSY";
- case STTP_ERROR_OUT_OF_NETWORK: return "STTP_ERROR_OUT_OF_NETWORK";
- case STTP_ERROR_PERMISSION_DENIED: return "STTP_ERROR_PERMISSION_DENIED";
- case STTP_ERROR_NOT_SUPPORTED: return "STTP_ERROR_NOT_SUPPORTED";
- case STTP_ERROR_INVALID_STATE: return "STTP_ERROR_INVALID_STATE";
- case STTP_ERROR_INVALID_LANGUAGE: return "STTP_ERROR_INVALID_LANGUAGE";
- case STTP_ERROR_ENGINE_NOT_FOUND: return "STTP_ERROR_ENGINE_NOT_FOUND";
- case STTP_ERROR_OPERATION_FAILED: return "STTP_ERROR_OPERATION_FAILED";
- case STTP_ERROR_NOT_SUPPORTED_FEATURE: return "STTP_ERROR_NOT_SUPPORTED_FEATURE";
- default:
- return "Invalid error code";
- }
-}
+static bool g_is_from_lib = false;
-static sttengine_s* __get_engine(int engine_id)
-{
- /* check whether engine id is valid or not.*/
- GSList *iter = NULL;
- sttengine_s *engine = NULL;
+/** callback functions */
+static stt_engine_result_cb g_result_cb = NULL;
+static stte_private_data_set_cb g_set_private_data_cb = NULL;
+static stte_private_data_requested_cb g_get_private_data_cb = NULL;
- if (g_slist_length(g_engine_list) > 0) {
- /*Get a first item*/
- iter = g_slist_nth(g_engine_list, 0);
- while (NULL != iter) {
- /*Get handle data from list*/
- engine = iter->data;
+static int __stt_set_engine_from(bool is_from_lib)
+{
+ g_is_from_lib = is_from_lib;
+ return 0;
+}
- if (engine_id == engine->engine_id) {
- return engine;
- }
+static bool __stt_get_engine_from(void)
+{
+ return g_is_from_lib;
+}
- /*Get next item*/
- iter = g_slist_next(iter);
- }
+static const char* __stt_get_engine_error_code(stte_error_e err)
+{
+ switch (err) {
+ case STTE_ERROR_NONE: return "STTE_ERROR_NONE";
+ case STTE_ERROR_OUT_OF_MEMORY: return "STTE_ERROR_OUT_OF_MEMORY";
+ case STTE_ERROR_IO_ERROR: return "STTE_ERROR_IO_ERROR";
+ case STTE_ERROR_INVALID_PARAMETER: return "STTE_ERROR_INVALID_PARAMETER";
+ case STTE_ERROR_NETWORK_DOWN: return "STTE_ERROR_NETWORK_DOWN";
+ case STTE_ERROR_PERMISSION_DENIED: return "STTE_ERROR_PERMISSION_DENIED";
+ case STTE_ERROR_NOT_SUPPORTED: return "STTE_ERROR_NOT_SUPPORTED";
+ case STTE_ERROR_INVALID_STATE: return "STTE_ERROR_INVALID_STATE";
+ case STTE_ERROR_INVALID_LANGUAGE: return "STTE_ERROR_INVALID_LANGUAGE";
+ case STTE_ERROR_OPERATION_FAILED: return "STTE_ERROR_OPERATION_FAILED";
+ case STTE_ERROR_NOT_SUPPORTED_FEATURE: return "STTE_ERROR_NOT_SUPPORTED_FEATURE";
+ case STTE_ERROR_RECORDING_TIMED_OUT: return "STTE_ERROR_RECORDING_TIMED_OUT";
+ default:
+ return "Invalid error code";
}
-
- return NULL;
}
/* Register engine id */
-int stt_engine_load(int engine_id, const char* filepath)
+int stt_engine_load(const char* filepath, stte_request_callback_s *callback)
{
- if (NULL == filepath || engine_id < 0) {
+ if (NULL == callback || NULL == filepath) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL != engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is already loaded", engine_id);
- return 0;
- }
-
- SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Engine] Load engine id(%d), path(%s)", engine_id, filepath);
-
/* allocation memory */
- engine = (sttengine_s*)calloc(1, sizeof(sttengine_s));
- if (NULL == engine) {
- SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
- return STTP_ERROR_OUT_OF_MEMORY;
- }
-
- /* load engine */
- char *error;
-
- engine->handle = dlopen(filepath, RTLD_LAZY);
- if (!engine->handle) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine] Invalid engine (Fail dlopen) : %s", filepath);
- free(engine);
- return STTP_ERROR_OPERATION_FAILED;
- }
-
- engine->pefuncs = (sttpe_funcs_s*)calloc(1, sizeof(sttpe_funcs_s));
- if (NULL == engine->pefuncs) {
- SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
- dlclose(engine->handle);
- free(engine);
- return STTP_ERROR_OUT_OF_MEMORY;
- }
- engine->pdfuncs = (sttpd_funcs_s*)calloc(1, sizeof(sttpd_funcs_s));
- if (NULL == engine->pdfuncs) {
- SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
- dlclose(engine->handle);
- free(engine->pefuncs);
- free(engine);
- return STTP_ERROR_OUT_OF_MEMORY;
- }
-
- engine->sttp_unload_engine = NULL;
- engine->sttp_load_engine = NULL;
-
- engine->sttp_unload_engine = (int (*)())dlsym(engine->handle, "sttp_unload_engine");
- if (NULL != (error = dlerror()) || NULL == engine->sttp_unload_engine) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_unload_engine() : %s", error);
- dlclose(engine->handle);
- free(engine->pefuncs);
- free(engine->pdfuncs);
- free(engine);
- return STTP_ERROR_OPERATION_FAILED;
- }
-
- engine->sttp_load_engine = (int (*)(sttpd_funcs_s*, sttpe_funcs_s*))dlsym(engine->handle, "sttp_load_engine");
- if (NULL != (error = dlerror()) || NULL == engine->sttp_load_engine) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_load_engine() : %s", error);
- dlclose(engine->handle);
- free(engine->pefuncs);
- free(engine->pdfuncs);
- free(engine);
- return STTP_ERROR_OPERATION_FAILED;
- }
-
- engine->engine_id = engine_id;
- engine->engine_path = strdup(filepath);
-
- engine->pdfuncs->version = 1;
- engine->pdfuncs->size = sizeof(sttpd_funcs_s);
-
- int ret = engine->sttp_load_engine(engine->pdfuncs, engine->pefuncs);
- if (0 != ret) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail sttp_load_engine() : %s", __stt_get_engine_error_code(ret));
- dlclose(engine->handle);
- free(engine->pefuncs);
- free(engine->pdfuncs);
- free(engine->engine_path);
- free(engine);
- return ret;
- }
-
- /* engine error check */
- if (engine->pefuncs->size != sizeof(sttpe_funcs_s)) {
- SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine is not valid : function size is not matched");
- }
-
- if (NULL == engine->pefuncs->initialize ||
- NULL == engine->pefuncs->deinitialize ||
- NULL == engine->pefuncs->foreach_langs ||
- NULL == engine->pefuncs->is_valid_lang ||
- NULL == engine->pefuncs->support_silence ||
- NULL == engine->pefuncs->support_recognition_type ||
- NULL == engine->pefuncs->get_audio_format ||
- NULL == engine->pefuncs->set_silence_detection ||
- NULL == engine->pefuncs->start ||
- NULL == engine->pefuncs->set_recording ||
- NULL == engine->pefuncs->stop ||
- NULL == engine->pefuncs->cancel ||
- NULL == engine->pefuncs->foreach_result_time)
- /* Current unused functions
- NULL == engine->pefuncs->start_file_recognition ||
- */
- {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] The engine functions are NOT valid");
- dlclose(engine->handle);
- free(engine->pefuncs);
- free(engine->pdfuncs);
- free(engine->engine_path);
- free(engine);
+ if (NULL != g_engine) {
+ SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine is already loaded");
+ } else {
+ g_engine = (sttengine_s*)calloc(1, sizeof(sttengine_s));
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+ return STTE_ERROR_OUT_OF_MEMORY;
+ }
- return STTP_ERROR_OPERATION_FAILED;
+ /* load engine */
+ g_engine->callback = callback;
+ g_engine->engine_path = strdup(filepath);
}
- SLOG(LOG_DEBUG, stt_tag(), "[Engine Success] Load engine : version(%d), size(%d)", engine->pefuncs->version, engine->pefuncs->size);
-
- g_engine_list = g_slist_append(g_engine_list, engine);
+ SLOG(LOG_DEBUG, stt_tag(), "[Engine Success] Load engine : version(%d)", g_engine->callback->version);
return 0;
}
/* Unregister engine id */
-int stt_engine_unload(int engine_id)
+int stt_engine_unload()
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- /* unload engine */
- engine->sttp_unload_engine();
- dlclose(engine->handle);
-
- if (NULL != engine->engine_path) free(engine->engine_path);
- if (NULL != engine->pefuncs) free(engine->pefuncs);
- if (NULL != engine->pdfuncs) free(engine->pdfuncs);
+ g_engine->callback = NULL;
- g_engine_list = g_slist_remove(g_engine_list, engine);
+ if (NULL != g_engine->engine_path) {
+ free(g_engine->engine_path);
+ g_engine->engine_path = NULL;
+ }
- free(engine);
+ free(g_engine);
+ g_engine = NULL;
return 0;
}
/* Initialize / Deinitialize */
-int stt_engine_initialize(int engine_id, sttpe_result_cb result_cb, sttpe_silence_detected_cb silence_cb)
+int stt_engine_initialize(bool is_from_lib)
{
- if (NULL == result_cb || NULL == silence_cb) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback->initialize) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
int ret;
- ret = engine->pefuncs->initialize(result_cb, silence_cb);
+ ret = __stt_set_engine_from(is_from_lib);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set engine : %s", __stt_get_engine_error_code(ret));
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ ret = g_engine->callback->initialize();
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to initialize : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_deinitialize(int engine_id)
+int stt_engine_deinitialize()
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->deinitialize) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
int ret;
- ret = engine->pefuncs->deinitialize();
+ ret = g_engine->callback->deinitialize();
if (0 != ret) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to deinitialize : %s", __stt_get_engine_error_code(ret));
}
}
/* Get option */
-int stt_engine_get_supported_langs(int engine_id, GSList** lang_list)
+int stt_engine_get_supported_langs(GSList** lang_list)
{
if (NULL == lang_list) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback->foreach_langs) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
int ret;
- ret = engine->pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list);
+ ret = g_engine->callback->foreach_langs(__supported_language_cb, (void*)lang_list);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid)
+int stt_engine_is_valid_language(const char* language, bool *is_valid)
{
if (NULL == language || NULL == is_valid) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- bool result;
- result = engine->pefuncs->is_valid_lang(language);
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
- *is_valid = result;
+ if (NULL == g_engine->callback->is_valid_lang) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
- return 0;
+ int ret = STTE_ERROR_NONE;
+ ret = g_engine->callback->is_valid_lang(language, is_valid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to check valid language(%d)", ret);
+ }
+ return ret;
}
-int stt_engine_set_private_data(int engine_id, const char* key, const char* data)
+int stt_engine_set_private_data(const char* key, const char* data)
{
if (NULL == key || NULL == data) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ int ret = STTE_ERROR_NONE;
+ if (NULL != g_set_private_data_cb) {
+ ret = g_set_private_data_cb(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set private data(%d)", ret);
+ }
}
- int ret = engine->pefuncs->set_private_data(key, data);
- if (0 != ret) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set private data(%d)", ret);
- }
return ret;
}
-int stt_engine_get_private_data(int engine_id, const char* key, char** data)
+int stt_engine_get_private_data(const char* key, char** data)
{
if (NULL == key || NULL == data) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
- }
-
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
+ int ret = STTE_ERROR_NONE;
char* temp = NULL;
- int ret = engine->pefuncs->get_private_data(key, &temp);
- if (0 != ret) {
- SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get private data(%d)", ret);
- return ret;
+ if (NULL != g_get_private_data_cb) {
+ ret = g_get_private_data_cb(key, &temp);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get private data(%d)", ret);
+ return ret;
+ }
+ } else {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] There's no private data function)");
}
if (NULL == temp)
else
*data = strdup(temp);
- return STTP_ERROR_NONE;
+ return STTE_ERROR_NONE;
}
-int stt_engine_get_first_language(int engine_id, char** language)
+int stt_engine_get_first_language(char** language)
{
if (NULL == language) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->foreach_langs || NULL == g_engine->callback->is_valid_lang) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
GSList* lang_list = NULL;
int ret;
- ret = engine->pefuncs->foreach_langs(__supported_language_cb, &lang_list);
+ ret = g_engine->callback->foreach_langs(__supported_language_cb, &lang_list);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret));
return ret;
if (NULL != iter) {
data = iter->data;
- if (true == engine->pefuncs->is_valid_lang(data)) {
+ bool is_valid = false;
+ ret = g_engine->callback->is_valid_lang(data, &is_valid);
+ if (0 == ret && true == is_valid) {
*language = strdup(data);
} else {
- ret = STTP_ERROR_OPERATION_FAILED;
+ ret = STTE_ERROR_OPERATION_FAILED;
}
}
return ret;
}
-int stt_engine_support_silence(int engine_id, bool* support)
+int stt_engine_support_silence(bool* support)
{
if (NULL == support) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback->support_silence) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
bool result;
- result = engine->pefuncs->support_silence();
+ result = g_engine->callback->support_silence();
*support = result;
- return 0;
+ return STTE_ERROR_NONE;
}
-
-int stt_engine_need_app_credential(int engine_id, bool* need)
+int stt_engine_need_app_credential(bool* need)
{
if (NULL == need) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- bool result;
- if (NULL != engine->pefuncs->need_app_credential) {
- result = engine->pefuncs->need_app_credential();
- *need = result;
- return STTP_ERROR_NONE;
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->need_app_credential) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- return STTP_ERROR_OPERATION_FAILED;
+ bool result;
+ result = g_engine->callback->need_app_credential();
+ *need = result;
+
+ return STTE_ERROR_NONE;
}
-int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support)
+int stt_engine_support_recognition_type(const char* type, bool* support)
{
if (NULL == type || NULL == support) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- bool result;
- if (NULL != engine->pefuncs->support_recognition_type) {
- result = engine->pefuncs->support_recognition_type(type);
- *support = result;
- return 0;
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->support_recognition_type) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR} Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- return STTP_ERROR_OPERATION_FAILED;
+ int ret = STTE_ERROR_NONE;
+ ret = g_engine->callback->support_recognition_type(type, support);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get supporting recognition type(%d)", ret);
+ }
+ return ret;
}
-int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels)
+int stt_engine_get_audio_type(stte_audio_type_e* types, int* rate, int* channels)
{
if (NULL == types || NULL == rate || NULL == channels) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->get_audio_format) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
int ret;
- ret = engine->pefuncs->get_audio_format(types, rate, channels);
+ ret = g_engine->callback->get_audio_format(types, rate, channels);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get audio format : %s", __stt_get_engine_error_code(ret));
}
}
/* Set option */
-int stt_engine_set_silence_detection(int engine_id, bool value)
+int stt_engine_set_silence_detection(bool value)
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->set_silence_detection(value);
- if (STTP_ERROR_NOT_SUPPORTED_FEATURE == ret) {
+ if (NULL == g_engine->callback->set_silence_detection) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ int ret = g_engine->callback->set_silence_detection(value);
+ if (STTE_ERROR_NOT_SUPPORTED_FEATURE == ret) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support silence detection");
- return STTP_ERROR_NOT_SUPPORTED_FEATURE;
} else if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set silence detection : %d", ret);
}
-
return ret;
}
-int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value)
+int stt_engine_check_app_agreed(const char* appid, bool* is_agreed)
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == is_agreed) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ return STTE_ERROR_INVALID_PARAMETER;
}
- if (NULL == engine->pefuncs->check_app_agreed) {
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->check_app_agreed) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support app agreement. All app is available");
- *value = true;
+ *is_agreed = true;
return 0;
}
- int ret = engine->pefuncs->check_app_agreed(appid, value);
+ int ret = g_engine->callback->check_app_agreed(appid, is_agreed);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get app agreement : %s", __stt_get_engine_error_code(ret));
- *value = false;
+ *is_agreed = false;
}
return ret;
}
/* Recognition */
-int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, const char* credential, void* user_param)
+int stt_engine_recognize_start(const char* lang, const char* recognition_type, const char* appid, const char* credential, void* user_param)
{
if (NULL == lang || NULL == recognition_type) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback->start) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->start(lang, recognition_type, credential, user_param);
+ int ret = g_engine->callback->start(lang, recognition_type, appid, credential, user_param);
+
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : %s", __stt_get_engine_error_code(ret));
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : lang(%s), recognition_type(%s), credential(%s)", lang, recognition_type, credential);
return ret;
}
-int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length)
+int stt_engine_set_recording_data(const void* data, unsigned int length)
{
if (NULL == data) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->set_recording(data, length);
+ if (NULL == g_engine->callback->set_recording) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ int ret = g_engine->callback->set_recording(data, length);
if (0 != ret) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to set recording : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_recognize_stop(int engine_id)
+int stt_engine_recognize_stop()
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->stop) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->stop();
+ int ret = g_engine->callback->stop();
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to stop : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_recognize_cancel(int engine_id)
+int stt_engine_recognize_cancel()
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->cancel();
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback->cancel) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ int ret = g_engine->callback->cancel();
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to cancel : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_foreach_result_time(int engine_id, void* time_info, sttpe_result_time_cb callback, void* user_data)
+int stt_engine_foreach_result_time(void* time_info, stte_result_time_cb callback, void* user_data)
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- int ret = engine->pefuncs->foreach_result_time(time_info, callback, user_data);
+ if (NULL == g_engine->callback->foreach_result_time) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ int ret = g_engine->callback->foreach_result_time(time_info, callback, user_data);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to foreach result time : %s", __stt_get_engine_error_code(ret));
}
return ret;
}
-int stt_engine_recognize_start_file(int engine_id, const char* lang, const char* recognition_type,
- const char* filepath, sttp_audio_type_e audio_type, int sample_rate, void* user_param)
+int stt_engine_recognize_start_file(const char* lang, const char* recognition_type,
+ const char* filepath, stte_audio_type_e audio_type, int sample_rate, void* user_param)
{
if (NULL == filepath || NULL == lang || NULL == recognition_type) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
- return STTP_ERROR_INVALID_PARAMETER;
+ return STTE_ERROR_INVALID_PARAMETER;
}
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- if (NULL == engine->pefuncs->start_file) {
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+#ifdef __UNUSED_CODES__
+ if (NULL == g_engine->callback->start_file) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid");
- return STTP_ERROR_NOT_SUPPORTED_FEATURE;
+ return STTE_ERROR_NOT_SUPPORTED_FEATURE;
}
- int ret = engine->pefuncs->start_file(lang, recognition_type, filepath, audio_type, sample_rate, user_param);
+ int ret = g_engine->callback->start_file(lang, recognition_type, filepath, audio_type, sample_rate, user_param);
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret));
}
-
- return ret;
+#endif
+ return 0;
}
-int stt_engine_recognize_cancel_file(int engine_id)
+int stt_engine_recognize_cancel_file()
{
- sttengine_s* engine = NULL;
- engine = __get_engine(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
- return STTP_ERROR_INVALID_PARAMETER;
+ if (NULL == g_engine) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] No engine");
+ return STTE_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_engine->callback) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid engine");
+ return STTE_ERROR_OPERATION_FAILED;
}
- if (NULL == engine->pefuncs->cancel_file) {
+#ifdef __UNUSED_CODES__
+ if (NULL == g_engine->callback->cancel_file) {
SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid");
- return STTP_ERROR_NOT_SUPPORTED_FEATURE;
+ return STTE_ERROR_NOT_SUPPORTED_FEATURE;
}
- int ret = engine->pefuncs->cancel_file();
+ int ret = g_engine->callback->cancel_file();
if (0 != ret) {
SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret));
}
+#endif
+ return 0;
+}
+
+int stt_engine_set_recognition_result_cb(stt_engine_result_cb result_cb, void* user_data)
+{
+ if (NULL == result_cb) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ g_result_cb = result_cb;
+
+ return 0;
+}
+
+int stt_engine_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
+ const char* msg, void* time_info, void* user_data)
+{
+ if (NULL == type || NULL == result) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ }
+
+ int ret = STTE_ERROR_NONE;
+ if (false == __stt_get_engine_from()) {
+ ret = sttd_engine_agent_send_result(event, type, result, result_count, msg, time_info, user_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to send result");
+ }
+ } else {
+ g_result_cb(event, type, result, result_count, msg, time_info, user_data);
+ }
+ return ret;
+}
+
+int stt_engine_send_error(stte_error_e error, const char* msg)
+{
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ }
+
+ int ret = STTE_ERROR_NONE;
+ ret = sttd_engine_agent_send_error(error, msg);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to send error info");
+ }
+ return ret;
+}
+int stt_engine_send_speech_status(stte_speech_status_e status, void* user_data)
+{
+ int ret = STTE_ERROR_NONE;
+ ret = sttd_engine_agent_send_speech_status(status, user_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to send speech status");
+ }
return ret;
}
+
+int stt_engine_set_private_data_set_cb(stte_private_data_set_cb private_data_set_cb, void* user_data)
+{
+ if (NULL == private_data_set_cb) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ g_set_private_data_cb = private_data_set_cb;
+
+ return 0;
+}
+
+int stt_engine_set_private_data_requested_cb(stte_private_data_requested_cb private_data_requested_cb, void* user_data)
+{
+ if (NULL == private_data_requested_cb) {
+ SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid parameter");
+ return STTE_ERROR_INVALID_PARAMETER;
+ }
+
+ g_get_private_data_cb = private_data_requested_cb;
+
+ return 0;
+}
#define __STT_ENGINE_H_
#include <glib.h>
-#include "sttp.h"
+#include "stte.h"
#ifdef __cplusplus
extern "C" {
#endif
+
+typedef void (*stt_engine_result_cb)(stte_result_event_e event, const char* type, const char** data, int data_count,
+ const char* msg, void* time_info, void* user_data);
+
/*
* STT Engine Interfaces
*/
/* Register engine id */
-int stt_engine_load(int engine_id, const char* filepath);
+int stt_engine_load(const char* filepath, stte_request_callback_s *callback);
/* Unregister engine id */
-int stt_engine_unload(int engine_id);
+int stt_engine_unload();
/* Init / Deinit */
-int stt_engine_initialize(int engine_id, sttpe_result_cb result_cb, sttpe_silence_detected_cb silence_cb);
+int stt_engine_initialize(bool is_from_lib);
-int stt_engine_deinitialize(int engine_id);
+int stt_engine_deinitialize();
/* Get option */
-int stt_engine_get_supported_langs(int engine_id, GSList** lang_list);
+int stt_engine_get_supported_langs(GSList** lang_list);
-int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid);
+int stt_engine_is_valid_language(const char* language, bool *is_valid);
-int stt_engine_set_private_data(int engine_id, const char* key, const char* data);
+int stt_engine_set_private_data(const char* key, const char* data);
-int stt_engine_get_private_data(int engine_id, const char* key, char** data);
+int stt_engine_get_private_data(const char* key, char** data);
-int stt_engine_get_first_language(int engine_id, char** language);
+int stt_engine_get_first_language(char** language);
-int stt_engine_support_silence(int engine_id, bool* support);
+int stt_engine_support_silence(bool* support);
-int stt_engine_need_app_credential(int engine_id, bool* need);
+int stt_engine_need_app_credential(bool* need);
-int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support);
+int stt_engine_support_recognition_type(const char* type, bool* support);
-int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels);
+int stt_engine_get_audio_type(stte_audio_type_e* types, int* rate, int* channels);
/* Set option */
-int stt_engine_set_silence_detection(int engine_id, bool value);
+int stt_engine_set_silence_detection(bool value);
/* Get right */
-int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value);
+int stt_engine_check_app_agreed(const char* appid, bool* is_agreed);
/* Recognition */
-int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, const char* credential, void* user_param);
+int stt_engine_recognize_start(const char* lang, const char* recognition_type, const char* appid, const char* credential, void* user_param);
-int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length);
+int stt_engine_set_recording_data(const void* data, unsigned int length);
-int stt_engine_recognize_stop(int engine_id);
+int stt_engine_recognize_stop();
-int stt_engine_recognize_cancel(int engine_id);
+int stt_engine_recognize_cancel();
-int stt_engine_foreach_result_time(int engine_id, void* time_info, sttpe_result_time_cb callback, void* user_data);
+int stt_engine_foreach_result_time(void* time_info, stte_result_time_cb callback, void* user_data);
/* File recognition */
-int stt_engine_recognize_start_file(int engine_id, const char* lang, const char* recognition_type,
- const char* filepath, sttp_audio_type_e audio_type, int sample_rate, void* user_param);
+int stt_engine_recognize_start_file(const char* lang, const char* recognition_type,
+ const char* filepath, stte_audio_type_e audio_type, int sample_rate, void* user_param);
+
+int stt_engine_recognize_cancel_file();
+
+int stt_engine_set_recognition_result_cb(stt_engine_result_cb result_cb, void* user_data);
+
+int stt_engine_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
+ const char* msg, void* time_info, void* user_data);
+
+int stt_engine_send_error(stte_error_e error, const char* msg);
+
+int stt_engine_send_speech_status(stte_speech_status_e status, void* user_data);
+
+int stt_engine_set_private_data_set_cb(stte_private_data_set_cb private_data_set_cb, void* user_data);
-int stt_engine_recognize_cancel_file(int engine_id);
+int stt_engine_set_private_data_requested_cb(stte_private_data_requested_cb private_data_requested_cb, void* user_data);
#ifdef __cplusplus
* To use of STT, use the following steps:<br>
* 1. Create a handle <br>
* 2. Register callback functions for notifications <br>
- * 3. Prepare stt-daemon asynchronously <br>
+ * 3. Prepare stt-service asynchronously <br>
* 4. Start recording for recognition <br>
* 5. Stop recording <br>
* 6. Get result after processing <br>
* 7. Destroy a handle <br>
*
* The STT has a client-server for the service of multi-applications.
- * The STT daemon as a server always works in the background for the STT service.
- * If the daemon is not working, client library will invoke it and client will communicate with it.
- * The daemon has engines and the recorder so client does not have the recorder itself.
- * Only the client request commands to the daemon for the service.
+ * The STT service always works in the background as a server.
+ * If the service is not working, client library will invoke it and client will communicate with it.
+ * The service has engines and the recorder so client does not have the recorder itself.
+ * Only the client request commands to the STT service for using STT.
*
* @section CAPI_STT_MODULE_STATE_DIAGRAM State Diagram
* The following diagram shows the life cycle and the states of the STT.
* <tr>
* <td>stt_prepare()</td>
* <td>Created</td>
- * <td>This function works asynchronously. If daemon fork is failed, application gets the error callback.</td>
+ * <td>This function works asynchronously. If the STT service fork is failed, application gets the error callback.</td>
* </tr>
* <tr>
* <td>stt_unprepare()</td>
--- /dev/null
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_UIX_STT_ENGINE_DOC_H__
+#define __TIZEN_UIX_STT_ENGINE_DOC_H__
+
+/**
+ * @ingroup CAPI_UIX_FRAMEWORK
+ * @defgroup CAPI_UIX_STTE_MODULE STT Engine
+ * @brief The @ref CAPI_UIX_STTE_MODULE APIs provide functions to operate Speech-To-Text Engine.
+ *
+ *
+ * @section CAPI_UIX_STTE_MODULE_HEADER Required Header
+ * \#include <stte.h>
+ *
+ *
+ * @section CAPI_UIX_STTE_MODULE_OVERVIEW Overview
+ * Speech-To-Text Engine (below STTE) is an engine for recording speech and resulting in texts of speech recognition.
+ * Using the @ref CAPI_UIX_STTE_MODULE APIs, STTE developers can provide STTE service users, who want to apply STTE, with functions necessary to operate the engine.
+ * According to the indispensability of STTE services, there are two ways to provide them to the users. <br>
+ *
+ * <b>A. Required STTE services</b> <br>
+ * These services are indispensable to operate STTE. Therefore, the STTE developers MUST implement callback functions corresponding to the required STTE services.
+ * The following is a list of the callback functions. <br>
+ *
+ * <table>
+ * <tr>
+ * <th>FUNCTION</th>
+ * <th>DESCRIPTION</th>
+ * </tr>
+ * <tr>
+ * <td>stte_get_info_cb()</td>
+ * <td>Called when the engine service user requests the basic information of STT engine.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_initialize_cb()</td>
+ * <td>Called when the engine service user initializes STT engine.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_deinitialize_cb()</td>
+ * <td>Called when the engine service user deinitializes STT engine.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_is_valid_language_cb()</td>
+ * <td>Called when the engine service user checks whether the corresponding language is valid or not.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_foreach_supported_langs_cb()</td>
+ * <td>Called when the engine service user gets the whole supported language list.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_support_silence_detection_cb()</td>
+ * <td>Called when the engine service user checks whether STT engine supports silence detection.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_set_silence_detection_cb()</td>
+ * <td>Called when the engine service user sets the silence detection.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_support_recognition_type_cb()</td>
+ * <td>Called when the engine service user checks whether STT engine supports the corresponding recognition type.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_get_recording_format_cb()</td>
+ * <td>Called when the engine service user gets the proper recording format of STT engine.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_set_recording_data_cb()</td>
+ * <td>Called when the engine service user sets and sends the recording data for speech recognition.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_foreach_result_time_cb()</td>
+ * <td>Called when the engine service user gets the result time information(stamp).</td>
+ * </tr>
+ * <tr>
+ * <td>stte_start_cb()</td>
+ * <td>Called when the engine service user starts to recognize the recording data.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_stop_cb()</td>
+ * <td>Called when the engine service user stops to recognize the recording data.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_cancel_cb()</td>
+ * <td>Called when the engine service user cancels to recognize the recording data.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_check_app_agreed_cb()</td>
+ * <td>Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_need_app_credential_cb()</td>
+ * <td>Called when the engine service user checks whether STT engine needs the application's credential.</td>
+ * </tr>
+ * </table>
+ *
+ * The STTE developers can register the above callback functions at a time with using a structure 'stte_request_callback_s' and an API 'stte_main()'.
+ * To operate STTE, the following steps should be used: <br>
+ * 1. Create a structure 'stte_request_callback_s'. <br>
+ * 2. Implement callback functions. (NOTE that the callback functions should return appropriate values in accordance with the instruction.
+ * If the callback function returns an unstated value, STT framework will handle it as #STTE_ERROR_OPERATION_FAILED.)<br>
+ * 3. Register callback functions using 'stte_main()'. (The registered callback functions will be called when the STTE service users request the STTE services.) <br>
+ * 4. Use 'service_app_main()' for working STTE. <br>
+ *
+ * <b>B. Optional STTE services</b> <br>
+ * Unlike the required STTE services, these services are optional to operate STTE. The followings are optional STTE services. <br>
+ * - receive/provide the private data <br>
+ *
+ * If the STTE developers want to provide the above services, use the following APIs and implement the corresponding callback functions: <br>
+ * <table>
+ * <tr>
+ * <th>FUNCTION</th>
+ * <th>DESCRIPTION</th>
+ * <th>CORRESPONDING CALLBACK</th>
+ * </tr>
+ * <tr>
+ * <td>stte_set_private_data_set_cb()</td>
+ * <td>Sets a callback function for receiving the private data from the engine service user.</td>
+ * <td>stte_private_data_set_cb()</td>
+ * </tr>
+ * <tr>
+ * <td>stte_set_private_data_requested_cb()</td>
+ * <td>Sets a callback function for providing the private data to the engine service user.</td>
+ * <td>stte_private_data_requested_cb()</td>
+ * </tr>
+ * </table>
+ * <br>
+ *
+ * Using the above APIs, the STTE developers can register the optional callback functions respectively.
+ * (For normal operation, put those APIs before 'service_app_main()' starts.)
+ *
+ * Unlike callback functions, the following APIs are functions for getting and sending data. The STTE developers can use these APIs when they implement STTE services: <br>
+ * <table>
+ * <tr>
+ * <th>FUNCTION</th>
+ * <th>DESCRIPTION</th>
+ * </tr>
+ * <tr>
+ * <td>stte_send_result()</td>
+ * <td>Sends the recognition result to the engine service user.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_send_error()</td>
+ * <td>Sends the error to the engine service user.</td>
+ * </tr>
+ * <tr>
+ * <td>stte_send_speech_status()</td>
+ * <td>Sends the speech status to the engine service user when STT engine notifies the change of the speech status.</td>
+ * </tr>
+ * </table>
+ *
+ *
+ * @section CAPI_UIX_STTE_MODULE_FEATURE Related Features
+ * This API is related with the following features:<br>
+ * - http://tizen.org/feature/speech.recognition<br>
+ * - http://tizen.org/feature/microphone<br>
+ *
+ * It is recommended to design feature related codes in your application for reliability.<br>
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.<br>
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.<br>
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
+
+#endif /* __TIZEN_UIX_STT_ENGINE_DOC_H__ */
+
INSTALL(FILES "${CMAKE_BINARY_DIR}/include/stt.h" DESTINATION ${INCLUDEDIR})
INSTALL(FILES "${CMAKE_BINARY_DIR}/include/stt_file.h" DESTINATION ${INCLUDEDIR})
INSTALL(FILES "${CMAKE_BINARY_DIR}/include/stt_setting.h" DESTINATION ${INCLUDEDIR})
-INSTALL(FILES "${CMAKE_BINARY_DIR}/server/sttp.h" DESTINATION ${INCLUDEDIR})
+INSTALL(FILES "${CMAKE_BINARY_DIR}/include/stte.h" DESTINATION ${INCLUDEDIR})
Description: Speech To Text client engine header
Requires: glib-2.0 dbus-1
Version: @VERSION@
+Libs: -L${libdir} -l@PROJECT_NAME@_engine
Cflags: -I${includedir}
STT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
STT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
STT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
- STT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
+ STT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the STT service */
STT_ERROR_RECORDER_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */
STT_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */
STT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */
* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #STT_ERROR_INVALID_STATE Invalid state
* @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
- * @retval #STT_ERROR_TIMED_OUT No answer from the daemon
+ * @retval #STT_ERROR_TIMED_OUT No answer from the STT service
*
* @pre The state should be #STT_STATE_READY.
*
* @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #STT_ERROR_INVALID_STATE Invalid state
* @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
- * @retval #STT_ERROR_TIMED_OUT No answer from the daemon
+ * @retval #STT_ERROR_TIMED_OUT No answer from the STT service
*
* @pre The state should be #STT_STATE_READY.
*
int stt_get_private_data(stt_h stt, const char* key, char** data);
/**
- * @brief Connects the daemon asynchronously.
+ * @brief Connects the STT service asynchronously.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @privlevel public
* @privilege %http://tizen.org/privilege/recorder
int stt_prepare(stt_h stt);
/**
- * @brief Disconnects the daemon.
+ * @brief Disconnects the STT service.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @privlevel public
* @privilege %http://tizen.org/privilege/recorder
* @privlevel public
* @privilege %http://tizen.org/privilege/recorder
*
- * @remarks This function starts recording in the daemon and sending recording data to engine. \n
+ * @remarks This function starts recording in the STT service and sending recording data to engine. \n
* This work continues until stt_stop(), stt_cancel() or silence detected by engine.
*
* @param[in] stt The STT handle
STT_SETTING_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
STT_SETTING_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
STT_SETTING_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
- STT_SETTING_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
+ STT_SETTING_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the service */
STT_SETTING_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */
STT_SETTING_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */
STT_SETTING_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< STT is NOT supported */
*
* @return 0 on success, otherwise a negative error value.
* @retval #STT_SETTING_ERROR_NONE Success.
-* @retval #STT_SETTING_ERROR_TIMED_OUT stt daemon is blocked or stt daemon do not exist.
+* @retval #STT_SETTING_ERROR_TIMED_OUT stt service is blocked or stt service do not exist.
* @retval #STT_SETTING_ERROR_INVALID_STATE STT setting has Already been initialized.
* @retval #STT_SETTING_ERROR_ENGINE_NOT_FOUND No available stt-engine. Engine should be installed.
* @retval #STT_SETTING_ERROR_NOT_SUPPORTED STT NOT supported
int stt_setting_initialize(void);
/**
-* @brief finalize stt setting and disconnect to stt-daemon.
+* @brief finalize stt setting and disconnect to stt-service.
*
* @return 0 on success, otherwise a negative error value.
* @retval #STT_SETTING_ERROR_NONE Success.
--- /dev/null
+/*
+* 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
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __STT_ENGINE_MAIN_H__
+#define __STT_ENGINE_MAIN_H__
+
+#include <tizen.h>
+
+/**
+* @addtogroup CAPI_UIX_STTE_MODULE
+* @{
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* @brief Enumerations for error codes.
+* @since_tizen 3.0
+*/
+typedef enum {
+ STTE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ STTE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
+ STTE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+ STTE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ STTE_ERROR_NETWORK_DOWN = TIZEN_ERROR_NETWORK_DOWN, /**< Network down(Out of network) */
+ STTE_ERROR_INVALID_STATE = TIZEN_ERROR_STT | 0x01, /**< Invalid state */
+ STTE_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_STT | 0x02, /**< Invalid language */
+ STTE_ERROR_OPERATION_FAILED = TIZEN_ERROR_STT | 0x04, /**< Operation failed */
+ STTE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_STT | 0x05, /**< Not supported feature */
+ STTE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+ STTE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ STTE_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x06 /**< Recording timed out */
+} stte_error_e;
+
+/**
+* @brief Enumerations for audio type.
+* @since_tizen 3.0
+*/
+typedef enum {
+ STTE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
+ STTE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */
+} stte_audio_type_e;
+
+/**
+* @brief Enumerations for callback event.
+* @since_tizen 3.0
+*/
+typedef enum {
+ STTE_RESULT_EVENT_FINAL_RESULT = 0, /**< Event when either the full matched or the final result is delivered */
+ STTE_RESULT_EVENT_PARTIAL_RESULT, /**< Event when the partial matched result is delivered */
+ STTE_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
+} stte_result_event_e;
+
+/**
+* @brief Enumerations for result time callback event.
+* @since_tizen 3.0
+*/
+typedef enum {
+ STTE_RESULT_TIME_EVENT_BEGINNING = 0, /**< Event when the token is beginning type */
+ STTE_RESULT_TIME_EVENT_MIDDLE, /**< Event when the token is middle type */
+ STTE_RESULT_TIME_EVENT_END /**< Event when the token is end type */
+} stte_result_time_event_e;
+
+/**
+* @brief Enumerations for speech status.
+* @since_tizen 3.0
+*/
+typedef enum {
+ STTE_SPEECH_STATUS_BEGINNING_POINT_DETECTED = 0, /**< Beginning point of speech is detected */
+ STTE_SPEECH_STATUS_END_POINT_DETECTED /**< End point of speech is detected */
+} stte_speech_status_e;
+
+/**
+* @brief Definition for free form dictation and default type.
+* @since_tizen 3.0
+*/
+#define STTE_RECOGNITION_TYPE_FREE "stt.recognition.type.FREE"
+
+/**
+* @brief Definition for free form dictation continuously.
+* @since_tizen 3.0
+*/
+#define STTE_RECOGNITION_TYPE_FREE_PARTIAL "stt.recognition.type.FREE.PARTIAL"
+
+/**
+* @brief Definition for None message.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_NONE "stt.result.message.none"
+
+/**
+* @brief Definition for failed recognition because the speech started too soon.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon"
+
+/**
+* @brief Definition for failed recognition because the speech started too short.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short"
+
+/**
+* @brief Definition for failed recognition because the speech started too long.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long"
+
+/**
+* @brief Definition for failed recognition because the speech started too quiet to listen.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet"
+
+/**
+* @brief Definition for failed recognition because the speech started too loud to listen.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud"
+
+/**
+* @brief Definition for failed recognition because the speech started too fast to listen.
+* @since_tizen 3.0
+*/
+#define STTE_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast"
+
+
+/**
+* @brief Called when STT engine provides the time stamp of result to the engine service user.
+* @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
+* @since_tizen 3.0
+*
+* @remarks This callback function is called in stte_foreach_result_time_cb() for adding time information.
+* @a user_data must be transferred from stte_foreach_result_time_cb().
+*
+* @param[in] index The result index
+* @param[in] event The token event
+* @param[in] text The result text
+* @param[in] start_time The time started speaking the result text
+* @param[in] end_time The time finished speaking the result text
+* @param[in] user_data The user data passed from stte_foreach_result_time_cb()
+*
+* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
+*
+* @pre stte_send_result() should be called.
+*
+* @see stte_send_result()
+* @see stte_foreach_result_time_cb()
+*/
+typedef bool (*stte_result_time_cb)(int index, stte_result_time_event_e event, const char* text,
+ long start_time, long end_time, void* user_data);
+
+
+/**
+* @brief Called when STT engine informs the engine service user about whole supported language list.
+* @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
+* @since_tizen 3.0
+*
+* @remarks This callback function is called in stte_foreach_supported_langs_cb() to inform the whole supported language list.
+* @a user_data must be transferred from stte_foreach_supported_langs_cb().
+*
+* @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
+* followed by ISO 639-1 for the two-letter language code \n
+* For example, "ko_KR" for Korean, "en_US" for American English
+* @param[in] user_data The user data passed from stte_foreach_supported_langs_cb()
+*
+* @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
+*
+* @pre stte_foreach_supported_langs_cb() will invoke this callback function.
+*
+* @see stte_foreach_supported_langs_cb()
+*/
+typedef bool (*stte_supported_language_cb)(const char* language, void* user_data);
+
+/**
+* @brief Called when the engine service user initializes STT engine.
+* @details This callback function is called by the engine service user to request for STT engine to be started.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_INVALID_STATE Already initialized
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @see stte_deinitialize_cb()
+*/
+typedef int (*stte_initialize_cb)(void);
+
+/**
+* @brief Called when the engine service user deinitializes STT engine
+* @details This callback function is called by the engine service user to request for STT engine to be deinitialized.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* NOTE that the engine may be terminated automatically.
+* When this callback function is invoked, the release of resources is necessary.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+*
+* @see stte_initialize_cb()
+*/
+typedef int (*stte_deinitialize_cb)(void);
+
+/**
+* @brief Called when the engine service user gets the whole supported language list.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* In this function, the engine service user's callback function 'stte_supported_language_cb()' is invoked repeatedly for getting all supported languages, and @a user_data must be transferred to 'stte_supported_language_cb()'.
+* If 'stte_supported_language_cb()' returns @c false, it should be stopped to call 'stte_supported_language_cb()'.
+*
+* @param[in] callback The callback function
+* @param[in] user_data The user data which must be passed to the callback function 'stte_supported_language_cb()'
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+*
+* @post This callback function invokes stte_supported_language_cb() repeatedly for getting supported languages.
+*
+* @see stte_supported_language_cb()
+*/
+typedef int (*stte_foreach_supported_langs_cb)(stte_supported_language_cb callback, void* user_data);
+
+/**
+* @brief Called when the engine service user checks whether the corresponding language is valid or not in STT engine.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
+* followed by ISO 639-1 for the two-letter language code \n
+* For example, "ko_KR" for Korean, "en_US" for American English
+* @param[out] is_valid A variable for checking whether the corresponding language is valid or not. \n @c true to be valid, @c false to be invalid.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @see stte_foreach_supported_languages_cb()
+*/
+typedef int (*stte_is_valid_language_cb)(const char* language, bool* is_valid);
+
+/**
+* @brief Called when the engine service user checks whether STT engine supports silence detection.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @return @c true to support silence detection, @c false not to support silence detection
+*
+* @see stte_set_silence_detection_cb()
+*/
+typedef bool (*stte_support_silence_detection_cb)(void);
+
+/**
+* @brief Called when the engine service user checks whether STT engine supports the corresponding recognition type.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @param[in] type The type for recognition (e.g. #STTE_RECOGNITION_TYPE_FREE)
+* @param[out] is_supported A variable for checking whether STT engine supports the corresponding recognition type. \n @c true to support recognition type, @c false not to support recognition type.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+*
+*/
+typedef int (*stte_support_recognition_type_cb)(const char* type, bool* is_supported);
+
+/**
+* @brief Called when the engine service user gets the proper recording format of STT engine.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* The recording format is used for creating the recorder.
+*
+* @param[out] types The format used by the recorder.
+* @param[out] rate The sample rate used by the recorder.
+* @param[out] channels The number of channels used by the recorder.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+*/
+typedef int (*stte_get_recording_format_cb)(stte_audio_type_e* types, int* rate, int* channels);
+
+/**
+* @brief Called when the engine service user sets the silence detection.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* If the engine service user sets this option as 'TRUE', STT engine will detect the silence (EPD) and send the callback event about it.
+*
+* @param[in] is_set A variable for setting the silence detection. \n @c true to detect the silence, @c false not to detect the silence.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+* @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
+*/
+typedef int (*stte_set_silence_detection_cb)(bool is_set);
+
+/**
+* @brief Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine.
+* @details This callback function is called when the engine service user requests for STT engine to check the application's agreement about using the engine.
+* According to the need, the engine developer can provide some user interfaces to check the agreement.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* If the STT engine developer wants not to check the agreement, the developer has need to return proper values as @a is_agreed in accordance with the intention. \n @c true if the developer regards that every application agreed the usage of the engine, @c false if the developer regards that every application disagreed.
+* NOTE that, however, there may be any legal issue unless the developer checks the agreement. Therefore, we suggest that the engine developers should provide a function to check the agreement.
+*
+* @param[in] appid The Application ID
+* @param[out] is_agreed A variable for checking whether the application agreed to use STT engine or not. \n @c true to agree, @c false to disagree.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+* @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
+*/
+typedef int (*stte_check_app_agreed_cb)(const char* appid, bool* is_agreed);
+
+/**
+* @brief Called when the engine service user checks whether STT engine needs the application's credential.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @return @c true if STT engine needs the application's credential, otherwise @c false
+*/
+typedef bool (*stte_need_app_credential_cb)(void);
+
+/**
+* @brief Called when the engine service user gets the result time information(stamp).
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* In this function, the engine service user's callback function 'stte_result_time_cb()' is invoked repeatedly for sending the time information to the engine service user, and @a user_data must be transferred to 'stte_result_time_cb()'.
+* If 'stte_result_time_cb()' returns @c false, it should be stopped to call 'stte_result_time_cb()'.
+* @a time_info is transferred from stte_send_result(). The type of @a time_info is up to the STT engine developer.
+*
+* @param[in] time_info The time information
+* @param[in] callback The callback function
+* @param[in] user_data The user data which must be passed to the callback function 'stte_result_time_cb()'
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_INVALID_STATE Not initialized
+*
+* @pre stte_send_result() will invoke this function.
+* @post This function invokes stte_result_time_cb() repeatedly for getting result time information.
+*
+* @see stte_result_time_cb()
+*/
+typedef int (*stte_foreach_result_time_cb)(void* time_info, stte_result_time_cb callback, void* user_data);
+
+/**
+* @brief Called when the engine service user starts to recognize the recording data.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* In this callback function, STT engine must transfer the recognition result and @a user_data to the engine service user using stte_send_result().
+* Also, if STT engine needs the application's credential, it sets the credential granted to the application.
+*
+* @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
+* followed by ISO 639-1 for the two-letter language code \n
+* For example, "ko_KR" for Korean, "en_US" for American English
+* @param[in] type The recognition type. (e.g. #STTE_RECOGNITION_TYPE_FREE)
+* @param[in] appid The Application ID
+* @param[in] credential The credential granted to the application
+* @param[in] user_data The user data to be passed to the callback function.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_INVALID_STATE Invalid state
+* @retval #STTE_ERROR_INVALID_LANGUAGE Invalid language
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+* @retval #STTE_ERROR_NETWORK_DOWN Out of network
+*
+* @pre The engine is not in recognition processing.
+*
+* @see stte_set_recording_data_cb()
+* @see stte_stop_cb()
+* @see stte_cancel_cb()
+* @see stte_need_app_credential_cb()
+*/
+typedef int (*stte_start_cb)(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
+
+/**
+* @brief Called when the engine service user sets and sends the recording data for speech recognition.
+* @details This callback function is called by the engine service user to send the recording data to STT engine.
+* The engine receives the recording data and uses for speech recognition.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* Also, this function should be returned immediately after recording data copy.
+*
+* @param[in] data The recording data
+* @param[in] length The length of recording data
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_INVALID_STATE Invalid state
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre stte_start_cb() should succeed.
+* @post If the engine supports partial result, stte_send_result() should be invoked.
+*
+* @see stte_start_cb()
+* @see stte_cancel_cb()
+* @see stte_stop_cb()
+*/
+typedef int (*stte_set_recording_data_cb)(const void* data, unsigned int length);
+
+/**
+* @brief Called when the engine service user stops to recognize the recording data.
+* @details This callback function is called by the engine service user to stop recording and to get the recognition result.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_STATE Invalid state
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+* @retval #STTE_ERROR_NETWORK_DOWN Out of network
+*
+* @pre stte_start_cb() should succeed.
+* @post After processing of the engine, stte_send_result() must be called.
+*
+* @see stte_start_cb()
+* @see stte_set_recording_data_cb()
+* @see stte_cancel_cb()
+* @see stte_send_result()
+*/
+typedef int (*stte_stop_cb)(void);
+
+/**
+* @brief Called when the engine service user cancels to recognize the recording data.
+* @details This callback function is called by the engine service user to cancel to recognize the recording data.
+* Also, when starting the recorder is failed, this function is called.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #STTE_ERROR_NONE Successful.
+* @retval #STTE_ERROR_INVALID_STATE Invalid state.
+*
+* @pre STT engine is in recognition processing or recording.
+*
+* @see stte_start_cb()
+* @see stte_stop_cb()
+*/
+typedef int (*stte_cancel_cb)(void);
+
+/**
+* @brief Called when the engine service user requests the basic information of STT engine.
+* @since_tizen 3.0
+*
+* @remarks This callback function is mandatory and must be registered using stte_main().
+* The allocated @a engine_uuid, @a engine_name, and @a engine_setting will be released internally.
+* In order to upload the engine at Tizen Appstore, both a service app and a ui app are necessary.
+* Therefore, @a engine_setting must be transferred to the engine service user.
+*
+* @param[out] engine_uuid UUID of engine
+* @param[out] engine_name Name of engine
+* @param[out] engine_setting The engine setting application(ui app)'s app id
+* @param[out] use_network A variable for checking whether the network is used or not
+*
+* @return 0 on success, otherwise a negative error code on failure
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+*/
+typedef int (*stte_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
+
+/**
+* @brief Called when STT engine receives the private data from the engine service user.
+* @details This callback function is called when the engine service user sends the private data to STT engine.
+* @since_tizen 3.0
+*
+* @remarks This callback function is optional and is registered using stte_set_private_data_set_cb().
+*
+* @param[in] key The key field of private data.
+* @param[in] data The data field of private data.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @see stte_private_data_requested_cb()
+* @see stte_set_private_data_set_cb()
+*/
+typedef int (*stte_private_data_set_cb)(const char* key, const char* data);
+
+/**
+* @brief Called when STT engine provides the engine service user with the private data.
+* @details This callback function is called when the engine service user gets the private data from STT engine.
+* @since_tizen 3.0
+*
+* @remarks This callback function is optional and is registered using stte_set_private_data_requested_cb().
+*
+* @param[out] key The key field of private data.
+* @param[out] data The data field of private data.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @see stte_private_data_set_cb()
+* @see stte_set_private_data_requested_cb()
+*/
+typedef int (*stte_private_data_requested_cb)(const char* key, char** data);
+
+/**
+* @brief A structure for the STT engine functions.
+* @details This structure contains essential callback functions for operating STT engine.
+* @since_tizen 3.0
+*
+* @remarks These functions are mandatory for operating STT engine. Therefore, all functions MUST be implemented.
+*/
+typedef struct {
+ int version; /**< The version of the structure 'stte_request_callback_s' */
+ stte_get_info_cb get_info; /**< Called when the engine service user requests the basic information of STT engine */
+
+ stte_initialize_cb initialize; /**< Called when the engine service user initializes STT engine */
+ stte_deinitialize_cb deinitialize; /**< Called when the engine service user deinitializes STT engine */
+
+ stte_foreach_supported_langs_cb foreach_langs; /**< Called when the engine service user gets the whole supported language list */
+ stte_is_valid_language_cb is_valid_lang; /**< Called when the engine service user checks whether the corresponding language is valid or not*/
+ stte_support_silence_detection_cb support_silence; /**< Called when the engine service user checks whether STT engine supports silence detection*/
+ stte_support_recognition_type_cb support_recognition_type; /**< Called when the engine service user checks whether STT engine supports the corresponding recognition type */
+ stte_get_recording_format_cb get_audio_format; /**< Called when the engine service user gets the proper recording format of STT engine */
+ stte_foreach_result_time_cb foreach_result_time; /**< Called when the engine service user gets the result time information(stamp) */
+
+ stte_set_silence_detection_cb set_silence_detection; /**< Called when the engine service user sets the silence detection */
+
+ stte_start_cb start; /**< Called when the engine service user starts to recognize the recording data */
+ stte_set_recording_data_cb set_recording; /**< Called when the engine service user sets and sends the recording data for speech recognition */
+ stte_stop_cb stop; /**< Called when the engine service user stops to recognize the recording data */
+ stte_cancel_cb cancel; /**< Called when the engine service user cancels to recognize the recording data */
+
+ stte_check_app_agreed_cb check_app_agreed; /**< Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine */
+ stte_need_app_credential_cb need_app_credential; /**< Called when the engine service user checks whether STT engine needs the application's credential */
+} stte_request_callback_s;
+
+/**
+* @brief Main function for Speech-To-Text (STT) engine.
+* @details This function is the main function for operating STT engine.
+* @since_tizen 3.0
+*
+* @privlevel public
+* @privilege %http://tizen.org/privilege/recorder
+*
+* @remarks The service_app_main() should be used for working the engine after this function.
+*
+* @param[in] argc The argument count(original)
+* @param[in] argv The argument(original)
+* @param[in] callback The structure of engine request callback function
+*
+* @return This function returns zero on success, or negative with error code on failure
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @see stte_request_callback_s
+*
+* @code
+#include <stte.h>
+
+// Required callback functions - MUST BE IMPLEMENTED
+static int sttengine_get_info_cb(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
+static int sttengine_initialize_cb(void);
+static int sttengine_deinitialize_cb(void);
+static int sttengine_is_valid_language_cb(const char* language, bool* is_valid);
+static int sttengine_foreach_supported_langs_cb(stte_supported_language_cb callback, void* user_data);
+static bool sttengine_support_silence_detection_cb(void);
+static int sttengine_set_silence_detection_cb(bool is_set);
+static int sttengine_support_recognition_type_cb(const char* type, bool* is_supported);
+static int sttengine_get_recording_format_cb(stte_audio_type_e* types, int* rate, int* channels);
+static int sttengine_set_recording_data_cb(const void* data, unsigned int length);
+static int sttengine_foreach_result_time_cb(void* time_info, stte_result_time_cb callback, void* user_data);
+static int sttengine_start_cb(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
+static int sttengine_stop_cb(void);
+static int sttengine_cancel_cb(void);
+static int sttengine_check_app_agreed_cb(const char* appid, bool* is_agreed);
+static bool sttengine_need_app_credential_cb(void);
+
+// Optional callback function
+static int sttengine_private_data_set_cb(const char* key, const char* data);
+
+int main(int argc, char* argv[])
+{
+ // 1. Create a structure 'stte_request_callback_s'
+ stte_request_callback_s engine_callback = { 0, };
+
+ engine_callback.size = sizeof(stte_request_callback_s);
+ engine_callback.version = 1;
+ engine_callback.get_info = sttengine_get_info_cb;
+
+ engine_callback.initialize = sttengine_initialize_cb;
+ engine_callback.deinitialize = sttengine_deinitialize_cb;
+
+ engine_callback.foreach_langs = sttengine_foreach_supported_langs_cb;
+ engine_callback.is_valid_lang = sttengine_is_valid_language_cb;
+ engine_callback.support_silence = sttengine_support_silence_detection_cb;
+ engine_callback.support_recognition_type = sttengine_support_recognition_type_cb;
+
+ engine_callback.get_audio_format = sttengine_get_recording_format_cb;
+ engine_callback.foreach_result_time = sttengine_foreach_result_time_cb;
+
+ engine_callback.set_silence_detection = sttengine_set_silence_detection_cb;
+
+ engine_callback.start = sttengine_start_cb;
+ engine_callback.set_recording = sttengine_set_recording_data_cb;
+ engine_callback.stop = sttengine_stop_cb;
+ engine_callback.cancel = sttengine_cancel_cb;
+
+ engine_callback.check_app_agreed = sttengine_check_app_agreed_cb;
+ engine_callback.need_app_credential = sttengine_need_app_credential_cb;
+
+ // 2. Run 'stte_main()'
+ if (0 != stte_main(argc, argv, &engine_callback)) {
+ return -1;
+ }
+
+ // Optional
+ stte_set_private_data_set_cb(sttengine_private_data_set_cb);
+
+ // 3. Set event callbacks for service app and Run 'service_app_main()'
+ char ad[50] = { 0, };
+
+ service_app_lifecycle_callback_s event_callback;
+ app_event_handler_h handlers[5] = { NULL, };
+
+ event_callback.create = service_app_create;
+ event_callback.terminate = service_app_terminate;
+ event_callback.app_control = service_app_control;
+
+ service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
+ service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
+ service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
+ service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
+
+ return service_app_main(argc, argv, &event_callback, ad);
+}
+
+* @endcode
+*/
+int stte_main(int argc, char** argv, stte_request_callback_s *callback);
+
+
+/**
+* @brief Sends the recognition result to the engine service user.
+* @since_tizen 3.0
+*
+* @remarks This API is used in stte_set_recording_data_cb() and stte_stop_cb(), when STT engine sends the recognition result to the engine service user.
+* This function is called in the following situations; 1) after stte_stop_cb() is called, 2) the end point of speech is detected from recording, or 3) partial result is occurred.
+* The recognition result and @a user_data must be transferred to the engine service user through this function.
+* Also, @a time_info must be transferred to stte_foreach_result_time_cb(). The type of @a time_info is up to the STT engine developer.
+*
+* @param[in] event The result event
+* @param[in] type The recognition type (e.g. #STTE_RECOGNITION_TYPE_FREE, #STTE_RECOGNITION_TYPE_FREE_PARTIAL)
+* @param[in] result Result texts
+* @param[in] result_count Result text count
+* @param[in] msg Engine message (e.g. #STTE_RESULT_MESSAGE_NONE, #STTE_RESULT_MESSAGE_ERROR_TOO_SHORT)
+* @param[in] time_info The time information
+* @param[in] user_data The user data passed from stte_start_cb()
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The stte_main() function should be invoked before this function is called.
+* stte_stop_cb() will invoke this function.
+* @post This function invokes stte_foreach_result_time_cb().
+*
+* @see stte_start_cb()
+* @see stte_set_recording_data_cb()
+* @see stte_stop_cb()
+* @see stte_foreach_result_time_cb()
+*/
+int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
+ const char* msg, void* time_info, void* user_data);
+
+
+/**
+* @brief Sends the error to the engine service user.
+* @details The following error codes can be delivered.\n
+* #STTE_ERROR_NONE,\n
+* #STTE_ERROR_OUT_OF_MEMORY,\n
+* #STTE_ERROR_IO_ERROR,\n
+* #STTE_ERROR_INVALID_PARAMETER,\n
+* #STTE_ERROR_NETWORK_DOWN,\n
+* #STTE_ERROR_INVALID_STATE,\n
+* #STTE_ERROR_INVALID_LANGUAGE,\n
+* #STTE_ERROR_OPERATION_FAILED,\n
+* #STTE_ERROR_NOT_SUPPORTED_FEATURE,\n
+* #STTE_ERROR_NOT_SUPPORTED,\n
+* #STTE_ERROR_PERMISSION_DENIED,\n
+* #STTE_ERROR_RECORDING_TIMED_OUT.\n
+*
+* @since_tizen 3.0
+*
+* @param[in] error The error reason
+* @param[in] msg The error message
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The stte_main() function should be invoked before this function is called.
+*/
+int stte_send_error(stte_error_e error, const char* msg);
+
+/**
+* @brief Sends the speech status to the engine service user when STT engine notifies the change of the speech status.
+* @since_tizen 3.0
+*
+* @remarks This API is invoked when STT engine wants to notify the change of the speech status anytime.
+* NOTE that this API can be invoked for recognizing the speech.
+*
+* @param[in] status The status of speech (e.g. STTE_SPEECH_STATUS_START_POINT_DETECTED or STTE_SPEECH_STATUS_END_POINT_DETECTED)
+* @param[in] user_data The user data passed from the start function.
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The stte_main() function should be invoked before this function is called.
+* stte_start_cb() and stte_set_recording_data_cb() will invoke this function.
+*
+* @see stte_start_cb()
+* @see stte_set_recording_data_cb()
+*/
+int stte_send_speech_status(stte_speech_status_e status, void* user_data);
+
+
+/**
+* @brief Sets a callback function for setting the private data.
+* @since_tizen 3.0
+*
+* @privlevel public
+* @privilege %http://tizen.org/privilege/recorder
+*
+* @remarks The stte_private_data_set_cb() function is called when the engine service user sends the private data.
+*
+* @param[in] callback_func stte_private_data_set event callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The stte_main() function should be invoked before this function is called.
+*
+* @see stte_private_data_set_cb()
+*/
+int stte_set_private_data_set_cb(stte_private_data_set_cb callback_func);
+
+/**
+* @brief Sets a callback function for requesting the private data.
+* @since_tizen 3.0
+*
+* @privlevel public
+* @privilege %http://tizen.org/privilege/recorder
+*
+* @remarks The stte_private_data_requested_cb() function is called when the engine service user gets the private data from STT engine.
+*
+* @param[in] callback_func stte_private_data_requested event callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #STTE_ERROR_NONE Successful
+* @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
+* @retval #STTE_ERROR_NOT_SUPPORTED Not supported
+* @retval #STTE_ERROR_OPERATION_FAILED Operation failure
+*
+* @pre The stte_main() function should be invoked before this function is called.
+*
+* @see stte_private_data_requested_cb()
+*/
+int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback_func);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}@}
+ */
+
+#endif /* __STT_ENGINE_MAIN_H__ */
[D-BUS Service]
Name=org.tizen.voice.sttserver
-Exec=/usr/bin/stt-daemon
+Exec=/bin/sh -c "launch_app org.tizen.stt-engine-default"
+
Name: stt
Summary: Speech To Text client library and daemon
-Version: 0.2.55
+Version: 0.2.56
Release: 1
Group: Graphics & UI Framework/Voice Framework
License: Apache-2.0
%license LICENSE.APLv2
%defattr(-,root,root,-)
%{_libdir}/lib*.so
-%{_bindir}/stt-daemon
/etc/dbus-1/session.d/stt-server.conf
%{TZ_SYS_RO_SHARE}/voice/stt/1.0/stt-config.xml
%{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice*
%files engine-devel
%defattr(-,root,root,-)
%{_libdir}/pkgconfig/stt-engine.pc
-%{_includedir}/sttp.h
+%{_includedir}/stte.h
sttd_dbus_server.c
sttd_dbus.c
sttd_engine_agent.c
- sttd_main.c
+ stte.c
sttd_recorder.c
sttd_server.c
../common/stt_config_mgr.c
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/server)
+INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE")
-SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+#SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE")
+#SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE")
+#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
## Executable ##
-ADD_EXECUTABLE("${PROJECT_NAME}-daemon" ${SRCS})
-TARGET_LINK_LIBRARIES("${PROJECT_NAME}-daemon" -ldl -lm ${pkgs_LDFLAGS})
+ADD_LIBRARY("${PROJECT_NAME}_engine" SHARED ${SRCS})
+#TARGET_LINK_LIBRARIES("${PROJECT_NAME}_engine" -ldl -lm ${pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES("${PROJECT_NAME}_engine" ${pkgs_LDFLAGS})
## Install
-INSTALL(TARGETS "${PROJECT_NAME}-daemon" DESTINATION bin)
+INSTALL(TARGETS "${PROJECT_NAME}_engine" DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
return;
}
-int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
- sttd_config_language_changed_cb lang_cb,
- sttd_config_silence_changed_cb silence_cb,
+int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
+ sttd_config_language_changed_cb lang_cb,
+ sttd_config_silence_changed_cb silence_cb,
void* user_data)
{
if (NULL == engine_cb || NULL == lang_cb || NULL == silence_cb) {
return -1;
}
- ret = stt_config_mgr_set_callback(getpid(), __sttd_config_engine_changed_cb, __sttd_config_lang_changed_cb,
+ ret = stt_config_mgr_set_callback(getpid(), __sttd_config_engine_changed_cb, __sttd_config_lang_changed_cb,
__config_bool_changed_cb, NULL);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to set config changed : %d", ret);
typedef void (*sttd_config_silence_changed_cb)(bool value, void* user_data);
-int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
- sttd_config_language_changed_cb lang_cb,
- sttd_config_silence_changed_cb silence_cb,
+int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
+ sttd_config_language_changed_cb lang_cb,
+ sttd_config_silence_changed_cb silence_cb,
void* user_data);
int sttd_config_finalize();
int uid;
char* key;
char* data;
- int ret = 0;
+ int ret = STTD_ERROR_OPERATION_FAILED;
dbus_message_get_args(msg, &err,
DBUS_TYPE_INT32, &uid,
DBUS_TYPE_STRING, &key,
}
if (!dbus_connection_send(conn, reply, NULL)) {
- SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to send reply");
+ SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
}
dbus_connection_flush(conn);
int uid;
char* key = NULL;
char* data = NULL;
-
- int ret = 0;
+ int ret = STTD_ERROR_OPERATION_FAILED;
dbus_message_get_args(msg, &err,
DBUS_TYPE_INT32, &uid,
DBUS_TYPE_STRING, &key,
}
if (!dbus_connection_send(conn, reply, NULL)) {
- SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to send reply");
+ SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Out Of Memory!");
}
dbus_connection_flush(conn);
#include "sttd_main.h"
#include "sttd_client_data.h"
#include "sttd_config.h"
+#include "sttd_dbus.h"
#include "sttd_recorder.h"
#include "sttd_engine_agent.h"
* Internal data structure
*/
-typedef struct {
- int uid;
- int engine_id;
- bool use_default_engine;
-} sttengine_client_s;
-
typedef struct _sttengine_info {
- int engine_id;
-
char* engine_uuid;
char* engine_path;
char* engine_name;
/** stt engine agent init */
static bool g_agent_init;
-/** list */
-static GSList* g_engine_client_list;
-static GSList* g_engine_list;
+static sttengine_info_s* g_engine_info = NULL;
/** default engine info */
-static int g_default_engine_id;
-static char* g_default_language;
+static char* g_default_language = NULL;
static bool g_default_silence_detected;
-static int g_engine_id_count;
-
-/** current engine id */
-static int g_recording_engine_id;
-
/** callback functions */
-static result_callback g_result_cb;
-static result_time_callback g_result_time_cb;
-static silence_dectection_callback g_silence_cb;
-
+static result_callback g_result_cb = NULL;
+static result_time_callback g_result_time_cb = NULL;
+static speech_status_callback g_speech_status_cb = NULL;
+static error_callback g_error_cb = NULL;
/** callback functions */
-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, stte_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,
- bool use_network, void* user_data);
-
/*
* Internal Interfaces
*/
/** get engine info */
-int __internal_get_engine_info(const char* filepath, sttengine_info_s** info);
+int __internal_get_engine_info(stte_request_callback_s *callback, sttengine_info_s** info);
int __log_enginelist();
* STT Engine Agent Interfaces
*/
int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb,
- silence_dectection_callback silence_cb)
+ speech_status_callback speech_status_cb, error_callback error_cb)
{
/* initialize static data */
- if (NULL == result_cb || NULL == time_cb || NULL == silence_cb) {
+ if (NULL == result_cb || NULL == time_cb || NULL == speech_status_cb || NULL == error_cb) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] Invalid parameter");
return STTD_ERROR_INVALID_PARAMETER;
}
g_result_cb = result_cb;
g_result_time_cb = time_cb;
- g_silence_cb = silence_cb;
+ g_speech_status_cb = speech_status_cb;
+ g_error_cb = error_cb;
- g_default_engine_id = -1;
g_default_language = NULL;
- g_engine_id_count = 1;
- 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");
g_default_silence_detected = (bool)temp;
}
- g_agent_init = false;
+ g_agent_init = true;
return 0;
}
if (NULL != engine->first_lang) free(engine->first_lang);
free(engine);
+ engine = NULL;
}
return 0;
int sttd_engine_agent_release()
{
- /* Release client list */
- GSList *iter = NULL;
- sttengine_client_s *client = NULL;
+ if (NULL != g_engine_info) {
+ if (g_engine_info->is_loaded) {
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine");
- if (g_slist_length(g_engine_client_list) > 0) {
- /* Get a first item */
- iter = g_slist_nth(g_engine_client_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- client = iter->data;
- g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
-
- if (NULL != client)
- free(client);
-
- iter = g_slist_nth(g_engine_client_list, 0);
- }
- }
-
- g_slist_free(g_engine_client_list);
-
- /* Release engine list */
- sttengine_info_s *engine = NULL;
-
- if (0 < g_slist_length(g_engine_list)) {
- /* Get a first item */
- iter = g_slist_nth(g_engine_list, 0);
+ if (0 != stt_engine_deinitialize()) {
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize");
+ }
- while (NULL != iter) {
- /* Get handle data from list */
- engine = iter->data;
- g_engine_list = g_slist_remove_link(g_engine_list, iter);
+ if (0 != stt_engine_unload()) {
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine");
+ }
- /* Check engine unload */
- if (engine->is_loaded) {
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", engine->engine_id);
+ if (NULL != g_engine_info->engine_uuid) {
+ free(g_engine_info->engine_uuid);
+ g_engine_info->engine_uuid = NULL;
+ }
- 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 (NULL != g_engine_info->engine_path) {
+ free(g_engine_info->engine_path);
+ g_engine_info->engine_path = NULL;
+ }
- if (0 != stt_engine_unload(engine->engine_id))
- SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
+ if (NULL != g_engine_info->engine_name) {
+ free(g_engine_info->engine_name);
+ g_engine_info->engine_name = NULL;
+ }
- engine->is_loaded = false;
+ if (NULL != g_engine_info->engine_setting_path) {
+ free(g_engine_info->engine_setting_path);
+ g_engine_info->engine_setting_path = NULL;
}
- __engine_agent_clear_engine(engine);
+ if (NULL != g_engine_info->first_lang) {
+ free(g_engine_info->first_lang);
+ g_engine_info->first_lang = NULL;
+ }
- iter = g_slist_nth(g_engine_list, 0);
+ g_engine_info->is_loaded = false;
}
+
+ __engine_agent_clear_engine(g_engine_info);
}
g_result_cb = NULL;
- g_silence_cb = NULL;
+ g_speech_status_cb = NULL;
+ g_error_cb = NULL;
+ g_result_time_cb = NULL;
g_agent_init = false;
- g_default_engine_id = -1;
return 0;
}
-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;
-
- temp->engine_uuid = g_strdup(engine_uuid);
- temp->engine_name = g_strdup(engine_name);
- temp->engine_setting_path = g_strdup(setting_ug_name);
- temp->use_network = use_network;
-}
-
-int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
+int __internal_get_engine_info(stte_request_callback_s *callback, sttengine_info_s** info)
{
- if (NULL == filepath || NULL == info) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- /* load engine */
- char *error;
- void* handle;
-
- handle = dlopen(filepath, RTLD_LAZY);
-
- if (!handle) {
- 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);
- 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);
- dlclose(handle);
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
-
- int (*get_engine_info)(sttpe_engine_info_cb callback, void* user_data);
-
- 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);
- dlclose(handle);
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
-
sttengine_info_s* temp;
temp = (sttengine_info_s*)calloc(1, sizeof(sttengine_info_s));
if (NULL == temp) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
- dlclose(handle);
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] fail to allocate memory");
return STTD_ERROR_OUT_OF_MEMORY;
}
- /* 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");
- dlclose(handle);
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid engine");
free(temp);
return STTD_ERROR_ENGINE_NOT_FOUND;
}
- /* close engine */
- dlclose(handle);
+ if (NULL == callback->get_info) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid engine");
+ free(temp);
+ return STTD_ERROR_ENGINE_NOT_FOUND;
+ }
- temp->engine_id = g_engine_id_count;
- g_engine_id_count++;
+ if (0 != callback->get_info(&(temp->engine_uuid), &(temp->engine_name), &(temp->engine_setting_path), &(temp->use_network))) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info");
+ free(temp);
+ return STTD_ERROR_ENGINE_NOT_FOUND;
+ }
- temp->engine_path = g_strdup(filepath);
+ /* todo - removed? */
+ temp->engine_path = strdup("empty");
temp->is_loaded = false;
SLOG(LOG_DEBUG, TAG_STTD, "----- Valid Engine");
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine id : %d", temp->engine_id);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", temp->engine_uuid);
- 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");
+ SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", (NULL == temp->engine_uuid) ? "NULL" : temp->engine_uuid);
+ SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", (NULL == temp->engine_name) ? "NULL" : temp->engine_name);
+ SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", (NULL == temp->engine_path) ? "NULL" : temp->engine_path);
+ SLOG(LOG_DEBUG, TAG_STTD, "Engine setting path : %s", (NULL == temp->engine_setting_path) ? "NULL" : temp->engine_setting_path);
+ SLOG(LOG_DEBUG, TAG_STTD, "Use network : %s", temp->use_network ? "true" : "false");
SLOG(LOG_DEBUG, TAG_STTD, "-----");
SLOG(LOG_DEBUG, TAG_STTD, " ");
bool __is_engine(const char* filepath)
{
- GSList *iter = NULL;
- sttengine_info_s *engine = NULL;
-
- if (0 < g_slist_length(g_engine_list)) {
- /* Get a first item */
- iter = g_slist_nth(g_engine_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- engine = iter->data;
-
- if (0 == strcmp(engine->engine_path, filepath)) {
- return true;
- }
+ if (NULL == filepath) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No filepath");
+ return false;
+ }
- iter = g_slist_next(iter);
+ if (NULL != g_engine_info) {
+ if (!strcmp(g_engine_info->engine_path, filepath)) {
+ return true;
}
}
return false;
}
-int sttd_engine_agent_initialize_engine_list()
+int __engine_agent_check_engine_unload()
{
- /* Get file name from default engine directory */
- DIR *dp = NULL;
- int ret = -1;
- struct dirent entry;
- struct dirent *dirp = NULL;
-
- dp = opendir(STT_DEFAULT_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_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
- filepath = (char*)calloc(filesize, sizeof(char));
+ /* Check the count of client to use this engine */
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No engine");
+ } else {
+ if (g_engine_info->is_loaded) {
+ /* unload engine */
+#ifndef AUDIO_CREATE_ON_START
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
+#endif
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine");
+ if (0 != stt_engine_deinitialize())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize engine");
- if (NULL != filepath) {
- snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE, dirp->d_name);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!");
- continue;
- }
+ if (0 != stt_engine_unload())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine");
- if (false == __is_engine(filepath)) {
- /* 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);
- }
- }
+ g_engine_info->is_loaded = false;
+ }
+ }
- if (NULL != filepath)
- free(filepath);
- }
- } while (NULL != dirp);
+ return 0;
+}
- closedir(dp);
- } else {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory");
+int sttd_engine_agent_load_current_engine(stte_request_callback_s *callback)
+{
+ if (false == g_agent_init) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ return STTD_ERROR_OPERATION_FAILED;
}
- if (0 >= g_slist_length(g_engine_list)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
- return STTD_ERROR_ENGINE_NOT_FOUND;
+ /* Get current engine info */
+ sttengine_info_s* info;
+ int ret = __internal_get_engine_info(callback, &info);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine info");
+ return ret;
+ } else {
+ g_engine_info = info;
}
__log_enginelist();
/* Set default engine */
- GSList *iter = NULL;
- sttengine_info_s *engine = NULL;
char* cur_engine_uuid = NULL;
bool is_default_engine = false;
/* get current engine from config */
if (0 == sttd_config_get_default_engine(&cur_engine_uuid)) {
SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] current engine from config : %s", cur_engine_uuid);
-
- if (0 < g_slist_length(g_engine_list)) {
- /* Get a first item */
- iter = g_slist_nth(g_engine_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- engine = iter->data;
-
- if (0 == strcmp(engine->engine_uuid, cur_engine_uuid)) {
- is_default_engine = true;
- g_default_engine_id = engine->engine_id;
- break;
- }
-
- iter = g_slist_next(iter);
+ if (NULL != g_engine_info->engine_uuid) {
+ if (!strcmp(g_engine_info->engine_uuid, cur_engine_uuid)) {
+ is_default_engine = true;
}
}
-
- if (cur_engine_uuid != NULL)
+ if (NULL != cur_engine_uuid) {
free(cur_engine_uuid);
+ cur_engine_uuid = NULL;
+ }
} else {
SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is not current engine from config");
}
if (false == is_default_engine) {
- if (0 < g_slist_length(g_engine_list)) {
- /* Get a first item */
- iter = g_slist_nth(g_engine_list, 0);
-
- /* Get handle data from list */
- engine = iter->data;
-
- if (NULL != engine) {
- is_default_engine = true;
- g_default_engine_id = engine->engine_id;
- }
- }
- }
-
- if (NULL != engine) {
- if (NULL != engine->engine_uuid) {
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine Id(%d) uuid(%s)", engine->engine_id, engine->engine_uuid);
-
- 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_DEBUG, TAG_STTD, "[Engine Agent] Current engine is not Default engine");
} else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is NULL");
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
-
- g_agent_init = true;
-
- return 0;
-}
-
-sttengine_info_s* __engine_agent_get_engine_by_id(int engine_id)
-{
- GSList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- iter = g_slist_nth(g_engine_list, 0);
-
- while (NULL != iter) {
-
- data = iter->data;
-
- if (data->engine_id == engine_id)
- return data;
-
- iter = g_slist_next(iter);
- }
-
- return NULL;
-}
-
-sttengine_info_s* __engine_agent_get_engine_by_uuid(const char* engine_uuid)
-{
- GSList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- iter = g_slist_nth(g_engine_list, 0);
-
- while (NULL != iter) {
-
- data = iter->data;
-
- if (0 == strcmp(data->engine_uuid, engine_uuid))
- return data;
-
- iter = g_slist_next(iter);
- }
-
- return NULL;
-}
-
-sttengine_client_s* __engine_agent_get_client(int uid)
-{
- GSList *iter = NULL;
- sttengine_client_s *data = NULL;
-
- if (0 < g_slist_length(g_engine_client_list)) {
- iter = g_slist_nth(g_engine_client_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- if (uid == data->uid)
- return data;
-
- iter = g_slist_next(iter);
- }
- }
-
- return NULL;
-}
-
-sttengine_info_s* __engine_agent_get_engine_by_uid(int uid)
-{
- sttengine_client_s *data;
-
- data = __engine_agent_get_client(uid);
- if (NULL != data)
- return __engine_agent_get_engine_by_id(data->engine_id);
-
- return NULL;
-}
-
-int __engine_agent_check_engine_unload(int engine_id)
-{
- /* Check the count of client to use this engine */
- 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);
-
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- if (data->engine_id == engine_id)
- client_count++;
-
- iter = g_slist_next(iter);
- }
- }
-
- if (0 == client_count) {
- sttengine_info_s* engine = NULL;
- engine = __engine_agent_get_engine_by_id(engine_id);
- if (NULL == engine) {
- SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine from client(%d)", engine_id);
- } else {
- if (engine->is_loaded) {
- /* unload engine */
-#ifndef AUDIO_CREATE_ON_START
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
- if (0 != sttd_recorder_destroy(engine->engine_id))
- SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
-#endif
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine id(%d)", 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))
- SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine id(%d)", engine->engine_id);
-
- engine->is_loaded = false;
- }
- }
- }
-
- return 0;
-}
-
-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");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- sttengine_client_s* client = NULL;
- sttengine_info_s* engine = NULL;
- 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) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
- return STTD_ERROR_OUT_OF_MEMORY;
- }
-
- /* 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 */
- engine = __engine_agent_get_engine_by_id(g_default_engine_id);
-
- if (NULL == engine) {
- SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get default engine : %d", g_default_engine_id);
- return STTD_ERROR_OPERATION_FAILED;
- }
- before_engine = client->engine_id;
-
- client->engine_id = engine->engine_id;
- client->use_default_engine = true;
- } else {
- /* Set engine by uid */
- engine = __engine_agent_get_engine_by_uuid(engine_uuid);
-
- if (NULL == engine) {
- SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine : %s", engine_uuid);
- return STTD_ERROR_OPERATION_FAILED;
- }
- before_engine = client->engine_id;
-
- client->engine_id = engine->engine_id;
- client->use_default_engine = false;
- }
-
- if (-1 != before_engine) {
- /* Unload engine if reference count is 0 */
- __engine_agent_check_engine_unload(before_engine);
- }
-
- if (true == engine->is_loaded) {
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine] engine id(%d) is already loaded", engine->engine_id);
- return 0;
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Current engine is Default engine");
}
/* Load engine */
- int ret;
- ret = stt_engine_load(engine->engine_id, engine->engine_path);
+ ret = stt_engine_load(g_engine_info->engine_path, callback);
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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load engine : path(%s)", g_engine_info->engine_path);
return ret;
}
- ret = stt_engine_initialize(engine->engine_id, __result_cb, __detect_silence_cb);
+ ret = stt_engine_initialize(false);
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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize engine : path(%s)", g_engine_info->engine_path);
return ret;
}
- ret = stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected);
+ ret = stt_engine_set_silence_detection(g_default_silence_detected);
if (0 != ret) {
SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Not support silence detection");
- engine->support_silence_detection = false;
+ g_engine_info->support_silence_detection = false;
} else {
SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Silence detection : %s", g_default_silence_detected ? "true" : "false");
- engine->support_silence_detection = true;
- engine->silence_detection = g_default_silence_detected;
+ g_engine_info->support_silence_detection = true;
+ g_engine_info->silence_detection = g_default_silence_detected;
}
/* Set first language */
char* tmp_lang = NULL;
- ret = stt_engine_get_first_language(engine->engine_id, &tmp_lang);
+ ret = stt_engine_get_first_language(&tmp_lang);
if (0 == ret && NULL != tmp_lang) {
- engine->first_lang = strdup(tmp_lang);
+ g_engine_info->first_lang = strdup(tmp_lang);
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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get first language from engine : %s", g_engine_info->engine_name);
return ret;
}
#ifndef AUDIO_CREATE_ON_START
/* Ready recorder */
- sttp_audio_type_e atype;
+ stte_audio_type_e atype;
int rate;
int channels;
- ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
+ ret = stt_engine_get_audio_type(&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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", g_engine_info->engine_name);
return ret;
}
- ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
+ ret = sttd_recorder_create(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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %s", g_engine_info->engine_name);
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);
+ g_engine_info->is_loaded = true;
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s has been loaded !!!", g_engine_info->engine_name);
return 0;
}
-int sttd_engine_agent_unload_current_engine(int uid)
+int sttd_engine_agent_unload_current_engine()
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
}
/* Remove client */
- int engine_id = -1;
-
- GSList *iter = NULL;
- sttengine_client_s *data = NULL;
-
- if (0 < g_slist_length(g_engine_client_list)) {
- iter = g_slist_nth(g_engine_client_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- if (NULL != data) {
- if (uid == data->uid) {
- g_engine_client_list = g_slist_remove_link(g_engine_client_list, iter);
- engine_id = data->engine_id;
- free(data);
- break;
- }
- }
-
- iter = g_slist_next(iter);
- }
- }
-
- if (-1 != engine_id) {
- __engine_agent_check_engine_unload(engine_id);
- }
+ __engine_agent_check_engine_unload();
return 0;
}
bool sttd_engine_agent_is_default_engine()
{
- if (g_default_engine_id > 0)
return true;
-
- return false;
}
int sttd_engine_agent_get_engine_list(GSList** engine_list)
return STTD_ERROR_OPERATION_FAILED;
}
- GSList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- iter = g_slist_nth(g_engine_list, 0);
-
- SLOG(LOG_DEBUG, TAG_STTD, "----- [Engine Agent] engine list -----");
-
- while (NULL != iter) {
- engine_s* temp_engine;
-
- temp_engine = (engine_s*)calloc(1, sizeof(engine_s));
- if (NULL == temp_engine) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to allocate memory");
- return STTD_ERROR_OUT_OF_MEMORY;
- }
-
- data = iter->data;
-
- temp_engine->engine_id = strdup(data->engine_uuid);
- temp_engine->engine_name = strdup(data->engine_name);
- temp_engine->ug_name = strdup(data->engine_setting_path);
-
- *engine_list = g_slist_append(*engine_list, temp_engine);
-
- 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 name(%s)", temp_engine->engine_name);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " Engine ug name(%s)", temp_engine->ug_name);
- }
-
SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
return 0;
}
-int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid)
+int sttd_engine_agent_get_current_engine(char** engine_uuid)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_INVALID_PARAMETER;
}
- sttengine_info_s* engine;
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- *engine_uuid = strdup(engine->engine_uuid);
+ *engine_uuid = strdup(g_engine_info->engine_uuid);
return 0;
}
-bool sttd_engine_agent_need_network(int uid)
+bool sttd_engine_agent_need_network()
{
if (false == g_agent_init) {
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;
+ if (NULL != g_engine_info)
+ return g_engine_info->use_network;
return false;
}
-int sttd_engine_agent_supported_langs(int uid, GSList** lang_list)
+int sttd_engine_agent_supported_langs(GSList** lang_list)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
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);
+ int ret = stt_engine_get_supported_langs(lang_list);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
}
return ret;
}
-int sttd_engine_agent_get_default_lang(int uid, char** lang)
+int sttd_engine_agent_get_default_lang(char** lang)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
/* get default language */
bool is_valid = false;
- int ret = -1;
- ret = stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid);
- if (0 != ret) {
+ if (0 != stt_engine_is_valid_language(g_default_language, &is_valid)) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
- return ret;
+ return STTD_ERROR_OPERATION_FAILED;
}
if (true == is_valid) {
*lang = strdup(g_default_language);
} else
- *lang = strdup(engine->first_lang);
+ *lang = strdup(g_engine_info->first_lang);
return 0;
}
-int sttd_engine_agent_set_private_data(int uid, const char* key, const char* data)
+int sttd_engine_agent_set_private_data(const char* key, const char* data)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->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);
+ ret = stt_engine_set_private_data(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)
+int sttd_engine_agent_get_private_data(const char* key, char** data)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->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);
+ ret = stt_engine_get_private_data(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)
+int sttd_engine_agent_get_option_supported(bool* silence)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- *silence = engine->support_silence_detection;
+ *silence = g_engine_info->support_silence_detection;
return 0;
}
return STTD_ERROR_INVALID_PARAMETER;
}
- sttengine_info_s* engine = NULL;
- engine = __engine_agent_get_engine_by_uid(uid);
-
- if (NULL == engine) {
+ if (NULL == g_engine_info) {
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) {
+ if (false == g_engine_info->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);
+ ret = stt_engine_need_app_credential(&temp);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
return ret;
return 0;
}
-int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support)
+int sttd_engine_agent_is_recognition_type_supported(const char* type, bool* support)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->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_support_recognition_type(engine->engine_id, type, &temp);
+ ret = stt_engine_support_recognition_type(type, &temp);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret);
return ret;
if (2 == silence) {
/* default option set */
if (g_default_silence_detected != engine->silence_detection) {
- if (0 != stt_engine_set_silence_detection(engine->engine_id, g_default_silence_detected)) {
+ if (0 != stt_engine_set_silence_detection(g_default_silence_detected)) {
SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", g_default_silence_detected ? "true" : "false");
} else {
engine->silence_detection = g_default_silence_detected;
}
} else {
if (silence != engine->silence_detection) {
- if (0 != stt_engine_set_silence_detection(engine->engine_id, silence)) {
+ if (0 != stt_engine_set_silence_detection(silence)) {
SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection : %s", silence ? "true" : "false");
} else {
engine->silence_detection = silence;
}
int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
- int silence, const char* credential, void* user_param)
+ int silence, const char* appid, const char* credential, void* user_param)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (0 != __set_option(engine, silence)) {
+ if (0 != __set_option(g_engine_info, silence)) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options");
return STTD_ERROR_OPERATION_FAILED;
}
char* temp = NULL;
if (0 == strncmp(lang, "default", strlen("default"))) {
bool is_valid = false;
- ret = stt_engine_is_valid_language(engine->engine_id, g_default_language, &is_valid);
+ ret = stt_engine_is_valid_language(g_default_language, &is_valid);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to check valid language");
return ret;
temp = strdup(g_default_language);
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is %s", temp);
} else {
- temp = strdup(engine->first_lang);
+ temp = strdup(g_engine_info->first_lang);
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is engine first lang : %s", temp);
}
} else {
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start engine");
- ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, credential, user_param);
+ ret = stt_engine_recognize_start(temp, recognition_type, appid, 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);
+ sttd_recorder_destroy();
return ret;
}
#ifdef AUDIO_CREATE_ON_START
/* Ready recorder */
- sttp_audio_type_e atype;
+ stte_audio_type_e atype;
int rate;
int channels;
- ret = stt_engine_get_audio_type(engine->engine_id, &atype, &rate, &channels);
+ ret = stt_engine_get_audio_type(&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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %s", g_engine_info->engine_name);
return ret;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Create recorder");
- ret = sttd_recorder_create(engine->engine_id, uid, atype, channels, rate);
+ ret = sttd_recorder_create(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);
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %s", g_engine_info->engine_name);
return ret;
}
#endif
#if 0
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder(%d)", uid);
- ret = sttd_recorder_start(engine->engine_id);
+ ret = sttd_recorder_start(uid);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
return ret;
}
- g_recording_engine_id = engine->engine_id;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
#endif
return 0;
int sttd_engine_agent_recognize_start_recorder(int uid)
{
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder");
int ret;
- ret = sttd_recorder_start(engine->engine_id);
+ ret = sttd_recorder_start(uid);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
- stt_engine_recognize_cancel(engine->engine_id);
- sttd_recorder_stop(engine->engine_id);
+ stt_engine_recognize_cancel();
+ sttd_recorder_stop();
return ret;
}
- g_recording_engine_id = engine->engine_id;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] g_recording_engine_id : %d", g_recording_engine_id);
-
return 0;
}
-int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int length)
+int sttd_engine_agent_set_recording_data(const void* data, unsigned int length)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
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);
+ int ret = stt_engine_set_recording_data(data, length);
if (0 != ret) {
SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
}
return ret;
}
-int sttd_engine_agent_recognize_stop_recorder(int uid)
+int sttd_engine_agent_recognize_stop_recorder()
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop recorder");
int ret;
- ret = sttd_recorder_stop(engine->engine_id);
+ ret = sttd_recorder_stop();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
return ret;
#ifdef AUDIO_CREATE_ON_START
SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
- if (0 != sttd_recorder_destroy(engine->engine_id))
- SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
#endif
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Stop recorder");
return 0;
}
-int sttd_engine_agent_recognize_stop_engine(int uid)
+int sttd_engine_agent_recognize_stop_engine()
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Stop engine");
int ret;
- ret = stt_engine_recognize_stop(engine->engine_id);
+ ret = stt_engine_recognize_stop();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
return ret;
return 0;
}
-int sttd_engine_agent_recognize_cancel(int uid)
+int sttd_engine_agent_recognize_cancel()
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Cancel engine");
int ret;
- ret = stt_engine_recognize_cancel(engine->engine_id);
+ ret = stt_engine_recognize_cancel();
if (0 != ret) {
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);
+ ret = sttd_recorder_stop();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
return ret;
#ifdef AUDIO_CREATE_ON_START
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Destroy recorder");
- if (0 != sttd_recorder_destroy(engine->engine_id))
- SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder(%d)", engine->engine_id);
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
#endif
- g_recording_engine_id = -1;
-
SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Success] Cancel recognition");
return 0;
__log_enginelist();
- sttengine_info_s* engine;
- engine = __engine_agent_get_engine_by_uuid(engine_uuid);
- if (NULL == engine) {
+ if (NULL == g_engine_info) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is not valid");
return STTD_ERROR_ENGINE_NOT_FOUND;
}
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine id(%d) engine uuid(%s)", engine->engine_id, engine->engine_uuid);
-
- g_default_engine_id = engine->engine_id;
-
- /* Update default engine of client */
- GSList *iter = NULL;
- sttengine_client_s *data = NULL;
-
- if (0 < g_slist_length(g_engine_client_list)) {
- iter = g_slist_nth(g_engine_client_list, 0);
-
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- if (true == data->use_default_engine) {
- 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)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load current engine : uid(%d)", data->uid);
- }
- }
-
- iter = g_slist_next(iter);
- }
- }
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default engine uuid(%s)", g_engine_info->engine_uuid);
return 0;
}
return 0;
}
-int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result)
+int sttd_engine_agent_check_app_agreed(const char* appid, bool* result)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- 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);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine of is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == engine->is_loaded) {
+ if (false == g_engine_info->is_loaded) {
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);
+ ret = stt_engine_check_app_agreed(appid, result);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
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,
+int sttd_engine_agent_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
const char* msg, void* time_info, void *user_data)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized");
- return;
+ return STTD_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Server] === Result time callback ===");
if (NULL != time_info) {
/* Get the time info */
- int ret = stt_engine_foreach_result_time(g_recording_engine_id, time_info, __result_time_cb, NULL);
+ int ret = stt_engine_foreach_result_time(time_info, __result_time_cb, NULL);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get time info : %d", ret);
+ return ret;
}
}
SLOG(LOG_DEBUG, TAG_STTD, "[Server] ============================");
- g_result_cb(event, type, data, data_count, msg, user_data);
+ g_result_cb(event, type, result, result_count, msg, user_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
+ if (event == STTE_RESULT_EVENT_ERROR) {
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
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
}
#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 STTD_ERROR_NONE;
}
-bool __result_time_cb(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
+int sttd_engine_agent_send_error(stte_error_e error, const char* msg)
{
- return g_result_time_cb(index, event, text, start_time, end_time, user_data);
+ /* check uid */
+ int uid = stt_client_get_current_recognition();
+
+ char* err_msg = strdup(msg);
+ int ret = STTE_ERROR_NONE;
+
+ ret = sttdc_send_error_signal(uid, error, err_msg);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info.");
+ }
+
+ if (NULL != err_msg) {
+ free(err_msg);
+ err_msg = NULL;
+ }
+
+ g_error_cb(error, msg);
+
+ return ret;
}
-void __detect_silence_cb(sttp_silence_type_e type, void* user_data)
+int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data)
{
if (false == g_agent_init) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
- return;
+ return STTD_ERROR_OPERATION_FAILED;
}
- g_silence_cb(type, user_data);
- return;
+ g_speech_status_cb(status, user_data);
+ return STTD_ERROR_NONE;
+}
+
+bool __result_time_cb(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
+{
+ return g_result_time_cb(index, event, text, start_time, end_time, user_data);
}
/* A function forging */
int __log_enginelist()
{
- GSList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- if (0 < g_slist_length(g_engine_list)) {
-
- /* Get a first item */
- iter = g_slist_nth(g_engine_list, 0);
-
- SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
-
- int i = 1;
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[%dth]", i);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine uuid : %s", data->engine_uuid);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine name : %s", data->engine_name);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " engine path : %s", data->engine_path);
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " use network : %s", data->use_network ? "true" : "false");
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " is loaded : %s", data->is_loaded ? "true" : "false");
- if (NULL != data->first_lang)
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, " default lang : %s", data->first_lang);
-
- iter = g_slist_next(iter);
- i++;
+ if (NULL != g_engine_info) {
+ SLOG(LOG_DEBUG, TAG_STTD, "------------------ engine -----------------------");
+ SLOG(LOG_DEBUG, TAG_STTD, "engine uuid : %s", g_engine_info->engine_uuid);
+ SLOG(LOG_DEBUG, TAG_STTD, "engine name : %s", g_engine_info->engine_name);
+ SLOG(LOG_DEBUG, TAG_STTD, "engine path : %s", g_engine_info->engine_path);
+ SLOG(LOG_DEBUG, TAG_STTD, "use network : %s", g_engine_info->use_network ? "true" : "false");
+ SLOG(LOG_DEBUG, TAG_STTD, "is loaded : %s", g_engine_info->is_loaded ? "true" : "false");
+ if (NULL != g_engine_info->first_lang) {
+ SLOG(LOG_DEBUG, TAG_STTD, "default lang : %s", g_engine_info->first_lang);
}
- SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
+ SLOG(LOG_DEBUG, TAG_STTD, "-------------------------------------------------");
} else {
- SLOG(LOG_DEBUG, TAG_STTD, "-------------- engine list -------------------");
- SLOG(LOG_DEBUG, TAG_STTD, " No Engine in engine directory");
- SLOG(LOG_DEBUG, TAG_STTD, "----------------------------------------------");
+ SLOG(LOG_DEBUG, TAG_STTD, "------------------ engine -----------------------");
+ SLOG(LOG_DEBUG, TAG_STTD, " No engine");
+ SLOG(LOG_DEBUG, TAG_STTD, "-------------------------------------------------");
}
return 0;
#define __STTD_ENGINE_AGENT_H_
#include "sttd_main.h"
-#include "sttp.h"
+#include "stte.h"
#ifdef __cplusplus
extern "C" {
#define ENGINE_PATH_SIZE 256
-typedef void (*result_callback)(sttp_result_event_e event, const char* type,
+typedef void (*result_callback)(stte_result_event_e event, const char* type,
const char** data, int data_count, const char* msg, void *user_data);
-typedef bool (*result_time_callback)(int index, sttp_result_time_event_e event, const char* text,
+typedef bool (*result_time_callback)(int index, stte_result_time_event_e event, const char* text,
long start_time, long end_time, void *user_data);
-typedef void (*silence_dectection_callback)(sttp_silence_type_e type, void *user_data);
+typedef void (*speech_status_callback)(stte_speech_status_e status, void *user_data);
+typedef void (*error_callback)(stte_error_e error, const char* msg);
/*
/** Init / Release engine agent */
int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb,
- silence_dectection_callback silence_cb);
+ speech_status_callback speech_status_cb, error_callback error_cb);
int sttd_engine_agent_release();
/** Manage engine */
-int sttd_engine_agent_initialize_engine_list();
+int sttd_engine_agent_initialize_engine_list(stte_request_callback_s *callback);
/** load / unload engine */
-int sttd_engine_agent_load_current_engine(int uid, const char* engine_uuid);
+int sttd_engine_agent_load_current_engine(stte_request_callback_s *callback);
-int sttd_engine_agent_unload_current_engine(int uid);
+int sttd_engine_agent_unload_current_engine();
bool sttd_engine_agent_is_default_engine();
int sttd_engine_agent_get_engine_list(GSList** engine_list);
-int sttd_engine_agent_get_current_engine(int uid, char** engine_uuid);
+int sttd_engine_agent_get_current_engine(char** engine_uuid);
/** Get/Set app option */
-bool sttd_engine_agent_need_network(int uid);
+bool sttd_engine_agent_need_network();
-int sttd_engine_agent_supported_langs(int uid, GSList** lang_list);
+int sttd_engine_agent_supported_langs(GSList** lang_list);
-int sttd_engine_agent_get_default_lang(int uid, char** lang);
+int sttd_engine_agent_get_default_lang(char** lang);
-int sttd_engine_agent_set_private_data(int uid, const char* key, const char* data);
+int sttd_engine_agent_set_private_data(const char* key, const char* data);
-int sttd_engine_agent_get_private_data(int uid, const char* key, char** data);
+int sttd_engine_agent_get_private_data(const char* key, char** data);
-int sttd_engine_agent_get_option_supported(int uid, bool* silence);
+int sttd_engine_agent_get_option_supported(bool* silence);
int sttd_engine_agent_is_credential_needed(int uid, bool* credential);
-int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support);
+int sttd_engine_agent_is_recognition_type_supported(const char* type, bool* support);
int sttd_engine_agent_set_default_engine(const char* engine_uuid);
int sttd_engine_agent_set_silence_detection(bool value);
-int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result);
+int sttd_engine_agent_check_app_agreed(const char* appid, bool* result);
/** Control engine */
int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
- int silence, const char* credential, void* user_param);
+ int silence, const char* appid, const char* credential, void* user_param);
int sttd_engine_agent_recognize_start_recorder(int uid);
-int sttd_engine_agent_set_recording_data(int uid, const void* data, unsigned int length);
+int sttd_engine_agent_set_recording_data(const void* data, unsigned int length);
-int sttd_engine_agent_recognize_stop(int uid);
+int sttd_engine_agent_recognize_stop();
-int sttd_engine_agent_recognize_stop_recorder(int uid);
+int sttd_engine_agent_recognize_stop_recorder();
-int sttd_engine_agent_recognize_stop_engine(int uid);
+int sttd_engine_agent_recognize_stop_engine();
-int sttd_engine_agent_recognize_cancel(int uid);
+int sttd_engine_agent_recognize_cancel();
+
+/** Send engine's information */
+int sttd_engine_agent_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
+ const char* msg, void* time_info, void *user_data);
+
+int sttd_engine_agent_send_error(stte_error_e error, const char* msg);
+
+int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data);
#ifdef __cplusplus
STTD_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
STTD_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
STTD_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
- STTD_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
+ STTD_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the STT service */
STTD_ERROR_RECORDER_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */
STTD_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */
STTD_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */
#include "sttd_dbus.h"
#include "sttd_recorder.h"
#include "sttd_main.h"
-#include "sttp.h"
#define FRAME_LENGTH 160
} sttd_recorder_state;
typedef struct {
- int engine_id;
int uid;
audio_in_h audio_h;
- sttp_audio_type_e audio_type;
+ stte_audio_type_e audio_type;
} stt_recorder_s;
-static GSList *g_recorder_list;
-
-static int g_recording_engine_id;
+static stt_recorder_s* g_recorder = NULL;
static stt_recorder_audio_cb g_audio_cb;
if (NULL != g_audio_cb) {
if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to read audio");
- sttd_recorder_stop(g_recording_engine_id);
+ sttd_recorder_stop();
}
- stt_recorder_s* recorder;
- recorder = __get_recorder(g_recording_engine_id);
- if (NULL == recorder) {
+ if (NULL == g_recorder) {
return;
}
- float vol_db = get_volume_decibel((char*)voice_data->audio_buf, (int)voice_data->length, recorder->audio_type);
- if (0 != sttdc_send_set_volume(recorder->uid, vol_db)) {
+ float vol_db = get_volume_decibel((char*)voice_data->audio_buf, (int)voice_data->length, g_recorder->audio_type);
+ if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
}
}
g_audio_cb = audio_cb;
g_interrupt_cb = interrupt_cb;
g_recorder_state = STTD_RECORDER_STATE_NONE;
- g_recording_engine_id = -1;
+ g_recorder = NULL;
if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, __recorder_focus_state_cb, NULL, &g_stream_info_h)) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to create stream info");
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy stream info");
}
+ if (NULL != g_recorder) {
+ audio_in_destroy(g_recorder->audio_h);
+ g_recorder->audio_h = NULL;
+ free(g_recorder);
+ g_recorder = NULL;
+ }
+
+#ifdef __UNUSED_CODES__
/* Remove all recorder */
GSList *iter = NULL;
stt_recorder_s *recorder = NULL;
iter = g_slist_nth(g_recorder_list, 0);
}
+#endif
#ifdef TV_BT_MODE
bt_hid_host_deinitialize();
return 0;
}
-static stt_recorder_s* __get_recorder(int engine_id)
-{
- GSList *iter = NULL;
- stt_recorder_s *recorder = NULL;
-
- iter = g_slist_nth(g_recorder_list, 0);
-
- while (NULL != iter) {
- recorder = iter->data;
-
- if (recorder->engine_id == engine_id) {
- return recorder;
- }
-
- iter = g_slist_next(iter);
- }
-
- return NULL;
-}
-
int sttd_recorder_set_audio_session()
{
return 0;
return 0;
}
-int sttd_recorder_create(int engine_id, int uid, sttp_audio_type_e type, int channel, unsigned int sample_rate)
+int sttd_recorder_create(stte_audio_type_e type, int channel, unsigned int sample_rate)
{
/* Check engine id is valid */
- if (NULL != __get_recorder(engine_id)) {
+ if (NULL != g_recorder) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is already registered");
return STTD_ERROR_INVALID_PARAMETER;
}
}
switch (type) {
- case STTP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break;
- case STTP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break;
+ case STTE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break;
+ case STTE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break;
default:
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Invalid Audio Type");
return STTD_ERROR_OPERATION_FAILED;
return STTD_ERROR_OUT_OF_MEMORY;
}
- recorder->engine_id = engine_id;
- recorder->uid = uid;
+ recorder->uid = -1;
recorder->audio_h = temp_in_h;
recorder->audio_type = type;
- g_recorder_list = g_slist_append(g_recorder_list, recorder);
+ g_recorder = recorder;
g_recorder_state = STTD_RECORDER_STATE_READY;
return 0;
}
-int sttd_recorder_destroy(int engine_id)
+int sttd_recorder_destroy()
{
// critical section required because this function can be called from stt engine thread context
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
pthread_mutex_lock(&sttd_audio_in_handle_mutex);
/* Check engine id is valid */
- stt_recorder_s* recorder;
- recorder = __get_recorder(engine_id);
- if (NULL == recorder) {
+ if (NULL == g_recorder) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
return STTD_ERROR_INVALID_PARAMETER;
#ifndef TV_BT_MODE
int ret;
if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
- if (recorder->audio_h) {
- ret = audio_in_unprepare(recorder->audio_h);
+ if (g_recorder->audio_h) {
+ ret = audio_in_unprepare(g_recorder->audio_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
}
g_recorder_state = STTD_RECORDER_STATE_READY;
}
- if (recorder->audio_h) {
- ret = audio_in_destroy(recorder->audio_h);
+ if (g_recorder->audio_h) {
+ ret = audio_in_destroy(g_recorder->audio_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy audioin : %d", ret);
}
- recorder->audio_h = NULL;
+ g_recorder->audio_h = NULL;
}
+
#else
if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
g_recorder_state = STTD_RECORDER_STATE_READY;
bt_hid_unset_audio_data_receive_cb();
#endif
- g_recorder_list = g_slist_remove(g_recorder_list, recorder);
-
- free(recorder);
+ free(g_recorder);
+ g_recorder = NULL;
pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Leave critical section");
return 0;
}
-static float get_volume_decibel(char* data, int size, sttp_audio_type_e type)
+static float get_volume_decibel(char* data, int size, stte_audio_type_e type)
{
#define MAX_AMPLITUDE_MEAN_16 32768
#define MAX_AMPLITUDE_MEAN_08 128
float rms = 0.0;
unsigned long long square_sum = 0;
- if (type == STTP_AUDIO_TYPE_PCM_S16_LE)
+ if (type == STTE_AUDIO_TYPE_PCM_S16_LE)
depthByte = 2;
else
depthByte = 1;
static char g_buffer[BUFFER_LENGTH];
/* Check engine id is valid */
- stt_recorder_s* recorder;
- recorder = __get_recorder(g_recording_engine_id);
- if (NULL == recorder) {
+ if (NULL == g_recorder) {
return EINA_FALSE;
}
return EINA_FALSE;
}
- read_byte = audio_in_read(recorder->audio_h, g_buffer, BUFFER_LENGTH);
+ read_byte = audio_in_read(g_recorder->audio_h, g_buffer, BUFFER_LENGTH);
if (0 > read_byte) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail to read audio : %d", read_byte);
g_recorder_state = STTD_RECORDER_STATE_READY;
if (0 != g_audio_cb(g_buffer, read_byte)) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail audio callback");
- sttd_recorder_stop(g_recording_engine_id);
+ sttd_recorder_stop();
return EINA_FALSE;
}
if (0 == g_buffer_count % 30) {
- float vol_db = get_volume_decibel(g_buffer, BUFFER_LENGTH, recorder->audio_type);
- if (0 != sttdc_send_set_volume(recorder->uid, vol_db)) {
+ float vol_db = get_volume_decibel(g_buffer, BUFFER_LENGTH, g_recorder->audio_type);
+ if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
}
}
}
#endif
-int sttd_recorder_start(int engine_id)
+int sttd_recorder_start(int uid)
{
if (STTD_RECORDER_STATE_RECORDING == g_recorder_state)
return 0;
int ret = -1;
#ifndef TV_BT_MODE
/* Check engine id is valid */
- stt_recorder_s* recorder;
- recorder = __get_recorder(engine_id);
- if (NULL == recorder) {
+ if (NULL == g_recorder) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to acquire focus : %d", ret);
} else {
- ret = audio_in_set_stream_info(recorder->audio_h, g_stream_info_h);
+ ret = audio_in_set_stream_info(g_recorder->audio_h, g_stream_info_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set stream info");
}
}
- ret = audio_in_prepare(recorder->audio_h);
+ ret = audio_in_prepare(g_recorder->audio_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to start audio : %d", ret);
return STTD_ERROR_RECORDER_BUSY;
}
#endif
g_recorder_state = STTD_RECORDER_STATE_RECORDING;
- g_recording_engine_id = engine_id;
+ g_recorder->uid = uid;
g_buffer_count = 0;
return 0;
}
-int sttd_recorder_stop(int engine_id)
+int sttd_recorder_stop()
{
if (STTD_RECORDER_STATE_READY == g_recorder_state)
return 0;
/* Check engine id is valid */
- stt_recorder_s* recorder;
- recorder = __get_recorder(engine_id);
- if (NULL == recorder) {
+ if (NULL == g_recorder) {
SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
return STTD_ERROR_INVALID_PARAMETER;
}
+ g_recorder->uid = -1;
+
int ret;
#ifndef TV_BT_MODE
- ret = audio_in_unprepare(recorder->audio_h);
+ ret = audio_in_unprepare(g_recorder->audio_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
}
#endif
g_recorder_state = STTD_RECORDER_STATE_READY;
- g_recording_engine_id = -1;
ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
if (SOUND_MANAGER_ERROR_NONE != ret) {
#ifndef __STTD_RECORDER_H__
#define __STTD_RECORDER_H__
-#include "sttp.h"
+#include "stte.h"
#ifdef __cplusplus
extern "C" {
int sttd_recorder_unset_audio_session();
-int sttd_recorder_create(int engine_id, int uid, sttp_audio_type_e type, int channel, unsigned int sample_rate);
+int sttd_recorder_create(stte_audio_type_e type, int channel, unsigned int sample_rate);
-int sttd_recorder_destroy(int engine_id);
+int sttd_recorder_destroy();
-int sttd_recorder_start(int engine_id);
+int sttd_recorder_start(int uid);
+
+int sttd_recorder_stop();
-int sttd_recorder_stop(int engine_id);
#ifdef __cplusplus
}
if (0 != uid) {
/* cancel engine recognition */
- int ret = sttd_engine_agent_recognize_cancel(uid);
+ int ret = sttd_engine_agent_recognize_cancel();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
}
uid = stt_client_get_current_recognition();
if (0 != uid) {
- ret = sttd_engine_agent_set_recording_data(uid, data, length);
+ ret = sttd_engine_agent_set_recording_data(data, length);
if (ret < 0) {
ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL);
return -1;
return;
}
-void __server_recognition_result_callback(sttp_result_event_e event, const char* type,
+void __server_recognition_result_callback(stte_result_event_e event, const char* type,
const char** data, int data_count, const char* msg, void *user_data)
{
// critical section
SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event);
/* send result to client */
- if (STTP_RESULT_EVENT_FINAL_RESULT == event) {
+ if (STTE_RESULT_EVENT_FINAL_RESULT == event) {
if (APP_STATE_PROCESSING != state) {
SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is NOT 'Processing'.");
}
sttd_client_set_state(uid, APP_STATE_READY);
stt_client_unset_current_recognition();
- } else if (STTP_RESULT_EVENT_PARTIAL_RESULT == event) {
+ } else if (STTE_RESULT_EVENT_PARTIAL_RESULT == event) {
SLOG(LOG_DEBUG, TAG_STTD, "[Server] The partial result from engine is event[%d] data_count[%d]", event, data_count);
sttd_config_time_save();
}
}
- } else if (STTP_RESULT_EVENT_ERROR == event) {
+ } else if (STTE_RESULT_EVENT_ERROR == event) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] The event of recognition result is ERROR");
/* Delete timer for processing time out */
return;
}
-bool __server_result_time_callback(int index, sttp_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
+bool __server_result_time_callback(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
{
pthread_mutex_lock(&sttpe_result_time_mutex);
return true;
}
-void __server_silence_dectection_callback(sttp_silence_type_e type, void *user_param)
+void __server_speech_status_callback(stte_speech_status_e status, void *user_param)
{
- SLOG(LOG_DEBUG, TAG_STTD, "===== Silence Detection Callback");
+ SLOG(LOG_DEBUG, TAG_STTD, "===== Speech status detected Callback");
int uid = stt_client_get_current_recognition();
if (0 != uid) {
return;
}
- if (STTP_SILENCE_TYPE_NO_RECORD_TIMEOUT == type) {
- SLOG(LOG_DEBUG, TAG_STTD, "Silence Detection type - No Record");
- ecore_main_loop_thread_safe_call_async(__cancel_by_no_record, NULL);
- if (0 != sttdc_send_error_signal(uid, STTP_ERROR_NO_SPEECH, "No speech while recording")) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No speech while recording");
- }
- } else if (STTP_SILENCE_TYPE_END_OF_SPEECH_DETECTED == type) {
- SLOG(LOG_DEBUG, TAG_STTD, "Silence Detection type - End of Speech");
+ if (STTE_SPEECH_STATUS_BEGINNING_POINT_DETECTED == status) {
+ SLOG(LOG_DEBUG, TAG_STTD, "Begin Speech detected");
+ } else if (STTE_SPEECH_STATUS_END_POINT_DETECTED == status) {
+ SLOG(LOG_DEBUG, TAG_STTD, "End Speech detected");
ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL);
}
} else {
return;
}
+void __server_error_callback(stte_error_e error, const char* msg)
+{
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Error Callback is called");
+ return;
+}
+
void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data)
{
if (NULL == engine_id) {
signal(SIGQUIT, __sig_handler);
}
-int sttd_initialize()
+int sttd_initialize(stte_request_callback_s *callback)
{
int ret = 0;
/* Engine Agent initialize */
ret = sttd_engine_agent_init(__server_recognition_result_callback, __server_result_time_callback,
- __server_silence_dectection_callback);
+ __server_speech_status_callback, __server_error_callback);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
return ret;
}
- /* Update engine list */
- ret = sttd_engine_agent_initialize_engine_list();
+ /* load engine */
+ ret = sttd_engine_agent_load_current_engine(callback);
if (0 != ret) {
- if (STTD_ERROR_ENGINE_NOT_FOUND == ret) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no stt engine");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to update engine list : %d", ret);
- return ret;
- }
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load default engine");
+ return ret;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] initialize");
int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential)
{
- if (false == sttd_engine_agent_is_default_engine()) {
- /* Update installed engine */
- sttd_engine_agent_initialize_engine_list();
-
- if (false == sttd_engine_agent_is_default_engine()) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] No stt-engine");
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
- }
-
int ret = STTD_ERROR_NONE;
/* check if uid is valid */
return STTD_ERROR_NONE;
}
- /* load engine */
- ret = sttd_engine_agent_load_current_engine(uid, NULL);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load default engine");
- return ret;
- }
-
- ret = sttd_engine_agent_get_option_supported(uid, silence);
+ ret = sttd_engine_agent_get_option_supported(silence);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine options supported");
return ret;
static Eina_Bool __quit_ecore_loop(void *data)
{
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Quit");
+
+ stt_network_finalize();
+ sttd_finalize();
ecore_main_loop_quit();
+
+ SLOG(LOG_DEBUG, TAG_STTD, "");
+
return EINA_FALSE;
}
stt_client_unset_current_recognition();
}
- if (0 != sttd_engine_agent_unload_current_engine(uid)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unload engine");
- }
-
/* Remove client information */
if (0 != sttd_client_delete(uid)) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete client");
}
int ret;
- ret = sttd_engine_agent_load_current_engine(uid, engine_id);
+ ret = sttd_engine_agent_load_current_engine(NULL);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : %d", ret);
return ret;
}
- ret = sttd_engine_agent_get_option_supported(uid, silence);
+ ret = sttd_engine_agent_get_option_supported(silence);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to engine options : %d", ret);
return ret;
}
int ret;
- ret = sttd_engine_agent_get_current_engine(uid, engine_id);
+ ret = sttd_engine_agent_get_current_engine(engine_id);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine : %d", ret);
return ret;
/* Ask engine available */
int ret;
bool temp = false;
- ret = sttd_engine_agent_check_app_agreed(uid, appid, &temp);
+ ret = sttd_engine_agent_check_app_agreed(appid, &temp);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret);
return ret;
}
/* get language list from engine */
- int ret = sttd_engine_agent_supported_langs(uid, lang_list);
+ int ret = sttd_engine_agent_supported_langs(lang_list);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get supported languages");
return ret;
}
/*get current language from engine */
- int ret = sttd_engine_agent_get_default_lang(uid, current_lang);
+ int ret = sttd_engine_agent_get_default_lang(current_lang);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language :result(%d)", ret);
return ret;
/* set private data to engine */
int ret = -1;
- ret = sttd_engine_agent_set_private_data(uid, key, data);
+ ret = sttd_engine_agent_set_private_data(key, data);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data :result(%d)", ret);
return ret;
/* get private data to engine */
int ret = -1;
- ret = sttd_engine_agent_get_private_data(uid, key, data);
+ ret = sttd_engine_agent_get_private_data(key, data);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get private data :result(%d)", ret);
return ret;
}
- SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get private data");
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get private data, key(%s), data(%s)", key, *data);
return STTD_ERROR_NONE;
}
}
bool temp;
- int ret = sttd_engine_agent_is_recognition_type_supported(uid, type, &temp);
+ int ret = sttd_engine_agent_is_recognition_type_supported(type, &temp);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get recognition type supported : result(%d)", ret);
return ret;
if (APP_STATE_READY == state) {
/* Cancel stt */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Ready'. The daemon should cancel recording", uid);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Ready'. The STT service should cancel recording", uid);
sttd_server_cancel(uid);
} else if (APP_STATE_PROCESSING == state) {
/* Cancel stt and send change state */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Processing'. The daemon should cancel recording", uid);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Processing'. The STT service should cancel recording", uid);
sttd_server_cancel(uid);
sttdc_send_set_state(uid, (int)APP_STATE_READY);
} else {
/* Normal state */
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] The states of daemon and client are identical");
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] The states of STT service and client are identical");
return EINA_TRUE;
}
int ret = 0;
if (false == stt_client_get_app_agreed(uid)) {
bool temp = false;
- ret = sttd_engine_agent_check_app_agreed(uid, appid, &temp);
+ ret = sttd_engine_agent_check_app_agreed(appid, &temp);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret);
return ret;
}
/* check if engine use network */
- if (true == sttd_engine_agent_need_network(uid)) {
+ if (true == sttd_engine_agent_need_network()) {
if (false == stt_network_is_connected()) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
return STTD_ERROR_OUT_OF_NETWORK;
}
/* 3. Create recorder & engine initialize */
- ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, credential, NULL);
+ ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, appid, credential, NULL);
if (0 != ret) {
stt_client_unset_current_recognition();
sttd_recorder_unset_audio_session();
return ret;
}
- if (0 != strcmp(STTP_RECOGNITION_TYPE_FREE_PARTIAL, recognition_type)) {
+ if (0 != strcmp(STTE_RECOGNITION_TYPE_FREE_PARTIAL, recognition_type)) {
g_recording_timer = ecore_timer_add(g_recording_timeout, __stop_by_recording_timeout, NULL);
}
stt_client_unset_current_recognition();
sttd_recorder_unset_audio_session();
- sttd_engine_agent_recognize_cancel(uid);
+ sttd_engine_agent_recognize_cancel();
ecore_timer_del(g_recording_timer);
sttd_client_set_state(uid, APP_STATE_READY);
if (0 == uid) return EINA_FALSE;
/* Cancel engine */
- int ret = sttd_engine_agent_recognize_cancel(uid);
+ int ret = sttd_engine_agent_recognize_cancel();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
}
- if (0 != sttdc_send_result(uid, STTP_RESULT_EVENT_FINAL_RESULT, NULL, 0, "Time out not to receive recognition result.")) {
+ if (0 != sttdc_send_result(uid, STTE_RESULT_EVENT_FINAL_RESULT, NULL, 0, "Time out not to receive recognition result.")) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result ");
/* send error msg */
}
/* Stop engine */
- ret = sttd_engine_agent_recognize_stop_engine(uid);
+ ret = sttd_engine_agent_recognize_stop_engine();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop engine : result(%d)", ret);
return;
int ret;
/* 1. Stop recorder */
- ret = sttd_engine_agent_recognize_stop_recorder(uid);
+ ret = sttd_engine_agent_recognize_stop_recorder();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop recorder : result(%d)", ret);
- if (0 != sttd_engine_agent_recognize_cancel(uid)) {
+ if (0 != sttd_engine_agent_recognize_cancel()) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel recognize");
}
if (NULL != sound) free(sound);
}
/* Stop engine */
- ret = sttd_engine_agent_recognize_stop_engine(uid);
+ ret = sttd_engine_agent_recognize_stop_engine();
if (0 != ret) {
stt_client_unset_current_recognition();
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop engine : result(%d)", ret);
sttd_client_set_state(uid, APP_STATE_READY);
/* cancel engine recognition */
- int ret = sttd_engine_agent_recognize_cancel(uid);
+ int ret = sttd_engine_agent_recognize_cancel();
if (0 != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
return ret;
#include <Ecore.h>
#include "sttd_main.h"
+#include "stte.h"
#ifdef __cplusplus
extern "C" {
/*
* Daemon functions
*/
-int sttd_initialize();
+int sttd_initialize(stte_request_callback_s *callback);
int sttd_finalize();
--- /dev/null
+/*
+* 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
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <Ecore.h>
+
+#include "stt_engine.h"
+#include "stt_defs.h"
+#include "stt_network.h"
+#include "sttd_dbus.h"
+#include "sttd_server.h"
+
+#include "stte.h"
+
+
+#define CLIENT_CLEAN_UP_TIME 500
+
+static Ecore_Timer* g_check_client_timer = NULL;
+
+int stte_main(int argc, char**argv, stte_request_callback_s *callback)
+{
+ SLOG(LOG_DEBUG, TAG_STTD, "===== Start engine");
+
+ if (!ecore_init()) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize Ecore");
+ return EXIT_FAILURE;
+ }
+
+ if (0 != sttd_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open connection");
+ return EXIT_FAILURE;
+ }
+
+ if (0 != sttd_initialize(callback)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize stt-service");
+ return EXIT_FAILURE;
+ }
+
+ stt_network_initialize();
+
+ g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL);
+ if (NULL == g_check_client_timer) {
+ SLOG(LOG_WARN, TAG_STTD, "[Main Warning] Fail to create timer of client check");
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-service start...");
+
+ SLOG(LOG_DEBUG, TAG_STTD, "=====");
+ SLOG(LOG_DEBUG, TAG_STTD, " ");
+ SLOG(LOG_DEBUG, TAG_STTD, " ");
+
+ return 0;
+}
+
+int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
+ const char* msg, void* time_info, void* user_data)
+{
+ if (NULL == type || NULL == result) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
+ }
+
+ int ret = STTE_ERROR_NONE;
+ ret = stt_engine_send_result(event, type, result, result_count, msg, time_info, user_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
+ }
+ return ret;
+}
+
+int stte_send_error(stte_error_e error, const char* msg)
+{
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
+ }
+
+ int ret = STTE_ERROR_NONE;
+ ret = stt_engine_send_error(error, msg);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info");
+ }
+ return ret;
+}
+
+int stte_send_speech_status(stte_speech_status_e status, void* user_data)
+{
+ int ret = STTE_ERROR_NONE;
+ ret = stt_engine_send_speech_status(status, user_data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
+ }
+ return ret;
+}
+
+int stte_set_private_data_set_cb(stte_private_data_set_cb callback)
+{
+ int ret = STTE_ERROR_NONE;
+ ret = stt_engine_set_private_data_set_cb(callback, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
+ }
+ return ret;
+}
+
+int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback)
+{
+ int ret = STTE_ERROR_NONE;
+ ret = stt_engine_set_private_data_requested_cb(callback, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
+ }
+ return ret;
+}
SLOG(LOG_DEBUG, TAG_STT_TEST, "( %s )", data[0]);
}
+ if (STT_RESULT_EVENT_FINAL_RESULT == event) {
ecore_timer_add(0, __stt_finalize, NULL);
+ }
}
int main(int argc, char *argv[])
return 0;
}
+ SLOG(LOG_DEBUG, TAG_STT_TEST, "STT set credential");
+ ret = stt_set_credential(g_stt, "1Q2W3E4R5T");
+ if (STT_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to set credential");
+ return 0;
+ }
+
SLOG(LOG_DEBUG, TAG_STT_TEST, "STT prepare");
ret = stt_prepare(g_stt);
if (STT_ERROR_NONE != ret) {