From 523f342a8445391ac326655b2e0f69c26991fca7 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 5 Oct 2016 13:32:34 +0900 Subject: [PATCH] Stop playing sound when starting STT Change-Id: I02ad9dbf60fc5f0a11943ad4175604f95560068c Signed-off-by: Jihoon Kim --- CMakeLists.txt | 1 + packaging/ise-default.spec | 1 + src/SttManager.cpp | 34 ++++++++++++++++++++++++++++++++++ src/include/SttManager.h | 1 + 4 files changed, 37 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25cb6dd..35b6f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ pkg_check_modules(ISE_PKGS REQUIRED libxml-2.0 stt capi-appfw-application + capi-media-audio-io ) FOREACH(flag ${ISE_PKGS_CFLAGS}) diff --git a/packaging/ise-default.spec b/packaging/ise-default.spec index 211631a..3431716 100644 --- a/packaging/ise-default.spec +++ b/packaging/ise-default.spec @@ -22,6 +22,7 @@ BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(stt) BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(capi-media-audio-io) BuildRequires: model-build-features diff --git a/src/SttManager.cpp b/src/SttManager.cpp index 994edca..f8251f9 100644 --- a/src/SttManager.cpp +++ b/src/SttManager.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "SttManager.h" #include "ise-stt-mode.h" @@ -31,6 +32,8 @@ enum { 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) @@ -45,6 +48,10 @@ static inline const char *stt_state_str(stt_state_e cur) return (const char *) "ABNORMAL CASE"; } +static void player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *extra_info, void *user_data) +{ +} + SttManager::SttManager(ISttFeedback& feedback) : ifeedback(feedback), iscancelled(false) @@ -59,6 +66,11 @@ SttManager::SttManager(ISttFeedback& feedback) 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 * @@ -82,6 +94,10 @@ SttManager::~SttManager() { LOGD("reason : %s", e.what()); stt_destroy(handle); } + + ReleaseSoundFocus(); + + sound_manager_destroy_stream_information(g_stream_info_h); } void SttManager::Prepare() { @@ -121,6 +137,12 @@ void SttManager::Start() { */ asrtype = STT_RECOGNITION_TYPE_FREE_PARTIAL; int ret; + + ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL); + if (SOUND_MANAGER_ERROR_NONE != ret) { + LOGW("Fail to acquire 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) @@ -317,6 +339,11 @@ void SttManager::on_state_changed( 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(); @@ -504,3 +531,10 @@ void SttManager::EnableSilenceDetection(bool enabled) { } } +void SttManager::ReleaseSoundFocus() +{ + int ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL); + if (SOUND_MANAGER_ERROR_NONE != ret) { + LOGW("Fail to release focus. ret : %d", ret); + } +} diff --git a/src/include/SttManager.h b/src/include/SttManager.h index 8e89ec7..bec6ea4 100644 --- a/src/include/SttManager.h +++ b/src/include/SttManager.h @@ -223,6 +223,7 @@ class SttManager static void PrintErrorState(stt_error_e reason); static void PrintState(stt_state_e previous, stt_state_e current); static void PrintResultState(stt_result_event_e result_type); + static void ReleaseSoundFocus(); }; }} /** end of is::stt */ -- 2.7.4