multi hotword support via HOTWORD=xyz bash build.sh
parent
e82ece9fd8
commit
0345cf00e6
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue