#include "sttd_recorder.h"
#include "sttd_server.h"
+
+#define CLIENT_CLEAN_UP_TIME 500
+
+
static pthread_mutex_t stte_result_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t stte_result_time_mutex = PTHREAD_MUTEX_INITIALIZER;
static double g_recording_timeout = 60;
+static Ecore_Timer* g_check_client_timer = NULL;
Ecore_Timer* g_recording_timer = NULL;
Ecore_Timer* g_processing_timer = NULL;
g_recording_timer = NULL;
}
+ int ret = 0;
int uid = 0;
uid = stt_client_get_current_recognition();
- if (0 != uid) {
- /* cancel engine recognition */
- int ret = sttd_engine_agent_recognize_cancel();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
- }
+ app_state_e state = 0;
+ ret = sttd_client_get_state(uid, &state);
- /* change uid state */
- sttd_client_set_state(uid, APP_STATE_READY);
- stt_client_unset_current_recognition();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
+ return;
+ }
- ret = sttdc_send_set_state(uid, (int)APP_STATE_READY);
+ if (0 != uid && (APP_STATE_PROCESSING == state || APP_STATE_RECORDING == state)) {
+ /* cancel engine recognition */
+ ret = sttd_server_cancel(uid);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send state change : result(%d)", ret);
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
}
} else {
SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] uid is NOT valid");
sttd_config_time_save();
sttd_config_time_reset();
+ sttd_recorder_clear();
+
sttd_client_set_state(uid, APP_STATE_READY);
stt_client_unset_current_recognition();
}
sttd_config_time_reset();
+ int ret = 0;
+ if (APP_STATE_RECORDING == state) {
+ ret = sttd_engine_agent_recognize_cancel();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel: result(%d)", ret);
+ }
+ }
+
sttd_client_set_state(uid, APP_STATE_READY);
stt_client_unset_current_recognition();
{
pthread_mutex_lock(&stte_result_time_mutex);
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] index(%d) event(%d) text(%s) start(%ld) end(%ld)",
+ SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Server] index(%d) event(%d) text(%s) start(%ld) end(%ld)",
index, event, text, start_time, end_time);
int ret;
return STTD_ERROR_OPERATION_FAILED;
}
- if (APP_STATE_RECORDING != state) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording");
+ if (APP_STATE_RECORDING != state && APP_STATE_PROCESSING != state) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording, state(%d), status(%d)", state, status);
return STTD_ERROR_INVALID_STATE;
}
SLOG(LOG_DEBUG, TAG_STTD, "[Server] New default engine : %s", engine_id);
}
+#if 0
/* need to change state of app to ready */
int uid;
uid = stt_client_get_current_recognition();
ret = sttd_engine_agent_set_silence_detection(support_silence);
if (0 != ret)
SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret);
+#endif
return;
}
return ret;
}
+ g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, sttd_cleanup_client, NULL);
+ if (NULL == g_check_client_timer) {
+ SLOG(LOG_WARN, TAG_STTD, "[Main Warning] Fail to create timer of client check");
+ }
+
SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] initialize");
return 0;
sttd_engine_agent_release();
+ if (NULL != g_check_client_timer) {
+ ecore_timer_del(g_check_client_timer);
+ g_check_client_timer = NULL;
+
+ SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete ecore timer handle");
+ }
+
return STTD_ERROR_NONE;
}
stt_network_finalize();
sttd_finalize();
+ sttd_dbus_close_connection();
ecore_main_loop_quit();
SLOG(LOG_DEBUG, TAG_STTD, "");
return;
}
- /* Notify uid state change */
- sttdc_send_set_state(uid, APP_STATE_RECORDING);
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
+ app_state_e temp_app_state;
+ if (0 != sttd_client_get_state(uid, &temp_app_state)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
+ return;
+ }
+ if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) {
+ /* Notify uid state change */
+ sttdc_send_set_state(uid, APP_STATE_RECORDING);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
+ }
}
void __sttd_start_sound_completed_cb(int id, void *user_data)
if (NULL != sound) {
int id = 0;
intptr_t puid = (intptr_t)uid;
- ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)puid, &id);
- if (WAV_PLAYER_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+ sound_stream_info_h wav_stream_info_h;
+ if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav");
is_sound_done = true;
+ } else {
+ ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_start_sound_completed_cb, (void*)puid, &id);
+ if (WAV_PLAYER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+ is_sound_done = true;
+ }
+
+ if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav");
+ }
}
free(sound);
sound = NULL;
g_recording_log_count = 0;
+ app_state_e temp_app_state;
+
if (true == is_sound_done) {
SLOG(LOG_DEBUG, TAG_STTD, "[Server] No sound play");
return ret;
}
- /* Notify uid state change */
- sttdc_send_set_state(uid, APP_STATE_RECORDING);
+ if (0 != sttd_client_get_state(uid, &temp_app_state)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+ if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) {
+ /* Notify uid state change */
+ sttdc_send_set_state(uid, APP_STATE_RECORDING);
+ }
SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
return STTD_RESULT_STATE_DONE;
if (NULL != sound) {
int id = 0;
intptr_t puid = (intptr_t)uid;
- ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_stop_sound_completed_cb, (void*)puid, &id);
- if (WAV_PLAYER_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+ sound_stream_info_h wav_stream_info_h;
+ if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav");
} else {
- SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound);
- }
+ ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_stop_sound_completed_cb, (void*)puid, &id);
+ if (WAV_PLAYER_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound);
+ }
+ if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav");
+ }
+ }
free(sound);
g_processing_timer = ecore_timer_add(g_processing_timeout, __time_out_for_processing, NULL);
return STTD_ERROR_NONE;
}
+
+int sttd_server_start_file(int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential,
+ const char* filepath, stte_audio_type_e audio_type, int sample_rate)
+{
+ if (NULL == lang || NULL == recognition_type || NULL == filepath) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check if uid is valid */
+ app_state_e state;
+ if (0 != sttd_client_get_state(uid, &state)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check uid state */
+ if (APP_STATE_READY != state) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] sttd_server_start : current state is not ready");
+ return STTD_ERROR_INVALID_STATE;
+ }
+
+ int ret = 0;
+ if (false == stt_client_get_app_agreed(uid)) {
+ bool temp = false;
+ ret = sttd_engine_agent_check_app_agreed(appid, &temp);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret);
+ return ret;
+ }
+
+ if (false == temp) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server] App(%s) NOT confirmed that engine is available", appid);
+ return STTD_ERROR_PERMISSION_DENIED;
+ }
+
+ stt_client_set_app_agreed(uid);
+ }
+
+ /* check if engine use network */
+ if (true == sttd_engine_agent_need_network()) {
+ if (false == stt_network_is_connected()) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
+ return STTD_ERROR_OUT_OF_NETWORK;
+ }
+ }
+
+ if (0 != stt_client_set_current_recognition(uid)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT is busy because of recording or processing");
+ return STTD_ERROR_RECORDER_BUSY;
+ }
+
+ /* engine start recognition */
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s), appid(%s), file(%s), audio_type(%d), sample_rate(%d)", uid, lang, recognition_type, appid, filepath, audio_type, sample_rate);
+
+ /* 1. Set audio session */
+ ret = sttd_recorder_set_audio_session();
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set session : %d", ret);
+ return ret;
+ }
+
+ /* 2. Start engine to recognize */
+ ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, appid, credential, NULL);
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ sttd_recorder_unset_audio_session();
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start engine : result(%d)", ret);
+ return ret;
+ }
+
+ sttd_client_set_state(uid, APP_STATE_RECORDING);
+ sttdc_send_set_state(uid, APP_STATE_RECORDING);
+
+ /* 3. Start to send pcm from file to engine */
+ ret = sttd_engine_agent_recognize_start_file(uid, filepath);
+ if (0 != ret) {
+ stt_client_unset_current_recognition();
+ sttd_recorder_unset_audio_session();
+ sttd_engine_agent_recognize_cancel();
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start file : result(%d)", ret);
+ return ret;
+ }
+
+ /* 4. Stop to send pcm from file */
+ ret = sttd_engine_agent_recognize_stop_file();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop recorder : result(%d)", ret);
+ stt_client_unset_current_recognition();
+ sttd_recorder_unset_audio_session();
+ sttd_engine_agent_recognize_cancel();
+ return ret;
+ }
+
+ /* 5. change & notify uid state */
+ sttd_client_set_state(uid, APP_STATE_PROCESSING);
+ sttdc_send_set_state(uid, APP_STATE_PROCESSING);
+
+ /* 6. Unset audio session */
+ ret = sttd_recorder_unset_audio_session();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret);
+ stt_client_unset_current_recognition();
+ return ret;
+ }
+
+ /* 7. Stop engine */
+ ret = sttd_engine_agent_recognize_stop_engine();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop engine : result(%d)", ret);
+ stt_client_unset_current_recognition();
+ return ret;
+ }
+
+ return STTD_ERROR_NONE;
+}
+
+int sttd_server_cancel_file(int uid)
+{
+ /* check if uid is valid */
+ app_state_e state;
+ if (0 != sttd_client_get_state(uid, &state)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check uid state */
+ if (APP_STATE_READY == state) {
+ SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is ready");
+ return STTD_ERROR_NONE;
+ }
+
+ stt_client_unset_current_recognition();
+
+ if (NULL != g_recording_timer) {
+ ecore_timer_del(g_recording_timer);
+ g_recording_timer = NULL;
+ }
+
+ if (NULL != g_processing_timer) {
+ ecore_timer_del(g_processing_timer);
+ g_processing_timer = NULL;
+ }
+
+ if (APP_STATE_RECORDING == state) {
+ /* Unset audio session */
+ int ret = sttd_recorder_unset_audio_session();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret);
+ return ret;
+ }
+ }
+
+ /* change uid state */
+ sttd_client_set_state(uid, APP_STATE_READY);
+
+ /* cancel engine recognition */
+ int ret = sttd_engine_agent_recognize_cancel();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
+ return ret;
+ }
+
+ /* Notify uid state change */
+ sttdc_send_set_state(uid, APP_STATE_READY);
+
+ return STTD_ERROR_NONE;
+}