multi model, custom output support

master
Bel LaPointe 2022-11-14 10:19:12 -07:00
parent 0345cf00e6
commit 0027ce8fa9
1 changed files with 12 additions and 9 deletions

View File

@ -12,6 +12,8 @@ import (
"flag"
"fmt"
"log"
"path"
"strings"
"time"
"github.com/brentnd/go-snowboy"
@ -76,12 +78,12 @@ func (s *Sound) Read(p []byte) (int, error) {
func main() {
resources := flag.String("r", "", "path to the .res file")
model := flag.String("m", "", "path to the .?mdl file")
models := flag.String("ms", "", "comma delimited path to the .?mdl file/output")
sensitivity := flag.Float64("s", 0.45, "0..1")
quiet := flag.Bool("q", false, "emit '1' on detect else silent")
flag.Parse()
if *resources == "" || *model == "" {
if *resources == "" || *models == "" {
panic("all flags must be set")
}
@ -95,13 +97,14 @@ func main() {
defer d.Close()
// set the handlers
d.HandleFunc(snowboy.NewHotword(*model, float32(*sensitivity)), func(string) {
if !*quiet {
log.Println("GOTCHA!")
} else {
fmt.Printf("1")
}
})
for _, modelStr := range strings.Split(*models, ",") {
d.HandleFunc(snowboy.NewHotword(path.Dir(modelStr), float32(*sensitivity)), func(string) {
if !*quiet {
log.Println("GOTCHA!")
}
fmt.Println(path.Base(modelStr))
})
}
d.HandleSilenceFunc(1*time.Second, func(string) {
if !*quiet {