#include <assert.h>
#include <vconf.h>
#include <vconf-keys.h>
+#include <sound_manager.h>
#include "Debug.h"
#include "SttManager.h"
CREATE = 0x1000
};
+static sound_stream_info_h g_stream_info_h = NULL;
+
static inline const char *stt_state_str(stt_state_e cur) {
if (cur == STT_STATE_CREATED)
return (const char *) "STT_STATE_CREATED";
return (const char *) "ABNORMAL CASE";
}
+static void player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
+ sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data)
+{
+}
+
SttManager::SttManager(ISttFeedback& feedback)
: ifeedback(feedback),
iscancelled(false)
if(ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
+ ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, player_focus_state_cb, NULL, &g_stream_info_h);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ LOGW("Fail to create stream info. ret : %d", ret);
+ }
+
/**
* Set default properties
*
PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
stt_destroy(handle);
}
+
+ ReleaseSoundFocus();
+
+ sound_manager_destroy_stream_information(g_stream_info_h);
}
void SttManager::Prepare() {
asrtype = STT_RECOGNITION_TYPE_FREE_PARTIAL;
int ret;
- bool bval = false;
-
-// stt_is_samsung_asr(&bval);
-
- if( bval == true && !language.compare("en_GB")) {
- PRINTFUNC(DLOG_DEBUG, "en_GB requested, change to en_US");
- ret = stt_start(handle, "en_US", asrtype.c_str());
- } else {
- ret = stt_start(handle, language.c_str(), asrtype.c_str());
+ ret = sound_manager_acquire_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), SOUND_BEHAVIOR_NONE, NULL);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ LOGW("Fail to acquire playback or recording focus. ret : %d, stream handle : %p", ret, g_stream_info_h);
}
+ ret = stt_start(handle, language.c_str(), asrtype.c_str());
+
if(ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
}
SttManager& manager = *((SttManager *) user_data);
if (current== STT_STATE_READY) {
+ if (previous == STT_STATE_RECORDING ||
+ previous == STT_STATE_PROCESSING) {
+ ReleaseSoundFocus();
+ }
+
if (previous == STT_STATE_CREATED) {
manager.EnableSilenceDetection();
manager.ifeedback.AutoStart();
}
}
+void SttManager::ReleaseSoundFocus()
+{
+ int ret = sound_manager_release_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), SOUND_BEHAVIOR_NONE, NULL);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ LOGW("Fail to release playback or recording focus. ret : %d", ret);
+ }
+}