3 #include <ros/node_handle.h>
5 #include <audio_common_msgs/AudioData.h>
6 #include <std_msgs/String.h>
8 #include <dynamic_reconfigure/server.h>
9 #include <snowboy_ros/SnowboyReconfigureConfig.h>
11 #include <boost/filesystem.hpp>
31 hotword_pub_ =
nh_.advertise<std_msgs::String>(
"hotword_detection", 10);
34 if (!
nh_p_.getParam(
"resource_filename", resource_filename))
36 ROS_ERROR(
"Mandatory parameter 'resource_filename' not present on the parameter server");
40 if ( !boost::filesystem::exists( resource_filename ) )
42 ROS_ERROR(
"Resource '%s' does not exist", resource_filename.c_str());
46 std::string resource_extension = boost::filesystem::extension(resource_filename);
47 if ( resource_extension !=
".res" )
49 ROS_ERROR(
"'%s' not a valid Snowboy resource extension ('.res').", resource_filename.c_str());
54 if (!
nh_p_.getParam(
"model_filename", model_filename))
56 ROS_ERROR(
"Mandatory parameter 'model_filename' not present on the parameter server");
60 if ( !boost::filesystem::exists( model_filename ) )
62 ROS_ERROR(
"Model '%s' does not exist", model_filename.
c_str());
66 std::string model_extension = boost::filesystem::extension(model_filename);
67 if ( model_extension !=
".pmdl" && model_extension !=
".umdl" )
69 ROS_ERROR(
"Model '%s', not a valid Snowboy model extension ('.pmdl', '.umdl').", resource_filename.c_str());
126 ROS_INFO(
"SnowboyROS (Re)Configured");
135 if (msg->data.size() != 0)
142 if ( msg->data.size() % 2 )
144 ROS_ERROR(
"Not an even number of bytes in this message!");
147 int16_t sample_array[msg->data.size()/2];
148 for (
size_t i = 0; i < msg->data.size(); i+=2 )
150 sample_array[i/2] = ((int16_t) (msg->data[i+1]) << 8) + (int16_t) (msg->data[i]);
156 ROS_DEBUG(
"Hotword detected!");
158 std_msgs::String hotword_msg;
162 else if (result == -3)
164 ROS_ERROR(
"Hotword detector not initialized");
166 else if (result == -1)
168 ROS_ERROR(
"Snowboy error");
176 int main(
int argc,
char** argv)
178 ros::init(argc, argv,
"snowboy_node");
188 ROS_ERROR(
"Failed to initialize snowboy_node");