diff --git a/snowboy-2022/build.sh b/snowboy-2022/build.sh index 5693ed3..5dd1a9d 100644 --- a/snowboy-2022/build.sh +++ b/snowboy-2022/build.sh @@ -17,10 +17,12 @@ if ! docker images | grep snowboy-pmdl.*latest &> /dev/null; then popd fi -if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/hotword.pmdl ]; then +export HOTWORD="${HOTWORD:-default_hotword}" + +if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/$HOTWORD.pmdl ]; then mkdir -p model pushd model - echo "record 3 instances of your hotword" >&2 + echo "record 3 instances of '$HOTWORD'" >&2 for i in 1 2 3; do read -p "ready? ctrl-c when done" rec \ @@ -38,6 +40,7 @@ if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/hotword.pmdl ]; then -it \ -v "$(realpath ./model)":/snowboy-master/examples/Python/model \ snowboy-pmdl:latest + mv ./model/hotword.pmdl ./model/$HOTWORD.pmdl fi if false; then @@ -54,7 +57,7 @@ if false; then import snowboydecoder import datetime detected_callback = lambda *args: print(datetime.datetime.now(), "GOTCHA") - d = snowboydecoder.HotwordDetector("../../../model/hotword.pmdl", sensitivity=0.5, audio_gain=1) + d = snowboydecoder.HotwordDetector("../../../model/'"$HOTWORD"'.pmdl", sensitivity=0.5, audio_gain=1) d.start(detected_callback) ' > breel.py echo GO @@ -65,10 +68,10 @@ if false; then python3 ./breel.py else resources="$(realpath snowboy.git.d/resources/common.res)" - hotword="$(realpath ./model/hotword.pmdl)" + hotword="$(realpath ./model/$HOTWORD.pmdl)" GOPROXY= go build -o snowboy if [ -z "$PUSH" ]; then - ./snowboy -model "$hotword" -resources "$resources" -sensitivity 0.5 + ./snowboy -m "$hotword" -r "$resources" -s 0.5 "$@" else echo ' FROM registry-app.eng.qops.net:5001/imported/alpine:3.16 diff --git a/snowboy-2022/main.go b/snowboy-2022/main.go index 41588a8..a309f32 100644 --- a/snowboy-2022/main.go +++ b/snowboy-2022/main.go @@ -11,6 +11,7 @@ import ( "encoding/binary" "flag" "fmt" + "log" "time" "github.com/brentnd/go-snowboy" @@ -74,9 +75,10 @@ func (s *Sound) Read(p []byte) (int, error) { } func main() { - resources := flag.String("resources", "", "path to the .res file") - model := flag.String("model", "", "path to the .?mdl file") - sensitivity := flag.Float64("sensitivity", 0.75, "0..1") + resources := flag.String("r", "", "path to the .res file") + model := flag.String("m", "", "path to the .?mdl file") + sensitivity := flag.Float64("s", 0.45, "0..1") + quiet := flag.Bool("q", false, "emit '1' on detect else silent") flag.Parse() if *resources == "" || *model == "" { @@ -94,16 +96,22 @@ func main() { // set the handlers d.HandleFunc(snowboy.NewHotword(*model, float32(*sensitivity)), func(string) { - fmt.Println(time.Now(), "GOTCHA!") + if !*quiet { + log.Println("GOTCHA!") + } else { + fmt.Printf("1") + } }) d.HandleSilenceFunc(1*time.Second, func(string) { - fmt.Println("...") + if !*quiet { + log.Println("...") + } }) // display the detector's expected audio format sr, nc, bd := d.AudioFormat() - fmt.Printf("sample rate=%d, num channels=%d, bit depth=%d\n", sr, nc, bd) + log.Printf("sample rate=%d, num channels=%d, bit depth=%d\n", sr, nc, bd) // start detecting using the microphone d.ReadAndDetect(mic) diff --git a/snowboy-2022/model/hotword.pmdl b/snowboy-2022/model/hotword.pmdl deleted file mode 100644 index 46618c0..0000000 Binary files a/snowboy-2022/model/hotword.pmdl and /dev/null differ diff --git a/snowboy-2022/model/up.pmdl b/snowboy-2022/model/up.pmdl new file mode 100644 index 0000000..51646cd Binary files /dev/null and b/snowboy-2022/model/up.pmdl differ