Stop playing sound when starting STT 31/90931/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 5 Oct 2016 04:32:34 +0000 (13:32 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 5 Oct 2016 04:32:38 +0000 (13:32 +0900)
Change-Id: I02ad9dbf60fc5f0a11943ad4175604f95560068c
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
packaging/ise-default.spec
src/SttManager.cpp
src/include/SttManager.h

index 25cb6dd..35b6f89 100644 (file)
@@ -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})
index 211631a..3431716 100644 (file)
@@ -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
 
 
index 994edca..f8251f9 100644 (file)
@@ -17,6 +17,7 @@
 #include <assert.h>
 #include <vconf.h>
 #include <vconf-keys.h>
+#include <sound_manager.h>
 
 #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);
+    }
+}
index 8e89ec7..bec6ea4 100644 (file)
@@ -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 */