#include "sttd_main.h"
-#define FRAME_LENGTH 160
+#define FRAME_LENGTH 320
#define BUFFER_LENGTH FRAME_LENGTH * 2
static pthread_mutex_t sttd_audio_in_handle_mutex = PTHREAD_MUTEX_INITIALIZER;
+static Ecore_Timer* g_audio_timer = NULL;
+
typedef enum {
STTD_RECORDER_STATE_NONE = -1,
STTD_RECORDER_STATE_READY = 0, /**< Recorder is ready to start */
return 0;
}
-static float get_volume_decibel(char* data, int size, stte_audio_type_e type)
+float get_volume_decibel(char* data, int size, stte_audio_type_e type)
{
#define MAX_AMPLITUDE_MEAN_16 32768
#define MAX_AMPLITUDE_MEAN_08 128
return EINA_FALSE;
}
- if (0 == g_buffer_count % 30) {
+ if (NULL == g_recorder)
+ SLOG(LOG_WARN, TAG_STTD, "[Recorder] g_recorder is NULL. It is already stopped and destroyed.");
+
+ if (0 == g_buffer_count % 30 && NULL != g_recorder) {
float vol_db = get_volume_decibel(g_buffer, BUFFER_LENGTH, g_recorder->audio_type);
if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
}
/* Add ecore timer to read audio data */
- ecore_timer_add(0, __read_audio_func, NULL);
+ if (NULL != g_audio_timer) {
+ ecore_timer_del(g_audio_timer);
+ g_audio_timer = NULL;
+ }
+
+ g_audio_timer = ecore_timer_add(0, __read_audio_func, NULL);
+ if (NULL == g_audio_timer) {
+ SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail to create timer of read_audio");
+ return STTD_ERROR_OPERATION_FAILED;
+ }
#endif
g_recorder_state = STTD_RECORDER_STATE_RECORDING;
int ret = -1;
#ifndef TV_BT_MODE
+ if (NULL != g_audio_timer) {
+ ecore_timer_del(g_audio_timer);
+ g_audio_timer = NULL;
+ }
+
ret = audio_in_unprepare(g_recorder->audio_h);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
/*
* STT Server Callback Functions
*/
-void __stop_by_silence(void *data)
+static void __cancel_recognition_internal();
+
+Eina_Bool __stop_by_silence(void *data)
{
SLOG(LOG_INFO, TAG_STTD, "===== Stop by silence detection");
if (0 != uid) {
ret = sttd_server_stop(uid);
if (0 > ret) {
- return;
+ __cancel_recognition_internal();
+ return EINA_FALSE;
}
if (STTD_RESULT_STATE_DONE == ret) {
SLOG(LOG_INFO, TAG_STTD, "=====");
SLOG(LOG_DEBUG, TAG_STTD, " ");
- return;
+ return EINA_FALSE;
}
static void __cancel_recognition_internal()
sttdc_send_speech_status(uid, status);
} else if (STTE_SPEECH_STATUS_END_POINT_DETECTED == status) {
SLOG(LOG_DEBUG, TAG_STTD, "End Speech detected");
- ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL);
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(0, __stop_by_silence, NULL);
+ ecore_thread_main_loop_end();
}
} else {
SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current recognition uid is not valid ");