/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
#include <dlfcn.h>
#include <dirent.h>
+#include "stt_defs.h"
+#include "stt_engine.h"
#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"
+#define AUDIO_CREATE_ON_START
+
/*
* Internal data structure
*/
-typedef struct {
- /* engine info */
+typedef struct _sttengine_info {
char* engine_uuid;
- char* engine_name;
char* engine_path;
+ char* engine_name;
+ char* engine_setting_path;
+ bool use_network;
- /* engine load info */
- bool is_set;
- bool is_loaded;
- bool need_network;
- bool support_silence_detection;
- bool support_profanity_filter;
- bool support_punctuation_override;
- void *handle;
+ bool is_loaded;
/* engine base setting */
- char* default_lang;
- bool profanity_filter;
- bool punctuation_override;
+ char* first_lang;
bool silence_detection;
-
- sttpe_funcs_s* pefuncs;
- sttpd_funcs_s* pdfuncs;
-
- int (*sttp_load_engine)(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
- int (*sttp_unload_engine)();
-} sttengine_s;
-
-typedef struct _sttengine_info {
- char* engine_uuid;
- char* engine_path;
- char* engine_name;
- char* setting_ug_path;
- bool use_network;
bool support_silence_detection;
+ bool need_credential;
} sttengine_info_s;
-
-/*
-* static data
-*/
-
/** stt engine agent init */
-static bool g_agent_init;
+static bool g_agent_init;
-/** stt engine list */
-static GList *g_engine_list;
+static sttengine_info_s* g_engine_info = NULL;
-/** current engine infomation */
-static sttengine_s g_cur_engine;
-
-/** default option value */
-static bool g_default_profanity_filter;
-static bool g_default_punctuation_override;
-static bool g_default_silence_detected;
+/** default engine info */
+static char* g_default_language = NULL;
+static bool g_default_silence_detected;
/** callback functions */
-static result_callback g_result_cb;
-static partial_result_callback g_partial_result_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 *user_data);
-
-void __partial_result_cb(sttp_result_event_e event, const char* data, void *user_data);
-
-void __detect_silence_cb(void* user_data);
+bool __result_time_cb(int index, stte_result_time_event_e event, const char* text,
+ long start_time, long end_time, 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);
-
-bool __engine_setting_cb(const char* key, const char* value, void* user_data);
-
-/** Free voice list */
-void __free_language_list(GList* lang_list);
-
-
/*
-* Internal Interfaces
+* Internal Interfaces
*/
-
-/** Set current engine */
-int __internal_set_current_engine(const char* engine_uuid);
-
-/** check engine id */
-int __internal_check_engine_id(const char* engine_uuid);
-
-/** update engine list */
-int __internal_update_engine_list();
/** 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, partial_result_callback partial_result_cb, silence_dectection_callback silence_cb)
+int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_cb,
+ speech_status_callback speech_status_cb, error_callback error_cb)
{
/* initialize static data */
- if (NULL == result_cb || NULL == silence_cb) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine agent ERROR] sttd_engine_agent_init : invalid parameter");
+ 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_partial_result_cb = partial_result_cb;
- g_silence_cb = silence_cb;
-
- g_cur_engine.engine_uuid = NULL;
- g_cur_engine.engine_name = NULL;
- g_cur_engine.engine_path = NULL;
+ g_result_time_cb = time_cb;
+ g_speech_status_cb = speech_status_cb;
+ g_error_cb = error_cb;
- g_cur_engine.is_set = false;
- g_cur_engine.handle = NULL;
- g_cur_engine.pefuncs = (sttpe_funcs_s*)malloc( sizeof(sttpe_funcs_s) );
- g_cur_engine.pdfuncs = (sttpd_funcs_s*)malloc( sizeof(sttpd_funcs_s) );
-
- g_agent_init = true;
+ g_default_language = NULL;
- if (0 != sttd_config_get_default_language(&(g_cur_engine.default_lang))) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No default voice in config");
+ 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");
/* Set default voice */
- g_cur_engine.default_lang = strdup("en_US");
+ g_default_language = strdup("en_US");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Default language is %s", g_default_language);
}
int temp;
if (0 != sttd_config_get_default_silence_detection(&temp)) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config");
+ SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no silence detection in config");
g_default_silence_detected = true;
} else {
g_default_silence_detected = (bool)temp;
}
- if (0 != sttd_config_get_default_profanity_filter(&temp)) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no profanity filter in config");
- g_default_profanity_filter = false;
- } else {
- g_default_profanity_filter = (bool)temp;
- }
-
- if (0 != sttd_config_get_default_punctuation_override(&temp)) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is no punctuation override in config");
- g_default_punctuation_override = false;
- } else {
- g_default_punctuation_override = (bool)temp;
- }
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Engine Agent Initialize");
+ g_agent_init = true;
return 0;
}
-int sttd_engine_agent_release()
+int __engine_agent_clear_engine(sttengine_info_s *engine)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- /* unload current engine */
- sttd_engine_agent_unload_current_engine();
-
- /* release engine list */
- GList *iter = NULL;
- sttengine_s *data = NULL;
-
- if (g_list_length(g_engine_list) > 0) {
- /* Get a first item */
- iter = g_list_first(g_engine_list);
+ if (NULL != engine) {
+ if (NULL != engine->engine_uuid) free(engine->engine_uuid);
+ if (NULL != engine->engine_path) free(engine->engine_path);
+ if (NULL != engine->engine_name) free(engine->engine_name);
+ if (NULL != engine->engine_setting_path)free(engine->engine_setting_path);
+ if (NULL != engine->first_lang) free(engine->first_lang);
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- iter = g_list_remove(iter, data);
- }
+ free(engine);
+ engine = NULL;
}
- g_list_free(iter);
-
- /* release current engine data */
- if( NULL != g_cur_engine.pefuncs )
- free(g_cur_engine.pefuncs);
-
- if( NULL != g_cur_engine.pdfuncs )
- free(g_cur_engine.pdfuncs);
-
- g_result_cb = NULL;
- g_silence_cb = NULL;
-
- g_agent_init = false;
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Engine Agent release");
-
return 0;
}
-int sttd_engine_agent_initialize_current_engine()
+int sttd_engine_agent_release()
{
- /* check agent init */
- if (false == g_agent_init ) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- /* update engine list */
- if (0 != __internal_update_engine_list()) {
- SLOG(LOG_ERROR, TAG_STTD, "[engine agent] sttd_engine_agent_init : __internal_update_engine_list : no engine error");
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
-
- /* get current engine from config */
- char* cur_engine_uuid = NULL;
- bool is_get_engineid_from_config = false;
-
- if (0 != sttd_config_get_default_engine(&cur_engine_uuid)) {
+ if (NULL != g_engine_info) {
+ if (g_engine_info->is_loaded) {
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Unload engine");
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] There is not current engine from config");
+ if (0 != stt_engine_deinitialize()) {
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to deinitialize");
+ }
- /* not set current engine */
- /* set system default engine */
- GList *iter = NULL;
- if (0 < g_list_length(g_engine_list)) {
- iter = g_list_first(g_engine_list);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[engine agent ERROR] sttd_engine_agent_initialize_current_engine() : no engine error");
- return -1;
- }
+ if (0 != stt_engine_unload()) {
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine");
+ }
- sttengine_info_s *data = NULL;
- data = iter->data;
+ if (NULL != g_engine_info->engine_uuid) {
+ free(g_engine_info->engine_uuid);
+ g_engine_info->engine_uuid = NULL;
+ }
- cur_engine_uuid = g_strdup(data->engine_uuid);
+ if (NULL != g_engine_info->engine_path) {
+ free(g_engine_info->engine_path);
+ g_engine_info->engine_path = NULL;
+ }
- is_get_engineid_from_config = false;
- } else {
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] current engine from config : %s", cur_engine_uuid);
+ if (NULL != g_engine_info->engine_name) {
+ free(g_engine_info->engine_name);
+ g_engine_info->engine_name = NULL;
+ }
- is_get_engineid_from_config = true;
- }
+ if (NULL != g_engine_info->engine_setting_path) {
+ free(g_engine_info->engine_setting_path);
+ g_engine_info->engine_setting_path = NULL;
+ }
- /* check whether cur engine uuid is valid or not. */
- if (0 != __internal_check_engine_id(cur_engine_uuid)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] It is not valid engine id and find other engine id");
+ if (NULL != g_engine_info->first_lang) {
+ free(g_engine_info->first_lang);
+ g_engine_info->first_lang = NULL;
+ }
- GList *iter = NULL;
- if (0 < g_list_length(g_engine_list)) {
- iter = g_list_first(g_engine_list);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_initialize_current_engine() : no engine error");
- return -1;
+ g_engine_info->is_loaded = false;
}
- if (NULL != cur_engine_uuid)
- free(cur_engine_uuid);
-
- sttengine_info_s *data = NULL;
- data = iter->data;
-
- cur_engine_uuid = g_strdup(data->engine_uuid);
-
- is_get_engineid_from_config = false;
+ __engine_agent_clear_engine(g_engine_info);
}
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Current Engine Id : %s", cur_engine_uuid);
-
- /* set current engine */
- if (0 != __internal_set_current_engine(cur_engine_uuid)) {
- SLOG(LOG_ERROR, TAG_STTD, "[engine agent ERROR] __internal_set_current_engine : no engine error");
-
- if( cur_engine_uuid != NULL)
- free(cur_engine_uuid);
-
- return STTD_ERROR_ENGINE_NOT_FOUND;
- }
-
- if (false == is_get_engineid_from_config) {
- if (0 != sttd_config_set_default_engine(cur_engine_uuid))
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default engine ");
- }
+ g_result_cb = NULL;
+ g_speech_status_cb = NULL;
+ g_error_cb = NULL;
+ g_result_time_cb = NULL;
- if( cur_engine_uuid != NULL )
- free(cur_engine_uuid);
+ g_agent_init = false;
return 0;
}
-int __internal_check_engine_id(const char* engine_uuid)
-{
- if (NULL == engine_uuid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- GList *iter = NULL;
- sttengine_s *data = NULL;
-
- if (0 < g_list_length(g_engine_list)) {
- /*Get a first item*/
- iter = g_list_first(g_engine_list);
-
- while (NULL != iter) {
- data = iter->data;
-
- if (0 == strncmp(engine_uuid, data->engine_uuid, strlen(data->engine_uuid))) {
- return 0;
- }
-
- iter = g_list_next(iter);
- }
- }
-
- return -1;
-}
-
-void __engine_info_cb(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
- bool use_network, void* user_data)
+int __internal_get_engine_info(stte_request_callback_s *callback, sttengine_info_s** info)
{
- sttengine_info_s* temp = (sttengine_info_s*)user_data;
-
- temp->engine_uuid = g_strdup(engine_uuid);
- temp->engine_name = g_strdup(engine_name);
- temp->setting_ug_path = g_strdup(setting_ug_name);
- temp->use_network = use_network;
-}
-
-
-int __internal_get_engine_info(const char* filepath, sttengine_info_s** info)
-{
- if (NULL == filepath || NULL == info) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- /* load engine */
- char *error;
- void* handle;
-
- handle = dlopen (filepath, RTLD_LAZY);
-
- if (!handle) {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Invalid engine : %s", filepath);
- return -1;
- }
-
- /* 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 -1;
+ 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");
+ return STTD_ERROR_OUT_OF_MEMORY;
}
- 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 -1;
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid engine");
+ free(temp);
+ 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 -1;
+ if (NULL == callback->get_info) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid engine");
+ free(temp);
+ return STTD_ERROR_ENGINE_NOT_FOUND;
}
- sttengine_info_s* temp;
- temp = (sttengine_info_s*)g_malloc0( sizeof(sttengine_info_s) );
-
- /* 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);
- g_free(temp);
- return -1;
+ 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;
}
- /* close engine */
- dlclose(handle);
-
- temp->engine_path = g_strdup(filepath);
+ /* todo - removed? */
+ temp->engine_path = strdup("empty");
+ temp->is_loaded = false;
SLOG(LOG_DEBUG, TAG_STTD, "----- Valid Engine");
- SLOG(LOG_DEBUG, TAG_STTD, "Engine uuid : %s", temp->engine_uuid);
- SLOG(LOG_DEBUG, TAG_STTD, "Engine name : %s", temp->engine_name);
- SLOG(LOG_DEBUG, TAG_STTD, "Setting ug path : %s", temp->setting_ug_path);
- SLOG(LOG_DEBUG, TAG_STTD, "Engine path : %s", temp->engine_path);
- 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, " ");
*info = temp;
- return 0;
+ return STTD_ERROR_NONE;
}
-int __internal_update_engine_list()
+bool __is_engine(const char* filepath)
{
- /* relsease engine list */
- GList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- if (0 < g_list_length(g_engine_list)) {
- /* Get a first item */
- iter = g_list_first(g_engine_list);
-
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
-
- if (NULL != data) {
- if (NULL != data->engine_uuid) free(data->engine_uuid);
- if (NULL != data->engine_path) free(data->engine_path);
- if (NULL != data->engine_name) free(data->engine_name);
- if (NULL != data->setting_ug_path) free(data->setting_ug_path);
-
- free(data);
- }
-
- g_engine_list = g_list_remove_link(g_engine_list, iter);
- iter = g_list_first(g_engine_list);
- }
+ if (NULL == filepath) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No filepath");
+ return false;
}
- /* Get file name from default engine directory */
- DIR *dp;
- struct dirent *dirp;
-
- dp = opendir(ENGINE_DIRECTORY_DEFAULT);
- if (NULL != dp) {
- while (NULL != (dirp = readdir(dp))) {
- sttengine_info_s* info;
- char* filepath;
- int filesize;
-
- filesize = strlen(ENGINE_DIRECTORY_DEFAULT) + strlen(dirp->d_name) + 5;
- filepath = (char*) g_malloc0(sizeof(char) * filesize);
-
- if (NULL != filepath) {
- strncpy(filepath, ENGINE_DIRECTORY_DEFAULT, strlen(ENGINE_DIRECTORY_DEFAULT) );
- strncat(filepath, "/", strlen("/") );
- strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!" );
- continue;
- }
-
- /* get its info and update engine list */
- if (0 == __internal_get_engine_info(filepath, &info)) {
- /* add engine info to g_engine_list */
- g_engine_list = g_list_append(g_engine_list, info);
- }
-
- if (NULL != filepath)
- g_free(filepath);
+ if (NULL != g_engine_info) {
+ if (!strcmp(g_engine_info->engine_path, filepath)) {
+ return true;
}
-
- closedir(dp);
- } else {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open default directory");
- }
-
- /* Get file name from downloadable engine directory */
- dp = opendir(ENGINE_DIRECTORY_DOWNLOAD);
- if (NULL != dp) {
- while (NULL != (dirp = readdir(dp))) {
- sttengine_info_s* info;
- char* filepath;
- int filesize;
-
- filesize = strlen(ENGINE_DIRECTORY_DOWNLOAD) + strlen(dirp->d_name) + 5;
- filepath = (char*) g_malloc0(sizeof(char) * filesize);
-
- if (NULL != filepath) {
- strncpy(filepath, ENGINE_DIRECTORY_DOWNLOAD, strlen(ENGINE_DIRECTORY_DOWNLOAD) );
- strncat(filepath, "/", strlen("/") );
- strncat(filepath, dirp->d_name, strlen(dirp->d_name) );
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Memory not enough!!" );
- continue;
- }
-
- /* get its info and update engine list */
- if (0 == __internal_get_engine_info(filepath, &info)) {
- /* add engine info to g_engine_list */
- g_engine_list = g_list_append(g_engine_list, info);
- }
-
- if (NULL != filepath)
- g_free(filepath);
- }
-
- closedir(dp);
- } else {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail to open downloadable directory");
- }
-
- if (0 >= g_list_length(g_engine_list)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] No Engine");
- return STTD_ERROR_ENGINE_NOT_FOUND;
}
- __log_enginelist();
-
- return 0;
+ return false;
}
-int __internal_set_current_engine(const char* engine_uuid)
+int __engine_agent_check_engine_unload()
{
- if (NULL == engine_uuid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- /* check whether engine id is valid or not.*/
- GList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- bool flag = false;
- if (g_list_length(g_engine_list) > 0) {
- /*Get a first item*/
- iter = g_list_first(g_engine_list);
-
- while (NULL != iter) {
- /*Get handle data from list*/
- data = iter->data;
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] engine_uuid(%s) engine list->uuid(%s)", engine_uuid, data->engine_uuid);
-
- if (0 == strncmp(data->engine_uuid, engine_uuid, strlen(engine_uuid))) {
- flag = true;
- break;
- }
-
- /*Get next item*/
- iter = g_list_next(iter);
- }
- }
-
- /* If current engine does not exist, return error */
- if (false == flag) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] __internal_set_current_engine : Cannot find engine id");
- return STTD_ERROR_INVALID_PARAMETER;
+ /* 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 (NULL != g_cur_engine.engine_uuid) {
- /*compare current engine uuid */
- if (0 == strncmp(g_cur_engine.engine_uuid, data->engine_uuid, strlen(engine_uuid))) {
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent Check] stt engine has already been set");
- return 0;
- }
+ 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 (0 != stt_engine_unload())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to unload engine");
+
+ g_engine_info->is_loaded = false;
}
}
- /* set data from g_engine_list */
- if (g_cur_engine.engine_uuid != NULL) free(g_cur_engine.engine_uuid);
- if (g_cur_engine.engine_name != NULL) free(g_cur_engine.engine_name);
- if (g_cur_engine.engine_path != NULL) free(g_cur_engine.engine_path);
-
- g_cur_engine.engine_uuid = g_strdup(data->engine_uuid);
- g_cur_engine.engine_name = g_strdup(data->engine_name);
- g_cur_engine.engine_path = g_strdup(data->engine_path);
-
- g_cur_engine.handle = NULL;
- g_cur_engine.is_loaded = false;
- g_cur_engine.is_set = true;
- g_cur_engine.need_network = data->use_network;
-
- g_cur_engine.profanity_filter = g_default_profanity_filter;
- g_cur_engine.punctuation_override = g_default_punctuation_override;
- g_cur_engine.silence_detection = g_default_silence_detected;
-
- SLOG(LOG_DEBUG, TAG_STTD, "-----");
- SLOG(LOG_DEBUG, TAG_STTD, " Current engine uuid : %s", g_cur_engine.engine_uuid);
- SLOG(LOG_DEBUG, TAG_STTD, " Current engine name : %s", g_cur_engine.engine_name);
- SLOG(LOG_DEBUG, TAG_STTD, " Current engine path : %s", g_cur_engine.engine_path);
- SLOG(LOG_DEBUG, TAG_STTD, "-----");
-
return 0;
}
-int sttd_engine_agent_load_current_engine()
+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");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_set) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_load_current_engine : No Current Engine ");
- return -1;
- }
-
- /* check whether current engine is loaded or not */
- if (true == g_cur_engine.is_loaded) {
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] sttd_engine_agent_load_current_engine : Engine has already been loaded ");
- return 0;
+ /* 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;
}
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Current engine path : %s", g_cur_engine.engine_path);
- /* open engine */
- char *error;
- g_cur_engine.handle = dlopen(g_cur_engine.engine_path, RTLD_LAZY);
+ __log_enginelist();
- if (NULL != (error = dlerror()) || !g_cur_engine.handle) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get engine handle");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- g_cur_engine.sttp_unload_engine = (int (*)())dlsym(g_cur_engine.handle, "sttp_unload_engine");
- if (NULL != (error = dlerror()) || NULL == g_cur_engine.sttp_unload_engine) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to link daemon to sttp_unload_engine() : %s", error);
- return STTD_ERROR_OPERATION_FAILED;
- }
+ /* Set default engine */
+ char* cur_engine_uuid = NULL;
+ bool is_default_engine = false;
- g_cur_engine.sttp_load_engine = (int (*)(sttpd_funcs_s*, sttpe_funcs_s*) )dlsym(g_cur_engine.handle, "sttp_load_engine");
- if (NULL != (error = dlerror()) || NULL == g_cur_engine.sttp_load_engine) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to link daemon to sttp_load_engine() : %s", error);
- return STTD_ERROR_OPERATION_FAILED;
+ /* 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 (NULL != g_engine_info->engine_uuid && NULL != cur_engine_uuid) {
+ if (!strcmp(g_engine_info->engine_uuid, cur_engine_uuid)) {
+ is_default_engine = true;
+ }
+ }
+ 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");
}
- /* load engine */
- g_cur_engine.pdfuncs->version = 1;
- g_cur_engine.pdfuncs->size = sizeof(sttpd_funcs_s);
-
- if (0 != g_cur_engine.sttp_load_engine(g_cur_engine.pdfuncs, g_cur_engine.pefuncs)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail sttp_load_engine()");
- return STTD_ERROR_OPERATION_FAILED;
+ if (false == is_default_engine) {
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Current engine is not Default engine");
+ } else {
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Current engine is Default engine");
}
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] engine info : version(%d), size(%d)",g_cur_engine.pefuncs->version, g_cur_engine.pefuncs->size);
-
- /* engine error check */
- if (g_cur_engine.pefuncs->size != sizeof(sttpe_funcs_s)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_load_current_engine : engine is not valid");
- return STTD_ERROR_OPERATION_FAILED;
+ /* Load engine */
+ 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 : path(%s)", g_engine_info->engine_path);
+ return ret;
}
- /* initalize engine */
- if (0 != g_cur_engine.pefuncs->initialize(__result_cb, __partial_result_cb, __detect_silence_cb)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize stt-engine");
- return STTD_ERROR_OPERATION_FAILED;
+ ret = stt_engine_initialize(false);
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to initialize engine : path(%s)", g_engine_info->engine_path);
+ return ret;
}
- /* set default setting */
- int ret = 0;
-
- if (NULL == g_cur_engine.pefuncs->set_profanity_filter) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_profanity_filter of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- /* check and set profanity filter */
- ret = g_cur_engine.pefuncs->set_profanity_filter(g_cur_engine.profanity_filter);
+ ret = stt_engine_set_silence_detection(g_default_silence_detected);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent] Not support profanity filter");
- g_cur_engine.support_profanity_filter = false;
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Not support silence detection");
+ g_engine_info->support_silence_detection = false;
} else {
- g_cur_engine.support_profanity_filter = true;
- }
-
- /* check and set punctuation */
- if (NULL == g_cur_engine.pefuncs->set_punctuation) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Silence detection : %s", g_default_silence_detected ? "true" : "false");
+ g_engine_info->support_silence_detection = true;
+ g_engine_info->silence_detection = g_default_silence_detected;
}
- ret = g_cur_engine.pefuncs->set_punctuation(g_cur_engine.punctuation_override);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Not support punctuation override");
- g_cur_engine.support_punctuation_override = false;
+ /* Set first language */
+ char* tmp_lang = NULL;
+ ret = stt_engine_get_first_language(&tmp_lang);
+ if (0 == ret && NULL != tmp_lang) {
+ g_engine_info->first_lang = strdup(tmp_lang);
+ free(tmp_lang);
} else {
- g_cur_engine.support_punctuation_override = true;
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get first language from engine : %s", g_engine_info->engine_name);
+ return ret;
}
- /* check and set silence detection */
- if (NULL == g_cur_engine.pefuncs->set_silence_detection) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence_detection of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
+#ifndef AUDIO_CREATE_ON_START
+ /* Ready recorder */
+ stte_audio_type_e atype;
+ int rate;
+ int channels;
- ret = g_cur_engine.pefuncs->set_silence_detection(g_cur_engine.silence_detection);
+ ret = stt_engine_get_audio_type(&atype, &rate, &channels);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Not support silence detection");
- g_cur_engine.support_silence_detection = false;
- } else {
- g_cur_engine.support_silence_detection = true;
- }
-
- /* select default language */
- bool set_voice = false;
- if (NULL != g_cur_engine.default_lang) {
- if (NULL == g_cur_engine.pefuncs->is_valid_lang) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_default_lang of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (true == g_cur_engine.pefuncs->is_valid_lang(g_cur_engine.default_lang)) {
- set_voice = true;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Set origin default voice to current engine : lang(%s)", g_cur_engine.default_lang);
- } else {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Fail set origin default language : lang(%s)", g_cur_engine.default_lang);
- }
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get audio type : %d %s", g_engine_info->engine_name);
+ return ret;
}
- if (false == set_voice) {
- if (NULL == g_cur_engine.pefuncs->foreach_langs) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_langs of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- /* get language list */
- int ret;
- GList* lang_list = NULL;
-
- ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, &lang_list);
-
- if (0 == ret && 0 < g_list_length(lang_list)) {
- GList *iter = NULL;
- iter = g_list_first(lang_list);
-
- if (NULL != iter) {
- char* temp_lang = iter->data;
-
- if (true != g_cur_engine.pefuncs->is_valid_lang(temp_lang)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail voice is NOT valid");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- sttd_config_set_default_language(temp_lang);
-
- g_cur_engine.default_lang = g_strdup(temp_lang);
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Select default voice : lang(%s)", temp_lang);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- __free_language_list(lang_list);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- }
-
- g_cur_engine.is_loaded = true;
+ ret = sttd_recorder_create(atype, channels, rate);
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %s", g_engine_info->engine_name);
+ return ret;
+ }
+#endif
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] The %s has been loaded !!!", g_cur_engine.engine_name);
+ g_engine_info->is_loaded = true;
+ SECURE_SLOG(LOG_INFO, TAG_STTD, "[Engine Agent SUCCESS] The %s has been loaded !!!", g_engine_info->engine_name);
return 0;
}
int sttd_engine_agent_unload_current_engine()
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_set) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_agent_unload_current_engine : No Current Engine ");
- return -1;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] Current engine has already been unloaded ");
- return 0;
- }
-
- /* shutdown engine */
- if (NULL == g_cur_engine.pefuncs->deinitialize) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] shutdown of engine is NULL!!");
- } else {
- g_cur_engine.pefuncs->deinitialize();
- }
-
- /* unload engine */
- if (0 != g_cur_engine.sttp_unload_engine()) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to unload engine");
- }
-
- dlclose(g_cur_engine.handle);
-
- /* reset current engine data */
- g_cur_engine.handle = NULL;
- g_cur_engine.is_loaded = false;
+ /* Remove client */
+ __engine_agent_check_engine_unload();
return 0;
}
-bool sttd_engine_agent_need_network()
+bool sttd_engine_agent_is_default_engine()
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- return g_cur_engine.need_network;
+ return true;
}
-int sttd_engine_get_option_supported(bool* silence, bool* profanity, bool* punctuation)
+int sttd_engine_agent_get_engine_list(GSList** engine_list)
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == silence || NULL == profanity || NULL == punctuation) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- *silence = g_cur_engine.support_silence_detection;
- *profanity = g_cur_engine.support_profanity_filter;
- *punctuation = g_cur_engine.support_punctuation_override;
-
- return 0;
-}
-
-/*
-* STT Engine Interfaces for client
-*/
-
-int __set_option(int profanity, int punctuation, int silence)
-{
- if (2 == profanity) {
- /* Default selection */
- if (g_default_profanity_filter != g_cur_engine.profanity_filter) {
- if (NULL != g_cur_engine.pefuncs->set_profanity_filter) {
- if (0 != g_cur_engine.pefuncs->set_profanity_filter(g_default_profanity_filter)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set profanity filter");
- return STTD_ERROR_OPERATION_FAILED;
- }
- g_cur_engine.profanity_filter = g_default_profanity_filter;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set profanity filter : %s", g_cur_engine.profanity_filter ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] profanity_filter() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- } else {
- /* Client selection */
- if (g_cur_engine.profanity_filter != profanity) {
- if (NULL != g_cur_engine.pefuncs->set_profanity_filter) {
- if (0 != g_cur_engine.pefuncs->set_profanity_filter((bool)profanity)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set profanity filter");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- g_cur_engine.profanity_filter = (bool)profanity;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set profanity filter : %s", g_cur_engine.profanity_filter ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] profanity_filter() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- }
-
- if (2 == punctuation) {
- /* Default selection */
- if (g_default_punctuation_override != g_cur_engine.punctuation_override) {
- if (NULL != g_cur_engine.pefuncs->set_punctuation) {
- if (0 != g_cur_engine.pefuncs->set_punctuation(g_default_punctuation_override)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override");
- return STTD_ERROR_OPERATION_FAILED;
- }
- g_cur_engine.punctuation_override = g_default_punctuation_override;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set punctuation override : %s", g_cur_engine.punctuation_override ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- } else {
- /* Client selection */
- if (g_cur_engine.punctuation_override != punctuation) {
- if (NULL != g_cur_engine.pefuncs->set_punctuation) {
- if (0 != g_cur_engine.pefuncs->set_punctuation((bool)punctuation)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- g_cur_engine.punctuation_override = (bool)punctuation;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set punctuation override : %s", g_cur_engine.punctuation_override ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_punctuation() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- }
-
- if (2 == silence) {
- /* Default selection */
- if (g_default_silence_detected != g_cur_engine.silence_detection) {
- if (NULL != g_cur_engine.pefuncs->set_silence_detection) {
- if (0 != g_cur_engine.pefuncs->set_silence_detection(g_default_silence_detected)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection");
- return STTD_ERROR_OPERATION_FAILED;
- }
- g_cur_engine.silence_detection = g_default_silence_detected;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_cur_engine.silence_detection ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- } else {
- /* Client selection */
- if (g_cur_engine.silence_detection != silence) {
- if (NULL != g_cur_engine.pefuncs->set_silence_detection) {
- if (0 != g_cur_engine.pefuncs->set_silence_detection((bool)silence)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection");
- return STTD_ERROR_OPERATION_FAILED;
- }
+ SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
- g_cur_engine.silence_detection = (bool)silence;
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_cur_engine.silence_detection ? "true" : "false");
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_silence() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
- }
-
return 0;
}
-int sttd_engine_recognize_start(const char* lang, const char* recognition_type,
- int profanity, int punctuation, int silence, void* user_param)
+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_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == lang || NULL == recognition_type) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ if (NULL == engine_uuid) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid parameter");
return STTD_ERROR_INVALID_PARAMETER;
}
- if (0 != __set_option(profanity, punctuation, silence)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set options");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == g_cur_engine.pefuncs->start) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] start() of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- char* temp;
- if (0 == strncmp(lang, "default", strlen("default"))) {
- temp = strdup(g_cur_engine.default_lang);
- } else {
- temp = strdup(lang);
- }
-
- int ret = g_cur_engine.pefuncs->start(temp, recognition_type, user_param);
- free(temp);
-
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_recognize_start : recognition start error(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] sttd_engine_recognize_start");
-
- return 0;
-}
-
-int sttd_engine_recognize_audio(const void* data, unsigned int length)
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == data) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ 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 (NULL == g_cur_engine.pefuncs->set_recording) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+ 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 = g_cur_engine.pefuncs->set_recording(data, length);
- if (0 != ret) {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
- return ret;
- }
+ *engine_uuid = strdup(g_engine_info->engine_uuid);
return 0;
}
-int sttd_engine_recognize_stop()
+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;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == g_cur_engine.pefuncs->stop) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
- }
+ if (NULL != g_engine_info)
+ return g_engine_info->use_network;
- int ret = g_cur_engine.pefuncs->stop();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- return 0;
+ return false;
}
-int sttd_engine_recognize_cancel()
+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_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == g_cur_engine.pefuncs->cancel) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- int ret = g_cur_engine.pefuncs->cancel();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- return 0;
-}
-
-int sttd_engine_get_audio_format(sttp_audio_type_e* types, int* rate, int* channels)
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == lang_list) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ 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 (NULL == g_cur_engine.pefuncs->get_audio_format) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+ 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 = g_cur_engine.pefuncs->get_audio_format(types, rate, channels);
+ int ret = stt_engine_get_supported_langs(lang_list);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get audio format error(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- return 0;
-}
-
-
-/*
-* STT Engine Interfaces for client and setting
-*/
-bool __supported_language_cb(const char* language, void* user_data)
-{
- GList** lang_list = (GList**)user_data;
-
- if (NULL == language || NULL == lang_list) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL in callback!!!!");
- return false;
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
}
- SLOG(LOG_DEBUG, TAG_STTD, "-- Language(%s)", language);
-
- char* temp_lang = g_strdup(language);
-
- *lang_list = g_list_append(*lang_list, temp_lang);
-
- return true;
+ return ret;
}
-int sttd_engine_supported_langs(GList** lang_list)
+int sttd_engine_agent_get_default_lang(char** lang)
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == g_cur_engine.pefuncs->foreach_langs) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == lang) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- int ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get language list error(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- return 0;
-}
-
-
-int sttd_engine_get_default_lang(char** lang)
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ /* get default language */
+ bool is_valid = false;
+ 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 STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == lang) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- /* get default language */
- *lang = g_strdup(g_cur_engine.default_lang);
+ if (true == is_valid) {
+ *lang = strdup(g_default_language);
+ } else
+ *lang = strdup(g_engine_info->first_lang);
return 0;
}
-int sttd_engine_is_partial_result_supported(bool* partial_result)
+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");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == key || NULL == data) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- if (NULL == partial_result) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ 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 (NULL == g_cur_engine.pefuncs->support_partial_result) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- *partial_result = g_cur_engine.pefuncs->support_partial_result();
+ /* set private data */
+ int ret = -1;
+ 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 0;
+ return ret;
}
-
-/*
-* STT Engine Interfaces for setting
-*/
-
-int sttd_engine_setting_get_engine_list(GList** engine_list)
+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");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == key || NULL == data) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- /* update engine list */
- if (0 != __internal_update_engine_list()) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] sttd_engine_setting_get_engine_list : __internal_update_engine_list()");
- return -1;
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- GList *iter = NULL;
- sttengine_info_s *data = NULL;
-
- iter = g_list_first(g_engine_list);
-
- SLOG(LOG_DEBUG, TAG_STTD, "----- [Engine Agent] engine list -----");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- while (NULL != iter) {
- engine_s* temp_engine;
+ /* get default language */
+ int ret = -1;
+ ret = stt_engine_get_private_data(key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get private data");
+ }
- temp_engine = (engine_s*)g_malloc0(sizeof(engine_s));
+ return ret;
+}
- data = iter->data;
+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_OPERATION_FAILED;
+ }
- temp_engine->engine_id = strdup(data->engine_uuid);
- temp_engine->engine_name = strdup(data->engine_name);
- temp_engine->ug_name = strdup(data->setting_ug_path);
+ if (NULL == silence) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
- *engine_list = g_list_append(*engine_list, temp_engine);
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
- iter = g_list_next(iter);
+ 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 id(%s) engine name(%s) ug name(%s) \n",
- temp_engine->engine_id, temp_engine->engine_name, temp_engine->ug_name);
+ bool temp = false;
+ if (0 != stt_engine_support_silence(&temp)) {
+ SLOG(LOG_WARN, TAG_STTD, "[WARNING] Fail to get support silence");
}
- SLOG(LOG_DEBUG, TAG_STTD, "--------------------------------------");
+ *silence = g_engine_info->support_silence_detection;
+ if (temp != *silence) {
+ SLOG(LOG_WARN, TAG_STTD, "[WARNING] Metadata and Engine spec are different (engine:%d) (meta:%d)", temp, *silence);
+ }
return 0;
}
-int sttd_engine_setting_get_engine(char** engine_id)
+int sttd_engine_agent_is_credential_needed(int uid, bool* credential)
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized" );
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
+ if (NULL == credential) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ 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 == g_engine_info->is_loaded) {
SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_ENGINE_NOT_FOUND;
+ return STTD_ERROR_OPERATION_FAILED;
}
- *engine_id = strdup(g_cur_engine.engine_uuid);
+ bool temp = false;
+ int ret;
+
+ 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;
+ }
+ *credential = temp;
return 0;
}
-int sttd_engine_setting_set_engine(const char* engine_id)
+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");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == engine_id) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ if (NULL == type || NULL == support) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
return STTD_ERROR_INVALID_PARAMETER;
}
- /* compare current engine and new engine. */
- if (NULL != g_cur_engine.engine_uuid) {
- if (0 == strncmp(g_cur_engine.engine_uuid, engine_id, strlen(g_cur_engine.engine_uuid))) {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] New engine is the same as current engine");
- return 0;
- }
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- char* tmp_uuid = NULL;
- tmp_uuid = g_strdup(g_cur_engine.engine_uuid);
- if (NULL == tmp_uuid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not enough memory!!");
- return STTD_ERROR_OUT_OF_MEMORY;
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ return STTD_ERROR_OPERATION_FAILED;
}
- /* unload engine */
- if (0 != sttd_engine_agent_unload_current_engine())
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to unload current engine");
- else
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] unload current engine");
-
- /* change current engine */
- if (0 != __internal_set_current_engine(engine_id)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] __internal_set_current_engine : no engine error");
-
- /* roll back to old current engine. */
- __internal_set_current_engine(tmp_uuid);
- sttd_engine_agent_load_current_engine();
+ bool temp = false;
+ int ret;
- if (NULL != tmp_uuid)
- free(tmp_uuid);
-
- return STTD_ERROR_OPERATION_FAILED;
+ 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 (0 != sttd_engine_agent_load_current_engine()) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to load new engine");
+ *support = temp;
- if (NULL != tmp_uuid)
- free(tmp_uuid);
-
- return STTD_ERROR_OPERATION_FAILED;
- }
+ return 0;
+}
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] sttd_engine_setting_set_engine() : Load new engine");
+/*
+* STT Engine Interfaces for client
+*/
- if( tmp_uuid != NULL )
- free(tmp_uuid);
+int __set_option(sttengine_info_s* engine, int silence)
+{
+ if (NULL == engine)
+ return -1;
- /* set engine id to config */
- if (0 != sttd_config_set_default_engine(engine_id)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set engine id");
+ /* Check silence detection */
+ if (engine->support_silence_detection) {
+ if (2 == silence) {
+ /* default option set */
+// if (g_default_silence_detected != engine->silence_detection) {
+ 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;
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", g_default_silence_detected ? "true" : "false");
+ }
+// }
+ } else {
+ if (silence != engine->silence_detection) {
+ 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;
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Set silence detection : %s", silence ? "true" : "false");
+ }
+ }
+ }
}
return 0;
}
-int sttd_engine_setting_get_lang_list(char** engine_id, GList** lang_list)
+int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type,
+ 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_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == lang_list || NULL == engine_id) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ if (NULL == lang || NULL == recognition_type) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
return STTD_ERROR_INVALID_PARAMETER;
}
- /* get language list from engine */
- int ret = sttd_engine_supported_langs(lang_list);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail get lang list (%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- *engine_id = strdup(g_cur_engine.engine_uuid);
-
- return 0;
-}
-
-int sttd_engine_setting_get_default_lang(char** language)
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ 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;
}
- if (NULL == language) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
+ SLOG(LOG_INFO, TAG_STTD, "g_default_language %s", g_default_language);
- if (NULL != g_cur_engine.default_lang) {
- *language = strdup(g_cur_engine.default_lang);
+ int ret;
+ char* temp = NULL;
+ if (0 == strncmp(lang, "default", strlen("default"))) {
+ bool is_valid = false;
+ 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;
+ }
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Get default lanaguae : language(%s)", *language);
- } else {
- if (NULL == g_cur_engine.pefuncs->foreach_langs) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_langs of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
+ if (true == is_valid) {
+ temp = strdup(g_default_language);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is %s", temp);
+ } else {
+ temp = strdup(g_engine_info->first_lang);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent DEBUG] Default language is engine first lang : %s", temp);
}
+ } else {
+ temp = strdup(lang);
+ }
- /* get language list */
- int ret;
- GList* lang_list = NULL;
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start engine");
- ret = g_cur_engine.pefuncs->foreach_langs(__supported_language_cb, &lang_list);
+ 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);
+ return ret;
+ }
- if (0 == ret && 0 < g_list_length(lang_list)) {
- GList *iter = NULL;
- iter = g_list_first(lang_list);
+#ifdef AUDIO_CREATE_ON_START
+ /* Ready recorder */
+ stte_audio_type_e atype;
+ int rate;
+ int channels;
- if (NULL != iter) {
- char* temp_lang = iter->data;
+ 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 : %s", g_engine_info->engine_name);
+ return ret;
+ }
- if (true != g_cur_engine.pefuncs->is_valid_lang(temp_lang)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail voice is NOT valid");
- return STTD_ERROR_OPERATION_FAILED;
- }
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Create recorder");
- sttd_config_set_default_language(temp_lang);
+ ret = sttd_recorder_create(atype, channels, rate);
+ if (0 != ret) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to create recorder : %s", g_engine_info->engine_name);
+ return ret;
+ }
+#endif
- g_cur_engine.default_lang = g_strdup(temp_lang);
+#if 0
+ SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start recorder(%d)", uid);
- *language = strdup(g_cur_engine.default_lang);
+ 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;
+ }
- SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent SUCCESS] Select default voice : lang(%s)", temp_lang);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
+#endif
- __free_language_list(lang_list);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine ERROR] Fail to get language list : result(%d)\n", ret);
- return STTD_ERROR_OPERATION_FAILED;
- }
- }
-
return 0;
}
-int sttd_engine_setting_set_default_lang(const char* language)
+int sttd_engine_agent_recognize_start_recorder(int uid)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ 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 (NULL == g_cur_engine.pefuncs->is_valid_lang) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] get_voice_list() of engine is NULL!!");
+ 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 = -1;
- if(false == g_cur_engine.pefuncs->is_valid_lang(language)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Language is NOT valid !!");
- return STTD_ERROR_INVALID_LANGUAGE;
- }
-
- if (NULL != g_cur_engine.default_lang)
- g_free(g_cur_engine.default_lang);
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start recorder");
- g_cur_engine.default_lang = strdup(language);
-
- ret = sttd_config_set_default_language(language);
+ int ret;
+ ret = sttd_recorder_start(uid);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret);
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
+ stt_engine_recognize_cancel();
+ sttd_recorder_stop();
+ return ret;
}
return 0;
}
-int sttd_engine_setting_get_profanity_filter(bool* value)
+int sttd_engine_agent_recognize_start_file(int uid, const char* filepath)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
- return STTD_ERROR_OPERATION_FAILED;
+ 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 == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == value) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
- }
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start recorder");
- *value = g_default_profanity_filter;
+ int ret;
+ ret = sttd_recorder_start_file(uid, filepath);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret);
+ stt_engine_recognize_cancel();
+ sttd_recorder_stop_file();
+ return ret;
+ }
return 0;
}
-int sttd_engine_setting_set_profanity_filter(bool value)
+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");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == data || 0 == length) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- if (NULL == g_cur_engine.pefuncs->set_profanity_filter) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- int ret = g_cur_engine.pefuncs->set_profanity_filter(value);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set profanity filter : result(%d)", ret);
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- g_default_profanity_filter = value;
-
- ret = sttd_config_set_default_profanity_filter((int)value);
+ int ret = stt_engine_set_recording_data(data, length);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set default lang (%d)", ret);
+ SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] set recording error(%d)", ret);
}
- return 0;
+ return ret;
}
-int sttd_engine_setting_get_punctuation_override(bool* value)
+int sttd_engine_agent_recognize_stop_file()
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ 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 == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == value) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Stop recorder");
+ int ret;
+ ret = sttd_recorder_stop_file();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
+ return ret;
}
- *value = g_default_punctuation_override;
+#ifdef AUDIO_CREATE_ON_START
+ SECURE_SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Destroy recorder");
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
+#endif
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent Success] Stop recorder");
return 0;
}
-int sttd_engine_setting_set_punctuation_override(bool value)
+int sttd_engine_agent_recognize_stop_recorder()
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ 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 (NULL == g_cur_engine.pefuncs->set_punctuation) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The function of engine is NULL!!");
+ 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 = g_cur_engine.pefuncs->set_punctuation(value);
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Stop recorder");
+ int ret;
+ ret = sttd_recorder_stop();
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set punctuation override : result(%d)", ret);
- return STTD_ERROR_OPERATION_FAILED;
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
+ return ret;
}
- g_default_punctuation_override = value;
- ret = sttd_config_set_default_punctuation_override((int)value);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set punctuation override (%d)", ret);
- }
+#ifdef 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
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent Success] Stop recorder");
return 0;
}
-int sttd_engine_setting_get_silence_detection(bool* value)
+int sttd_engine_agent_recognize_stop_engine()
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ 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 == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- if (NULL == value) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
- return STTD_ERROR_INVALID_PARAMETER;
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Stop engine");
+
+ int ret;
+ ret = stt_engine_recognize_stop();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] stop recognition error(%d)", ret);
+ return ret;
}
- *value = g_default_silence_detected;
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent Success] Stop engine");
return 0;
}
-int sttd_engine_setting_set_silence_detection(bool value)
+int sttd_engine_agent_recognize_cancel()
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == g_engine_info) {
+ SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- int ret = g_cur_engine.pefuncs->set_silence_detection(value);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set silence detection : result(%d)", ret);
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
-
- g_default_silence_detected = value;
- ret = sttd_config_set_default_silence_detection((int)value);
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Cancel engine");
+
+ int ret;
+ ret = stt_engine_recognize_cancel();
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set silence detection (%d)", ret);
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
+ return ret;
}
-
- return 0;
-}
-bool __engine_setting_cb(const char* key, const char* value, void* user_data)
-{
- GList** engine_setting_list = (GList**)user_data;
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Stop recorder");
- if (NULL == engine_setting_list || NULL == key || NULL == value) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL in engine setting callback!!!!");
- return false;
+ ret = sttd_recorder_stop();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to stop recorder : result(%d)", ret);
+ return ret;
}
- engine_setting_s* temp = g_malloc0(sizeof(engine_setting_s));
- temp->key = g_strdup(key);
- temp->value = g_strdup(value);
+#ifdef AUDIO_CREATE_ON_START
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Destroy recorder");
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
+#endif
- *engine_setting_list = g_list_append(*engine_setting_list, temp);
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent Success] Cancel recognition");
- return true;
+ return 0;
}
-int sttd_engine_setting_get_engine_setting_info(char** engine_id, GList** setting_list)
+
+/*
+* STT Engine Interfaces for configure
+*/
+
+int sttd_engine_agent_set_default_engine(const char* engine_uuid)
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
- return STTD_ERROR_OPERATION_FAILED;
+ if (NULL == engine_uuid) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
}
- if (NULL == setting_list) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Input parameter is NULL");
- return STTD_ERROR_INVALID_PARAMETER;
+ __log_enginelist();
+
+ if (NULL == g_engine_info) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Default engine is not valid");
+ return STTD_ERROR_ENGINE_NOT_FOUND;
}
- if (NULL == g_cur_engine.pefuncs->foreach_engine_settings) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] foreach_engine_settings() of engine is NULL!!");
+ SECURE_SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Default engine uuid(%s)", g_engine_info->engine_uuid);
+
+ return 0;
+}
+
+int sttd_engine_agent_set_default_language(const char* language)
+{
+ if (false == g_agent_init) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- /* get setting info and move setting info to input parameter */
- int result = 0;
+ if (NULL == language) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
- result = g_cur_engine.pefuncs->foreach_engine_settings(__engine_setting_cb, setting_list);
+ if (NULL != g_default_language)
+ free(g_default_language);
- if (0 == result && 0 < g_list_length(*setting_list)) {
- *engine_id = strdup(g_cur_engine.engine_uuid);
- } else {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] fail to get setting info : result(%d)\n", result);
- result = STTD_ERROR_OPERATION_FAILED;
- }
+ g_default_language = strdup(language);
- return result;
+ return 0;
}
-int sttd_engine_setting_set_engine_setting(const char* key, const char* value)
+int sttd_engine_agent_set_silence_detection(bool value)
{
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized");
return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
+ g_default_silence_detected = value;
+
+ return 0;
+}
+
+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;
}
- if (NULL == key || NULL == value) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter");
+ 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 (NULL == g_cur_engine.pefuncs->set_engine_setting) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] set_engine_setting() of engine is NULL!!");
+ if (false == g_engine_info->is_loaded) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine");
return STTD_ERROR_OPERATION_FAILED;
}
- /* get setting info and move setting info to input parameter */
- int ret = g_cur_engine.pefuncs->set_engine_setting(key, value);
+ int ret;
+ ret = stt_engine_check_app_agreed(appid, result);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail set setting info (%d) ", ret);
- return STTD_ERROR_OPERATION_FAILED;
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] cancel recognition error(%d)", ret);
+ return ret;
}
+
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Get engine right : %s", *result ? "true" : "false");
return 0;
}
-/*
-* STT Engine Callback Functions ` *
-*/
-
-void __result_cb(sttp_result_event_e event, const char* type,
- const char** data, int data_count, const char* msg, void *user_data)
+static void __recorder_destroy_by_error_result(void *data)
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized");
- return;
- }
-
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not loaded engine");
- return;
- }
+ SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Destroy recorder");
+ if (0 != sttd_recorder_destroy())
+ SECURE_SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Fail to destroy recorder");
- return g_result_cb(event, type, data, data_count, msg, user_data);
+ return;
}
-void __partial_result_cb(sttp_result_event_e event, const char* data, void *user_data)
+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 ret = -1;
+
if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Partial Result Callback : Not Initialized");
- return;
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Result Callback : Not Initialized");
+ return STTD_ERROR_OPERATION_FAILED;
}
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Partial Result Callback : Not loaded engine");
- return;
+ SLOG(LOG_INFO, TAG_STTD, "[Server] === Result time callback ===");
+
+ if (NULL != time_info) {
+ /* Get the time info */
+ 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;
+ }
}
- return g_partial_result_cb(event, data, user_data);
-}
+ SLOG(LOG_INFO, TAG_STTD, "[Server] ============================");
-void __detect_silence_cb(void* user_data)
-{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
- return;
- }
+ ret = g_result_cb(event, type, result, result_count, msg, user_data);
- if (false == g_cur_engine.is_loaded) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not loaded engine");
- return;
+#ifdef AUDIO_CREATE_ON_START
+ if (event == STTE_RESULT_EVENT_ERROR) {
+ ecore_main_loop_thread_safe_call_async(__recorder_destroy_by_error_result, NULL);
}
+#endif
- if (true == g_cur_engine.silence_detection) {
- g_silence_cb(user_data);
- } else {
- SLOG(LOG_WARN, TAG_STTD, "[Engine Agent] Silence detection callback is blocked because option value is false.");
- }
+ return ret;
}
-void __free_language_list(GList* lang_list)
+int sttd_engine_agent_send_error(stte_error_e error, const char* msg)
{
- GList *iter = NULL;
- char* data = NULL;
+ /* check uid */
+ int uid = stt_client_get_current_recognition();
- /* if list have item */
- if (g_list_length(lang_list) > 0) {
- /* Get a first item */
- iter = g_list_first(lang_list);
+ char* err_msg = NULL;
+ int ret = STTD_ERROR_NONE;
- while (NULL != iter) {
- data = iter->data;
- if (NULL != data)
- g_free(data);
-
- lang_list = g_list_remove_link(lang_list, iter);
+ if (NULL != msg) {
+ err_msg = strdup(msg);
+ }
- iter = g_list_first(lang_list);
- }
+ ret = sttdc_send_error_signal(uid, error, err_msg);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info.");
}
-}
-/* A function forging */
-int __log_enginelist()
-{
- GList *iter = NULL;
- sttengine_info_s *data = NULL;
+ if (NULL != err_msg) {
+ free(err_msg);
+ err_msg = NULL;
+ }
- if (0 < g_list_length(g_engine_list)) {
+ ret = g_error_cb(error, msg);
- /* Get a first item */
- iter = g_list_first(g_engine_list);
+ return ret;
+}
- SLOG(LOG_DEBUG, TAG_STTD, "--------------- engine list -------------------");
+int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data)
+{
+ int ret = STTD_ERROR_NONE;
+ if (false == g_agent_init) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Silence Callback : Not Initialized");
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- int i = 1;
- while (NULL != iter) {
- /* Get handle data from list */
- data = iter->data;
+ ret = g_speech_status_cb(status, user_data);
+ return ret;
+}
- SLOG(LOG_DEBUG, TAG_STTD, "[%dth]", i);
- SLOG(LOG_DEBUG, TAG_STTD, " engine uuid : %s", data->engine_uuid);
- SLOG(LOG_DEBUG, TAG_STTD, " engine name : %s", data->engine_name);
- SLOG(LOG_DEBUG, TAG_STTD, " engine path : %s", data->engine_path);
- SLOG(LOG_DEBUG, TAG_STTD, " setting ug path : %s", data->setting_ug_path);
+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);
+}
- iter = g_list_next(iter);
- i++;
+/* A function forging */
+int __log_enginelist()
+{
+ 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;
}
-
-
-