|
@@ -4,13 +4,17 @@
|
|
|
#include <audio_common_msgs/AudioData.h>
|
|
|
#include <dynamic_reconfigure/server.h>
|
|
|
#include <hotword_detector.h>
|
|
|
+#include <wiringPi.h>
|
|
|
|
|
|
+#define BTN_PIN 27
|
|
|
+volatile char btn_click = 0;
|
|
|
|
|
|
namespace snowboy_wakeup
|
|
|
{
|
|
|
std::string beep_filename;
|
|
|
std::string pre_param = "play -q --multi-threaded ";
|
|
|
std::string all_param;
|
|
|
+
|
|
|
//!
|
|
|
//! \brief The HotwordDetectorNode class Wraps the C++ 11 Snowboy detector in a ROS node
|
|
|
//!
|
|
@@ -22,6 +26,7 @@ namespace snowboy_wakeup
|
|
|
|
|
|
bool initialize()
|
|
|
{
|
|
|
+
|
|
|
std::string resource_filename;
|
|
|
if (!nh_p_.getParam("resource_filename", resource_filename))
|
|
|
{
|
|
@@ -86,6 +91,7 @@ namespace snowboy_wakeup
|
|
|
//!
|
|
|
HotwordDetector detector_;
|
|
|
|
|
|
+
|
|
|
//!
|
|
|
//! \brief reconfigureCallback Reconfigure update for sensitiviy and audio level
|
|
|
//! \param cfg The updated config
|
|
@@ -96,6 +102,7 @@ namespace snowboy_wakeup
|
|
|
ROS_INFO("SnowboyROS (Re)Configured");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//!
|
|
|
//! \brief audioCallback Audio stream callback
|
|
|
//! \param msg The audo data
|
|
@@ -117,10 +124,11 @@ namespace snowboy_wakeup
|
|
|
|
|
|
std_msgs::Int32 hotword_msg;
|
|
|
int result = detector_.runDetection( &sample_array[0], msg->data.size()/2);
|
|
|
- if (result == 1)
|
|
|
+ if (result == 1 || btn_click == 1)
|
|
|
{
|
|
|
+ btn_click = 0;
|
|
|
ROS_DEBUG("wakeUp detected!");
|
|
|
- hotword_msg.data = result;
|
|
|
+ hotword_msg.data = 1;
|
|
|
hotword_pub_.publish(hotword_msg);
|
|
|
system(all_param.data());
|
|
|
}
|
|
@@ -138,11 +146,22 @@ namespace snowboy_wakeup
|
|
|
|
|
|
}
|
|
|
|
|
|
+//click btn ISR function
|
|
|
+void btnISR()
|
|
|
+{
|
|
|
+ btn_click = 1;
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char** argv)
|
|
|
{
|
|
|
ros::init(argc, argv, "snowboy_wakeup_node");
|
|
|
snowboy_wakeup::HotwordDetectorNode ros_hotword_detector_node;
|
|
|
|
|
|
+ wiringPiSetup();
|
|
|
+ pinMode(BTN_PIN, INPUT);
|
|
|
+ pullUpDnControl(BTN_PIN, PUD_UP);
|
|
|
+ wiringPiISR(BTN_PIN, INT_EDGE_RISING, &btnISR);
|
|
|
+
|
|
|
if (ros_hotword_detector_node.initialize())
|
|
|
{
|
|
|
ros::spin();
|