forked from Kitt-AI/snowboy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Kitt-AI#136 from brentnd/master
Add Go support
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"unsafe" | ||
"os" | ||
|
||
"github.com/Kitt-AI/snowboy/swig/Go" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
fmt.Printf("usage: %s <keyword.umdl> <wav file>\n", os.Args[0]) | ||
return | ||
} | ||
fmt.Printf("Snowboy detecting keyword in %s\n", os.Args[2]) | ||
detector := snowboydetect.NewSnowboyDetect("../../resources/common.res", os.Args[1]) | ||
detector.SetSensitivity("0.5") | ||
detector.SetAudioGain(1) | ||
defer snowboydetect.DeleteSnowboyDetect(detector) | ||
|
||
dat, err := ioutil.ReadFile(os.Args[2]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ptr := snowboydetect.SwigcptrInt16_t(unsafe.Pointer(&dat[0])) | ||
res := detector.RunDetection(ptr, len(dat) / 2 /* len of int16 */) | ||
if res == -2 { | ||
fmt.Println("Snowboy detected silence") | ||
} else if res == -1 { | ||
fmt.Println("Snowboy detection returned error") | ||
} else if res == 0 { | ||
fmt.Println("Snowboy detected nothing") | ||
} else { | ||
fmt.Println("Snowboy detected keyword ", res) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Dependencies | ||
|
||
### Swig | ||
http://www.swig.org/ | ||
|
||
### Go Package | ||
``` | ||
go get github.com/Kitt-AI/snowboy/swig/Go | ||
``` | ||
|
||
## Building | ||
|
||
``` | ||
go build -o snowboy main.go | ||
``` | ||
|
||
## Running | ||
|
||
``` | ||
./snowboy <keyword.umdl> <wav file> | ||
``` | ||
|
||
### Examples | ||
Cmd: | ||
`./snowboy ../../resources/snowboy.umdl ../../resources/snowboy.wav` | ||
|
||
Output: | ||
``` | ||
Snowboy detecting keyword in ../../resources/snowboy.wav | ||
Snowboy detected keyword 1 | ||
``` | ||
|
||
Cmd: | ||
`./snowboy ../../resources/alexa.umdl ../../resources/snowboy.wav` | ||
|
||
Output: | ||
``` | ||
Snowboy detecting keyword in ../../resources/snowboy.wav | ||
Snowboy detected nothing | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package snowboydetect | ||
|
||
/* | ||
#cgo CXXFLAGS: -std=c++11 | ||
#cgo linux,amd64 LDFLAGS: -lcblas -L${SRCDIR}/../../lib/ubuntu64 -lsnowboy-detect | ||
#cgo linux,arm LDFLAGS: -lcblas -L${SRCDIR}/../../lib/rpi -lsnowboy-detect | ||
#cgo darwin LDFLAGS: -lcblas -L${SRCDIR}/../../lib/osx -lsnowboy-detect | ||
*/ | ||
import "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// swig/Go/snowboydetect.swigcxx | ||
|
||
%module snowboydetect | ||
|
||
// Suppress SWIG warnings. | ||
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_CLASS | ||
%include "std_string.i" | ||
|
||
%{ | ||
#include "../../include/snowboy-detect.h" | ||
%} | ||
|
||
%include "../../include/snowboy-detect.h" |