snowboy_ros
hotword_detector.cpp
Go to the documentation of this file.
1 #define _GLIBCXX_USE_CXX11_ABI 0
2 
4 
5 #include <sstream>
6 
7 namespace snowboy_ros
8 {
9 
11 {
12 }
13 
14 void HotwordDetector::initialize(const char* resource_filename, const char* model_filename)
15 {
16  // Delete detector if we already had one
17  if (detector_)
18  {
19  delete detector_;
20  }
21 
22  // We need to use cpp98 therefore we cannot pass std::strings
23  std::string resource_filename_cpp98(resource_filename);
24  std::string model_filename_cpp98(model_filename);
25 
26  detector_ = new snowboy::SnowboyDetect(resource_filename_cpp98, model_filename_cpp98);
27 }
28 
29 bool HotwordDetector::configure(double sensitivity, double audio_gain)
30 {
31  // Return false if detector not initialized
32  if (!detector_)
33  {
34  return false;
35  }
36 
37  std::stringstream sensitivity_ss; sensitivity_ss << sensitivity;
38 
39  detector_->SetAudioGain(audio_gain);
40  detector_->SetSensitivity(sensitivity_ss.str());
41 
42  return true;
43 }
44 
46 {
47  if (detector_)
48  {
49  delete detector_;
50  }
51 }
52 
53 int HotwordDetector::runDetection(const int16_t* const data, const int array_length)
54 {
55  if (!detector_)
56  {
57  return -3;
58  }
59  return detector_->RunDetection(data, array_length);
60 }
61 
62 }
63 
sstream
std::string
snowboy::SnowboyDetect::SetAudioGain
void SetAudioGain(const float audio_gain)
snowboy_ros::HotwordDetector::configure
bool configure(double sensitivity, double audio_gain)
configure Configure the detector on runtime
Definition: hotword_detector.cpp:29
snowboy_ros::HotwordDetector::initialize
void initialize(const char *resource_filename, const char *model_filename)
initialize Initializes the Snowbody
Definition: hotword_detector.cpp:14
std::stringstream
snowboy_ros
Definition: hotword_detector.h:6
snowboy::SnowboyDetect::RunDetection
int RunDetection(const std::string &data)
training_service.data
dictionary data
END OF MODIFY ##################.
Definition: training_service.py:31
hotword_detector.h
demo2.sensitivity
list sensitivity
Definition: demo2.py:29
snowboy::SnowboyDetect::SetSensitivity
void SetSensitivity(const std::string &sensitivity_str)
snowboy_ros::HotwordDetector::~HotwordDetector
~HotwordDetector()
Definition: hotword_detector.cpp:45
snowboy_ros::HotwordDetector::detector_
snowboy::SnowboyDetect * detector_
detector_ Instance of Snowboy detect
Definition: hotword_detector.h:48
snowboy::SnowboyDetect
Definition: snowboy-detect.h:22
std::stringstream::str
T str(T... args)
snowboy_ros::HotwordDetector::runDetection
int runDetection(const int16_t *const data, const int array_length)
runDetection Runs hotword detection of Snowboy, see Snowboy API for more docs
Definition: hotword_detector.cpp:53
snowboy_ros::HotwordDetector::HotwordDetector
HotwordDetector()
Definition: hotword_detector.cpp:10