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