/*
-* Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
static GSList* g_engine_list;
-static int g_engine_id_count = 0;
-
#define STT_FILE_CONFIG_HANDLE 100000
-const char* stt_tag()
-{
- return TAG_STTFC;
-}
-
static const char* __stt_file_get_error_code(stt_file_error_e err)
{
switch (err) {
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);
if ((error = dlerror()) != NULL || NULL == get_engine_info) {
SLOG(LOG_WARN, TAG_STTFC, "[Engine Agent WARNING] Invalid engine. Fail to open sttp_get_engine_info : %s", error);
dlclose(handle);
- return -1;
+ return STT_FILE_ERROR_ENGINE_NOT_FOUND;
}
sttengine_info_s* temp;
SLOG(LOG_DEBUG, TAG_STTFC, " ");
*info = temp;
+#endif
return STT_FILE_ERROR_NONE;
}
return false;
}
-void __stt_file_relseae_engine_info()
+void __stt_file_relseae_engine_info(void)
{
GSList *iter = NULL;
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,
+int __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)
{
/* check handle */
if (NULL == client) {
SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Fail to notify error : A handle is not valid");
- return;
+ return STT_FILE_ERROR_OPERATION_FAILED;
}
if (NULL != time_info) {
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;
+ return STT_FILE_ERROR_NONE;
}
-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;
return STT_FILE_ERROR_NONE;
}
-int stt_file_initialize()
+int stt_file_initialize(void)
{
SLOG(LOG_DEBUG, TAG_STTFC, "===== Initialize STT FILE");
}
if (NULL != dirp) {
- sttengine_info_s* info;
+ if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
+ continue;
+
+ sttengine_info_s* info = NULL;
char* filepath;
int filesize;
}
}
- if (NULL != engine_id) free(engine_id);
+ if (NULL != engine_id) {
+ free(engine_id);
+ engine_id = NULL;
+ }
if (false == is_found) {
+ engine = NULL;
SLOG(LOG_WARN, TAG_STTFC, "[STT FILE WARNING] Fail to find default engine");
iter = g_slist_nth(g_engine_list, 0);
- engine = iter->data;
+ if (NULL != iter)
+ engine = iter->data;
if (NULL == engine) {
SLOG(LOG_ERROR, TAG_STTFC, "[Engine Agent ERROR] Fail to initialize engine");
return STT_FILE_ERROR_NONE;
}
-int stt_file_deinitialize()
+int stt_file_deinitialize(void)
{
SLOG(LOG_DEBUG, TAG_STTFC, "===== Deinitialize STT FILE");
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 */
*state = client->current_state;
switch (*state) {
- case STT_FILE_STATE_NONE: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'NONE'"); break;
- case STT_FILE_STATE_READY: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Ready'"); break;
- case STT_FILE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Processing'"); break;
- default: SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid value"); break;
+ case STT_FILE_STATE_NONE: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'NONE'"); break;
+ case STT_FILE_STATE_READY: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Ready'"); break;
+ case STT_FILE_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTFC, "Current state is 'Processing'"); break;
+ default: SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid value"); break;
}
return STT_FILE_ERROR_NONE;
}
if (client->current_state != STT_FILE_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", client->current_state);
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
SLOG(LOG_DEBUG, TAG_STTFC, " ");
return STT_FILE_ERROR_INVALID_STATE;
}
if (client->current_state != STT_FILE_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", client->current_state);
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
SLOG(LOG_DEBUG, TAG_STTFC, " ");
return STT_FILE_ERROR_INVALID_STATE;
/* check state */
if (client->current_state != STT_FILE_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not 'Ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", client->current_state);
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
SLOG(LOG_DEBUG, TAG_STTFC, " ");
return STT_FILE_ERROR_INVALID_STATE;
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, "=====");
return STT_FILE_ERROR_NONE;
}
-int stt_file_start(const char* language, const char* type, const char* filepath,
+int stt_file_start(const char* language, const char* type, const char* filepath,
stt_file_audio_type_e audio_type, int sample_rate)
{
SLOG(LOG_DEBUG, TAG_STTFC, "===== STT FILE START");
/* check state */
if (client->current_state != STT_FILE_STATE_READY) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state is not READY");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
SLOG(LOG_DEBUG, TAG_STTFC, " ");
return STT_FILE_ERROR_INVALID_STATE;
}
SLOG(LOG_DEBUG, TAG_STTFC, "[START Info] Engine(%d) Lang(%s) Type(%s) Filepath(%s) Audio(%d) Sample rate(%d)",
- , client->current_engine_id, language, type, filepath, audio_type, sample_rate);
+ 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, "=====");
return STT_FILE_ERROR_NONE;
}
-int stt_file_cancel()
+int stt_file_cancel(void)
{
SLOG(LOG_DEBUG, TAG_STTFC, "===== STT FILE CANCEL");
/* check state */
if (STT_FILE_STATE_PROCESSING != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid state : Current state is NOT 'Processing'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Invalid state : Current state(%d) is NOT 'Processing'", client->current_state);
SLOG(LOG_DEBUG, TAG_STTFC, "=====");
SLOG(LOG_DEBUG, TAG_STTFC, " ");
return STT_FILE_ERROR_INVALID_STATE;
}
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);
+ index, event, text, start_time, end_time);
stt_file_client_s* client = stt_file_client_get();
}
if (NULL != client->result_time_cb) {
- client->result_time_cb(index, (stt_file_result_time_event_e)event,
+ client->result_time_cb(index, (stt_file_result_time_event_e)event,
text, start_time, end_time, client->result_time_user_data);
} else {
SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Callback is NULL");
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;
}
if (STT_FILE_STATE_READY != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state(%d) is not 'ready'", client->current_state);
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()
+int stt_file_unset_recognition_result_cb(void)
{
stt_file_client_s* client = stt_file_client_get();
}
if (STT_FILE_STATE_READY != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state(%d) is not 'ready'", client->current_state);
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)
}
if (STT_FILE_STATE_READY != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state(%d) is not 'ready'", client->current_state);
return STT_FILE_ERROR_INVALID_STATE;
}
return 0;
}
-int stt_file_unset_state_changed_cb()
+int stt_file_unset_state_changed_cb(void)
{
stt_file_client_s* client = stt_file_client_get();
}
if (STT_FILE_STATE_READY != client->current_state) {
- SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state is not 'ready'");
+ SLOG(LOG_ERROR, TAG_STTFC, "[ERROR] Current state(%d) is not 'ready'", client->current_state);
return STT_FILE_ERROR_INVALID_STATE;
}