Stop playing sound when starting STT 56/91356/2
authorsungwook79.park <sungwook79.park@samsung.com>
Fri, 7 Oct 2016 06:39:53 +0000 (15:39 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Mon, 10 Oct 2016 01:18:37 +0000 (10:18 +0900)
Change-Id: I3426487ad9ac3b90430748ca09654e71c950583f
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
inc/SttManager.h
packaging/org.tizen.inputdelegator.spec
src/CMakeLists.txt
src/SttManager.cpp

index 68a9a24..8b76f5e 100755 (executable)
@@ -221,6 +221,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 */
index 9a74048..efc6250 100755 (executable)
@@ -30,6 +30,7 @@ BuildRequires: pkgconfig(stt)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(db-util)
 BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(capi-media-audio-io)
 
 
 %if %{enable_log_manager}
index 01749a5..74963d3 100755 (executable)
@@ -11,6 +11,7 @@ PKG_CHECK_MODULES(STT REQUIRED stt)
 PKG_CHECK_MODULES(VCONF REQUIRED vconf)
 PKG_CHECK_MODULES(DB_UTIL_PKG REQUIRED db-util)
 PKG_CHECK_MODULES(SQLITE3_PKG REQUIRED sqlite3)
+pkg_check_modules(CAPI_MEDIA_AUDIO_IO REQUIRED capi-media-audio-io)
 #PKG_CHECK_MODULES(GRAPHICS_EXTENSION REQUIRED graphics-extension)
 #PKG_CHECK_MODULES(WNOTI_SERVICE REQUIRED wnoti-service2)
 #PKG_CHECK_MODULES(SAP_CLIENT_STUB_API REQUIRED sap-client-stub-api)
@@ -37,7 +38,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
                ${SQLITE3_PKG_INCLUDE_DIRS}
                ${DATA_CONTROL_INCLUDE_DIRS}
                ${WNOTI_SERVICE_INCLUDE_DIRS}
-               ${SAP_CLIENT_STUB_API_INCLUDE_DIRS})
+               ${SAP_CLIENT_STUB_API_INCLUDE_DIRS}
+               ${CAPI_MEDIA_AUDIO_IO_INCLUDE_DIRS})
 
 
 LINK_DIRECTORIES(${DLOG_LIBRARY_DIRS}
@@ -56,6 +58,7 @@ LINK_DIRECTORIES(${DLOG_LIBRARY_DIRS}
                ${VCONF_LIBRARY_DIRS}
                ${WNOTI_SERVICE_LIBRARY_DIRS}
                ${SAP_CLIENT_STUB_API_LIBRARY_DIRS}
+               ${CAPI_MEDIA_AUDIO_IO_LIBRARY_DIRS}
                )
 
 ADD_EXECUTABLE(${W_INPUT_SELECTOR}
@@ -75,6 +78,7 @@ TARGET_LINK_LIBRARIES(${W_INPUT_SELECTOR}
                ${DB_UTIL_PKG_LIBRARIES}
                ${SQLITE3_PKG_LIBRARIES}
                ${VCONF_LIBRARIES}
+               ${CAPI_MEDIA_AUDIO_IO_LIBRARIES}
                )
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
index 1be05a3..c4a080e 100755 (executable)
@@ -17,6 +17,7 @@
 #include <assert.h>
 #include <vconf.h>
 #include <vconf-keys.h>
+#include <sound_manager.h>
 
 #include "Debug.h"
 #include "SttManager.h"
@@ -30,6 +31,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)
                return (const char *) "STT_STATE_CREATED";
@@ -47,6 +50,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)
@@ -61,6 +68,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
                *
@@ -84,6 +96,10 @@ SttManager::~SttManager() {
                PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
                stt_destroy(handle);
        }
+
+       ReleaseSoundFocus();
+
+       sound_manager_destroy_stream_information(g_stream_info_h);
 }
 
 void SttManager::Prepare() {
@@ -123,7 +139,13 @@ void SttManager::Start() {
        */
        asrtype = STT_RECOGNITION_TYPE_FREE_PARTIAL;
        int ret;
-        ret = stt_start(handle, language.c_str(), asrtype.c_str());
+
+       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)
                throw SttException(ret, ErrorString((stt_error_e)ret));
@@ -318,6 +340,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();
@@ -525,3 +552,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);
+       }
+}