Skip to content

Commit

Permalink
Merge pull request seasalt-ai#6 from dschnabel/patch-1
Browse files Browse the repository at this point in the history
C++ demo for use with SoX
  • Loading branch information
chenguoguo authored May 3, 2021
2 parents 01cb94e + 50683c2 commit f99cfc5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion examples/C++/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include demo.mk

BINFILES = demo demo2
BINFILES = demo demo2 demo3

all: $(BINFILES)

Expand Down
39 changes: 39 additions & 0 deletions examples/C++/demo3.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "include/snowboy-detect.h"
#include <iostream>
#include <string.h>

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;
}
}
}

0 comments on commit f99cfc5

Please sign in to comment.