Snowman  0.1.0
snowboy-detect.h
1 #pragma once
2 #include <memory>
3 #include <string>
4 
5 namespace snowboy {
6  namespace testing {
7  class Inspector;
8  }
9  struct WaveHeader;
10  class PipelineDetect;
11  struct PipelineVad;
12  class PipelinePersonalEnroll;
13  class PipelineTemplateCut;
14  struct MatrixBase;
15 
22  class SnowboyDetect {
23  friend class testing::Inspector;
24 
25  public:
48  SnowboyDetect(const std::string& resource_filename,
49  const std::string& model_str);
50 
61  bool Reset();
62 
96  int RunDetection(const std::string& data, bool is_end = false);
97 
113  int RunDetection(const float* const data,
114  const int array_length, bool is_end = false);
115 
131  int RunDetection(const int16_t* const data,
132  const int array_length, bool is_end = false);
133 
149  int RunDetection(const int32_t* const data,
150  const int array_length, bool is_end = false);
151 
164  void SetSensitivity(const std::string& sensitivity_str);
165 
177  void SetHighSensitivity(const std::string& high_sensitivity_str);
178 
184  std::string GetSensitivity() const;
185 
194  void SetAudioGain(const float audio_gain);
195 
205  void UpdateModel() const;
206 
214  int NumHotwords() const;
215 
230  void ApplyFrontend(const bool apply_frontend);
231 
236  int SampleRate() const;
237 
242  int NumChannels() const;
243 
248  int BitsPerSample() const;
249 
251  ~SnowboyDetect();
252 
253  private:
254  std::unique_ptr<WaveHeader> wave_header_;
255  std::unique_ptr<PipelineDetect> detect_pipeline_;
256  };
257 
266  class SnowboyVad {
267  friend class testing::Inspector;
268 
269  public:
277  SnowboyVad(const std::string& resource_filename);
278 
287  bool Reset();
288 
311  int RunVad(const std::string& data, bool is_end = false);
312 
328  int RunVad(const float* const data,
329  const int array_length, bool is_end = false);
330 
346  int RunVad(const int16_t* const data,
347  const int array_length, bool is_end = false);
348 
364  int RunVad(const int32_t* const data,
365  const int array_length, bool is_end = false);
366 
375  void SetAudioGain(const float audio_gain);
376 
391  void ApplyFrontend(const bool apply_frontend);
392 
397  int SampleRate() const;
398 
403  int NumChannels() const;
404 
409  int BitsPerSample() const;
410 
412  ~SnowboyVad();
413 
414  private:
415  std::unique_ptr<WaveHeader> wave_header_;
416  std::unique_ptr<PipelineVad> vad_pipeline_;
417  };
418 
425  friend class testing::Inspector;
426 
427  public:
437  SnowboyPersonalEnroll(const std::string& resource_filename, const std::string& model_filename);
438 
458  int RunEnrollment(const std::string& data);
459 
474  int RunEnrollment(const float* const data, const int array_length);
475 
490  int RunEnrollment(const int16_t* const data, const int array_length);
491 
506  int RunEnrollment(const int32_t* const data, const int array_length);
507 
516  bool Reset();
517 
522  int GetNumTemplates() const;
523 
528  int SampleRate() const;
529 
534  int NumChannels() const;
535 
540  int BitsPerSample() const;
541 
544 
545  private:
550  int RunEnrollment(const MatrixBase& mat);
551  std::unique_ptr<WaveHeader> wave_header_;
552  std::unique_ptr<PipelinePersonalEnroll> enroll_pipeline_;
553  };
554 
562  friend class testing::Inspector;
563 
564  public:
572  SnowboyTemplateCut(const std::string& resource_filename);
573 
585  std::string CutTemplate(const std::string& data);
586 
604  int CutTemplate(const float* const data, const int array_length, float* const data_out, int* array_length_out);
605 
623  int CutTemplate(const int16_t* const data, const int array_length, int16_t* const data_out, int* array_length_out);
624 
642  int CutTemplate(const int32_t* const data, const int array_length, int32_t* const data_out, int* array_length_out);
643 
652  bool Reset();
653 
658  int SampleRate() const;
659 
664  int NumChannels() const;
665 
670  int BitsPerSample() const;
671 
674 
675  private:
676  std::unique_ptr<WaveHeader> wave_header_;
677  std::unique_ptr<PipelineTemplateCut> cut_pipeline_;
678  };
679 
680 } // namespace snowboy
Hotword detector class.
Definition: snowboy-detect.h:22
SnowboyDetect(const std::string &resource_filename, const std::string &model_str)
Default constructor.
Definition: snowboy-detect.cpp:13
std::string GetSensitivity() const
Returns the sensitivity string for the current hotwords.
Definition: snowboy-detect.cpp:101
void SetSensitivity(const std::string &sensitivity_str)
Sets the sensitivity string for the loaded hotwords.
Definition: snowboy-detect.cpp:93
void UpdateModel() const
Writes the models to the model filenames specified in <model_str> in the constructor.
Definition: snowboy-detect.cpp:109
int NumHotwords() const
Returns the number of the loaded hotwords.
Definition: snowboy-detect.cpp:113
void SetHighSensitivity(const std::string &high_sensitivity_str)
Sets the high sensitivity string for the loaded hotwords.
Definition: snowboy-detect.cpp:97
int BitsPerSample() const
Returns the expected number of bits for audio provided to RunDetection().
Definition: snowboy-detect.cpp:129
int SampleRate() const
Returns the expected sample rate for audio provided to RunDetection().
Definition: snowboy-detect.cpp:121
~SnowboyDetect()
Destructor.
Definition: snowboy-detect.cpp:27
void SetAudioGain(const float audio_gain)
Apply a fixed gain to the input audio.
Definition: snowboy-detect.cpp:105
int NumChannels() const
Returns the expected number of channels for audio provided to RunDetection().
Definition: snowboy-detect.cpp:125
bool Reset()
Resets the detection.
Definition: snowboy-detect.cpp:32
int RunDetection(const std::string &data, bool is_end=false)
Runs hotword detection.
Definition: snowboy-detect.cpp:37
void ApplyFrontend(const bool apply_frontend)
Enable or disable audio frontend (NS & AGC).
Definition: snowboy-detect.cpp:117
Enrollment class.
Definition: snowboy-detect.h:424
int NumChannels() const
Returns the expected number of channels for audio provided to RunDetection().
Definition: snowboy-detect.cpp:322
int SampleRate() const
Returns the expected sample rate for audio provided to RunDetection().
Definition: snowboy-detect.cpp:318
int RunEnrollment(const std::string &data)
Runs the hotword enrollment.
Definition: snowboy-detect.cpp:244
int GetNumTemplates() const
Returns the minimum number of recordings required for the new hotword.
Definition: snowboy-detect.cpp:314
int BitsPerSample() const
Returns the expected number of bits for audio provided to RunDetection().
Definition: snowboy-detect.cpp:326
SnowboyPersonalEnroll(const std::string &resource_filename, const std::string &model_filename)
Default constructor.
Definition: snowboy-detect.cpp:232
~SnowboyPersonalEnroll()
Destructor.
Definition: snowboy-detect.cpp:330
bool Reset()
Resets the enrollment.
Definition: snowboy-detect.cpp:309
Template cut class.
Definition: snowboy-detect.h:561
int BitsPerSample() const
Returns the expected number of bits for audio provided to RunDetection().
Definition: snowboy-detect.cpp:427
std::string CutTemplate(const std::string &data)
Cuts the provided sample.
Definition: snowboy-detect.cpp:345
int NumChannels() const
Returns the expected number of channels for audio provided to RunDetection().
Definition: snowboy-detect.cpp:423
SnowboyTemplateCut(const std::string &resource_filename)
Default constructor.
Definition: snowboy-detect.cpp:332
~SnowboyTemplateCut()
Destructor.
Definition: snowboy-detect.cpp:431
bool Reset()
Resets the enrollment.
Definition: snowboy-detect.cpp:414
int SampleRate() const
Returns the expected sample rate for audio provided to RunDetection().
Definition: snowboy-detect.cpp:419
Voice activity detector class.
Definition: snowboy-detect.h:266
int RunVad(const std::string &data, bool is_end=false)
Runs the VAD algorithm.
Definition: snowboy-detect.cpp:156
bool Reset()
Resets the vad.
Definition: snowboy-detect.cpp:151
int SampleRate() const
Returns the expected sample rate for audio provided to RunDetection().
Definition: snowboy-detect.cpp:220
int BitsPerSample() const
Returns the expected number of bits for audio provided to RunDetection().
Definition: snowboy-detect.cpp:228
void ApplyFrontend(const bool apply_frontend)
Enable or disable audio frontend (NS & AGC).
Definition: snowboy-detect.cpp:216
~SnowboyVad()
Destructor.
Definition: snowboy-detect.cpp:146
int NumChannels() const
Returns the expected number of channels for audio provided to RunDetection().
Definition: snowboy-detect.cpp:224
void SetAudioGain(const float audio_gain)
Apply a fixed gain to the input audio.
Definition: snowboy-detect.cpp:212
SnowboyVad(const std::string &resource_filename)
Default constructor.
Definition: snowboy-detect.cpp:133
Definition: matrix-wrapper.h:11