diff --git a/.gitignore b/.gitignore index a050624f..dee4fbc5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ Snowboy.pm /examples/C++/portaudio /examples/C++/demo /examples/C++/demo2 +/examples/C++/demo3 /examples/Java/Demo.class /examples/Perl/data/ /examples/iOS/Obj-C/Pods/Pods.xcodeproj/xcuserdata/ diff --git a/examples/C++/Makefile b/examples/C++/Makefile index c8904032..00666def 100644 --- a/examples/C++/Makefile +++ b/examples/C++/Makefile @@ -1,6 +1,6 @@ include demo.mk -BINFILES = demo demo2 +BINFILES = demo demo2 demo3 all: $(BINFILES) diff --git a/examples/C++/demo3.cc b/examples/C++/demo3.cc new file mode 100644 index 00000000..5ba5aab2 --- /dev/null +++ b/examples/C++/demo3.cc @@ -0,0 +1,39 @@ +#include "include/snowboy-detect.h" +#include +#include + +using namespace std; + +#define BUFFER_SIZE 2000 + +/** + * run like this: + * rec -q -r 16000 -c 1 -b 16 -e signed-integer -t wav - | ./demo3 + */ +int main(int argc, char* argv[]) { + snowboy::SnowboyDetect detector("resources/common.res", "resources/models/snowboy.umdl"); + detector.SetSensitivity("0.5"); + detector.SetAudioGain(1.0); + detector.ApplyFrontend(false); + + short data_buffer[BUFFER_SIZE]; + + int mode = 0; + while (1) { + cin.read((char*)&data_buffer[0], BUFFER_SIZE*2); + + int newMode = detector.RunDetection(&data_buffer[0], BUFFER_SIZE); + if (newMode != mode) { + string str; + switch (newMode) { + case -2: str = "silence"; break; + case -1: str = "error"; break; + case 0: str = "noise"; break; + default: str = "hotword"; break; + } + + mode = newMode; + cout << str << endl; + } + } +}