mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
}
-static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
+static void handle_speech_streaming_event_success(void *data)
{
- if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
- ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
+ if (NULL == data) return;
+
+ mas_speech_data* speech_data = data;
+ if (NULL == speech_data->buffer) {
+ free(speech_data);
return;
}
+
static int count = 0;
- if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
- MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)", event, buffer, len);
+ if (speech_data->event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
+ MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
+ speech_data->event, speech_data->buffer, speech_data->len);
}
++count;
if (pid == -1) {
MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
} else {
- if (__validate_streaming_event_order(pid, &event)) {
- int ret = masc_dbus_send_streaming_audio_data(pid, event, buffer, len);
+ if (__validate_streaming_event_order(pid, &(speech_data->event))) {
+ int ret = masc_dbus_send_streaming_audio_data(pid,
+ speech_data->event, speech_data->buffer, speech_data->len);
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
}
if (pid != preprocessing_pid && -1 != preprocessing_pid) {
- int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid, event, buffer, len);
+ int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid,
+ speech_data->event, speech_data->buffer, speech_data->len);
if (0 != ret) {
MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
}
}
#ifdef BUF_SAVE_MODE
- /* write pcm buffer */
if (g_pFile)
- fwrite(buffer, 1, len, g_pFile);
+ fwrite(speech_data->buffer, 1, speech_data->len, g_pFile);
- if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == speech_data->event) {
if (g_pFile) {
MAS_LOGE("[Recorder SUCCESS] File Close");
fclose(g_pFile);
}
}
#endif
+ free(speech_data->buffer);
+ free(speech_data);
+}
+
+static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
+{
+ if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
+ ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
+ } else {
+ mas_speech_data* data = malloc(sizeof(mas_speech_data));
+ if (data) {
+ data->event = event;
+ data->buffer = malloc(len);
+ if (data->buffer) memcpy(data->buffer, buffer, len);
+ data->len = len;
+ ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_success, data);
+ }
+ }
}
static void __speech_status_cb(mas_speech_status_e status, void *user_data)