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
|
popd
|
||||||
fi
|
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
|
mkdir -p model
|
||||||
pushd 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
|
for i in 1 2 3; do
|
||||||
read -p "ready? ctrl-c when done"
|
read -p "ready? ctrl-c when done"
|
||||||
rec \
|
rec \
|
||||||
|
|
@ -38,6 +40,7 @@ if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/hotword.pmdl ]; then
|
||||||
-it \
|
-it \
|
||||||
-v "$(realpath ./model)":/snowboy-master/examples/Python/model \
|
-v "$(realpath ./model)":/snowboy-master/examples/Python/model \
|
||||||
snowboy-pmdl:latest
|
snowboy-pmdl:latest
|
||||||
|
mv ./model/hotword.pmdl ./model/$HOTWORD.pmdl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if false; then
|
if false; then
|
||||||
|
|
@ -54,7 +57,7 @@ if false; then
|
||||||
import snowboydecoder
|
import snowboydecoder
|
||||||
import datetime
|
import datetime
|
||||||
detected_callback = lambda *args: print(datetime.datetime.now(), "GOTCHA")
|
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)
|
d.start(detected_callback)
|
||||||
' > breel.py
|
' > breel.py
|
||||||
echo GO
|
echo GO
|
||||||
|
|
@ -65,10 +68,10 @@ if false; then
|
||||||
python3 ./breel.py
|
python3 ./breel.py
|
||||||
else
|
else
|
||||||
resources="$(realpath snowboy.git.d/resources/common.res)"
|
resources="$(realpath snowboy.git.d/resources/common.res)"
|
||||||
hotword="$(realpath ./model/hotword.pmdl)"
|
hotword="$(realpath ./model/$HOTWORD.pmdl)"
|
||||||
GOPROXY= go build -o snowboy
|
GOPROXY= go build -o snowboy
|
||||||
if [ -z "$PUSH" ]; then
|
if [ -z "$PUSH" ]; then
|
||||||
./snowboy -model "$hotword" -resources "$resources" -sensitivity 0.5
|
./snowboy -m "$hotword" -r "$resources" -s 0.5 "$@"
|
||||||
else
|
else
|
||||||
echo '
|
echo '
|
||||||
FROM registry-app.eng.qops.net:5001/imported/alpine:3.16
|
FROM registry-app.eng.qops.net:5001/imported/alpine:3.16
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/brentnd/go-snowboy"
|
"github.com/brentnd/go-snowboy"
|
||||||
|
|
@ -74,9 +75,10 @@ func (s *Sound) Read(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
resources := flag.String("resources", "", "path to the .res file")
|
resources := flag.String("r", "", "path to the .res file")
|
||||||
model := flag.String("model", "", "path to the .?mdl file")
|
model := flag.String("m", "", "path to the .?mdl file")
|
||||||
sensitivity := flag.Float64("sensitivity", 0.75, "0..1")
|
sensitivity := flag.Float64("s", 0.45, "0..1")
|
||||||
|
quiet := flag.Bool("q", false, "emit '1' on detect else silent")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *resources == "" || *model == "" {
|
if *resources == "" || *model == "" {
|
||||||
|
|
@ -94,16 +96,22 @@ func main() {
|
||||||
|
|
||||||
// set the handlers
|
// set the handlers
|
||||||
d.HandleFunc(snowboy.NewHotword(*model, float32(*sensitivity)), func(string) {
|
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) {
|
d.HandleSilenceFunc(1*time.Second, func(string) {
|
||||||
fmt.Println("...")
|
if !*quiet {
|
||||||
|
log.Println("...")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// display the detector's expected audio format
|
// display the detector's expected audio format
|
||||||
sr, nc, bd := d.AudioFormat()
|
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
|
// start detecting using the microphone
|
||||||
d.ReadAndDetect(mic)
|
d.ReadAndDetect(mic)
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue