Browse Source

新增一个唤醒词,同时检测两个唤醒词

corvin 5 years ago
parent
commit
7d17c06f9a

+ 40 - 44
catkin_ws/src/snowboy_wakeup/include/hotword_detector.h

@@ -5,49 +5,45 @@
 
 namespace snowboy_wakeup
 {
-
-//!
-//! \brief The HotwordDetector class wraps Snowboy detect so we can use C++ 11
-//!
-class HotwordDetector
-{
-
-public:
-
-  HotwordDetector();
-  ~HotwordDetector();
-
-  //!
-  //! \brief initialize Initializes the Snowbody
-  //! \param [in]  resource_filename   Filename of resource file.
-  //! \param [in]  model_str           A string of multiple hotword models,
-  //!
-  void initialize(const char* resource_filename, const char* model_filename);
-
-  //!
-  //! \brief configure Configure the detector on runtime
-  //! \param sensitivity Hotword sensitivity
-  //! \param audio_gain Fixed gain to the input audio.
-  //! \return True if success, False otherwise
-  //!
-  bool configure(double sensitivity, double audio_gain);
-
-  //!
-  //! \brief runDetection Runs hotword detection of Snowboy, see Snowboy API for more docs
-  //! \param data Small chunk of data to be detected
-  //! \param array_length Length of the data array.
-  //! \return -3 not initialized, -2 Silence, -1 Error, 0 No event, 1 Hotword triggered
-  //!
-  int runDetection(const int16_t* const data, const int array_length);
-
-private:
-
-  //!
-  //! \brief detector_ Instance of Snowboy detect
-  //!
-  snowboy::SnowboyDetect* detector_;
-};
-
-}  // namespace snowboy_wakeup
+    //!
+    //! \brief The HotwordDetector class wraps Snowboy detect so we can use C++ 11
+    //!
+    class HotwordDetector
+    {
+        public:
+            HotwordDetector();
+            ~HotwordDetector();
+
+            //!
+            //! \brief initialize Initializes the Snowbody
+            //! \param [in]  resource_filename   Filename of resource file.
+            //! \param [in]  model_str           A string of multiple hotword models,
+            //!
+            void initialize(const char* resource_filename, const char* model_filename);
+
+            //!
+            //! \brief configure Configure the detector on runtime
+            //! \param sensitivity Hotword sensitivity
+            //! \param audio_gain Fixed gain to the input audio.
+            //! \return True if success, False otherwise
+            //!
+            bool configure(double sensitivity, double audio_gain);
+
+            //!
+            //! \brief runDetection Runs hotword detection of Snowboy, see Snowboy API for more docs
+            //! \param data Small chunk of data to be detected
+            //! \param array_length Length of the data array.
+            //! \return -3 not initialized, -2 Silence, -1 Error, 0 No event, 1 Hotword triggered
+            //!
+            int runDetection(const int16_t* const data, const int array_length);
+
+        private:
+            //!
+            //! \brief detector_ Instance of Snowboy detect
+            //!
+            snowboy::SnowboyDetect* detector_;
+    };
+}// namespace snowboy_wakeup
 
 #endif  // SNOWBOY_ROS_HOTWORD_DETECTOR_H_
+

+ 2 - 1
catkin_ws/src/snowboy_wakeup/launch/snowboy_wakeup.launch

@@ -13,7 +13,8 @@
 
     <node pkg="snowboy_wakeup" type="hotword_detector_node" name="snowboy_wakeup" respawn="true">
         <param name="resource_filename" value="$(find snowboy_wakeup)/resources/common.res" />
-        <param name="model_filename" value="$(find snowboy_wakeup)/resources/snowboy.umdl" />
+        <param name="model_filename" value="$(find snowboy_wakeup)/resources/snowboy.umdl,
+                                            $(find snowboy_wakeup)/resources/corvin.pmdl" />
 
         <param name="sensitivity_str" value="0.7" type="str" />
         <param name="audio_gain" value="1.0" />

+ 12 - 12
catkin_ws/src/snowboy_wakeup/src/hotword_detector_node.cpp

@@ -6,8 +6,6 @@
 #include <hotword_detector.h>
 
 
-#define  ASR_START_FLAG  1  //detect hotword then start ASR
-
 namespace snowboy_wakeup
 {
     //!
@@ -59,10 +57,6 @@ namespace snowboy_wakeup
             }
 
         private:
-
-            //!
-            //! \brief nh_ Global nodehandle for topics
-            //!
             ros::NodeHandle nh_;
 
             //!
@@ -112,15 +106,21 @@ namespace snowboy_wakeup
                         sample_array[i/2] = ((int16_t) (msg->data[i+1]) << 8) + (int16_t) (msg->data[i]);
                     }
 
-                    int result = detector_.runDetection( &sample_array[0], msg->data.size()/2);
-                    if (result > 0)
+                    std_msgs::Int32 hotword_msg;
+                    int result = detector_.runDetection( &sample_array[0], msg->data.size()/2);                    
+                    if (result == 1)
                     {
-                        ROS_DEBUG("Hotword detected!");
-
+                        ROS_INFO("Hotword 1 detected!");
+                        hotword_msg.data = result;
+                        hotword_pub_.publish(hotword_msg);
                         system("play -q --multi-threaded ~/Music/ding.wav");
-                        std_msgs::Int32 hotword_msg;
-                        hotword_msg.data = ASR_START_FLAG;
+                    }
+                    else if(result == 2)
+                    {
+                        ROS_INFO("Hotword 2 detected!");
+                        hotword_msg.data = result;
                         hotword_pub_.publish(hotword_msg);
+                        system("play -q --multi-threaded ~/Music/dong.wav");
                     }
                     else if (result == -3)
                     {