From 3ebd30aad18da2f3fc8f643c4a3eb190d3aea642 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 23 Mar 2023 09:51:36 +0900 Subject: [PATCH] Cancel stop by silence timer when new recording is started - Issue: New recording can be stopped by previously reserved stop by silence timer. - Solution: This patch adds new code for managing stop by silence timer. And also, this patch adds new code for canceling this timer when sttd_server_start() is invoked. Through this patch, recording can be started on perfectly clear state. Change-Id: I578b66819ccb983a9c8c98203e058ecdb69b5c21 Signed-off-by: Suyeon Hwang --- server/sttd_server.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/server/sttd_server.c b/server/sttd_server.c index c5abc1e..99df629 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -44,6 +44,7 @@ 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; +static Ecore_Timer *g_stop_by_silence_timer = NULL; static int g_recording_log_count = 0; @@ -73,6 +74,7 @@ Eina_Bool __stop_by_silence(void *data) SLOG(LOG_INFO, TAG_STTD, "====="); SLOG(LOG_DEBUG, TAG_STTD, " "); + g_stop_by_silence_timer = NULL; return EINA_FALSE; } @@ -350,7 +352,9 @@ int __server_speech_status_callback(stte_speech_status_e status, void *user_para } else if (STTE_SPEECH_STATUS_END_POINT_DETECTED == status) { SLOG(LOG_DEBUG, TAG_STTD, "End Speech detected"); ecore_thread_main_loop_begin(); - ecore_timer_add(0, __stop_by_silence, NULL); + if (NULL == g_stop_by_silence_timer) { + g_stop_by_silence_timer = ecore_timer_add(0, __stop_by_silence, NULL); + } ecore_thread_main_loop_end(); } } else { @@ -710,6 +714,11 @@ int sttd_server_finalize(unsigned int uid) } } + if (NULL != g_stop_by_silence_timer) { + ecore_timer_del(g_stop_by_silence_timer); + g_stop_by_silence_timer = NULL; + } + SLOG(LOG_INFO, TAG_STTD, "[Server INFO] stt_cancel is invoked while state is (%d)", state); if (0 != sttd_engine_agent_recognize_cancel(uid)) { @@ -1196,6 +1205,11 @@ int sttd_server_start(unsigned int uid, const char* lang, const char* recognitio return ret; } + 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; + } + if (NULL != g_recording_timer) { ecore_timer_del(g_recording_timer); g_recording_timer = NULL; @@ -1207,6 +1221,11 @@ int sttd_server_start(unsigned int uid, const char* lang, const char* recognitio g_processing_timer = NULL; } + if (NULL != g_stop_by_silence_timer) { + ecore_timer_del(g_stop_by_silence_timer); + g_stop_by_silence_timer = NULL; + } + char* sound = NULL; ret = sttd_client_get_start_sound(uid, &sound); if (0 != ret) { @@ -1221,12 +1240,6 @@ int sttd_server_start(unsigned int uid, const char* lang, const char* recognitio return ret; } - if (0 != stt_client_set_current_recognition(uid)) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT is busy because of recording or processing"); - if (NULL != sound) free(sound); - return STTD_ERROR_RECORDER_BUSY; - } - /* engine start recognition */ SLOG(LOG_INFO, TAG_STTD, "[Server] start : uid(%u), lang(%s), recog_type(%s)", uid, lang, recognition_type); @@ -1437,6 +1450,11 @@ int sttd_server_stop(unsigned int uid) g_processing_timer = NULL; } + if (NULL != g_stop_by_silence_timer) { + ecore_timer_del(g_stop_by_silence_timer); + g_stop_by_silence_timer = NULL; + } + char* sound = NULL; if (0 != sttd_client_get_stop_sound(uid, &sound)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get start beep sound"); @@ -1541,6 +1559,11 @@ static int __sttd_server_cancel(unsigned int uid) g_processing_timer = NULL; } + if (NULL != g_stop_by_silence_timer) { + ecore_timer_del(g_stop_by_silence_timer); + g_stop_by_silence_timer = NULL; + } + if (APP_STATE_RECORDING == state) { /* Unset audio session */ int ret = sttd_recorder_unset_audio_session(); @@ -1676,4 +1699,4 @@ int sttd_server_cancel_file(unsigned int uid) SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End sttd_server_cancel_file"); return ret; -} \ No newline at end of file +} -- 2.7.4