diff --git a/README.md b/README.md deleted file mode 100644 index 4713123..0000000 --- a/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# stt - -## listen on linux - -https://wiki.archlinux.org/title/PulseAudio/Examples - -``` -10. ALSA monitor source - -To be able to record from a monitor source (a.k.a. "What-U-Hear", "Stereo Mix"), use pactl list to find out the name of the source in PulseAudio (e.g. alsa_output.pci-0000_00_1b.0.analog-stereo.monitor). Then add lines like the following to /etc/asound.conf or ~/.asoundrc: - -pcm.pulse_monitor { - type pulse - device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -} - -ctl.pulse_monitor { - type pulse - device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -} - -Now you can select pulse_monitor as a recording source. - -Alternatively, you can use pavucontrol to do this: make sure you have set up the display to "All input devices", then select "Monitor of [your sound card]" as the recording source. -``` - -```bash -$ pactl list | grep -A 50 RUNNING | grep -E 'RUNNING|Name:|Monitor Source:' | grep Monitor.Source | head -n 1 | awk '{print $NF}' -``` diff --git a/snowboy-2022/build.sh b/snowboy-2022/build.sh deleted file mode 100644 index d88ca59..0000000 --- a/snowboy-2022/build.sh +++ /dev/null @@ -1,99 +0,0 @@ -#! /bin/bash - -echo https://github.com/seasalt-ai/snowboy -cd "$(dirname "$(realpath "$BASH_SOURCE")")" - -set -e -set -o pipefail - -if [ ! -d ./snowboy.git.d ]; then - git clone https://github.com/seasalt-ai/snowboy snowboy.git.d -fi - -timeout 2 docker version &> /dev/null -if ! docker images | grep snowboy-pmdl.*latest &> /dev/null; then - pushd snowboy.git.d - docker build -t snowboy-pmdl:latest . - popd -fi - -export HOTWORD="${HOTWORD:-${TRAIN:-default_hotword}}" - -if [ -n "$TRAIN" ] || [ ! -d ./model ] || [ ! -f ./model/$HOTWORD.pmdl ]; then - mkdir -p model - pushd model - rm -f ./record{1,2,3}.wav || true - echo "record 3 instances of '$HOTWORD'" >&2 - for i in 1 2 3; do - read -p "[$i/3] ready? you get 3 seconds." - ( - timeout 3 rec \ - -r 16000 \ - -c 1 \ - -b 16 \ - -e signed-integer \ - -t wav \ - record$i.wav - ) || true - ls record$i.wav - done - popd - - docker run \ - --rm \ - -it \ - -v "$(realpath ./model)":/snowboy-master/examples/Python/model \ - snowboy-pmdl:latest - mv ./model/hotword.pmdl ./model/$HOTWORD.pmdl - if [ -n "$TRAIN" ]; then - exit 0 - fi -fi - -if false; then - if ! which swig; then - brew install swig - fi - pip3 install pyaudio - pushd snowboy.git.d/swig/Python3/ - make - popd - - cd snowboy.git.d/examples/Python3/ - echo ' - 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.start(detected_callback) - ' > breel.py - echo GO - cleanup() { - echo OK IM DONE NOW - } - trap cleanup EXIT - python3 ./breel.py -else - resources="$(realpath snowboy.git.d/resources/common.res)" - hotword="$(realpath ./model/$HOTWORD.pmdl)" - GOPROXY= go build -o snowboy - if [ -z "$PUSH" ]; then - ./snowboy \ - -ms "$hotword/$HOTWORD" \ - -r "$resources" \ - -s 0.5 \ - "$@" - else - echo ' -FROM registry-app.eng.qops.net:5001/imported/alpine:3.16 -WORKDIR /main/ -COPY ./snowboy.git.d/resources/common.res ./ -COPY ./model/hotword.pmdl ./ -COPY ./snowboy ./ -ENTRYPOINT ["sh", "-c", "true; echo copying /main/ to /mnt/; cp /main/* /mnt/"] -CMD [] - ' > Dockerfile - docker build -t registry-app.eng.qops.net:5001/breel/snowboy:latest . - docker push registry-app.eng.qops.net:5001/breel/snowboy:latest - fi -fi diff --git a/snowboy-2022/go.mod b/snowboy-2022/go.mod deleted file mode 100644 index dcb4c91..0000000 --- a/snowboy-2022/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module snowboy - -go 1.19 - -require ( - github.com/brentnd/go-snowboy v0.0.0-20190301212623-e19133c572af - github.com/gordonklaus/portaudio v0.0.0-20221027163845-7c3b689db3cc -) - -require ( - github.com/Kitt-AI/snowboy v1.3.0 // indirect - github.com/stretchr/testify v1.8.1 // indirect -) diff --git a/snowboy-2022/go.sum b/snowboy-2022/go.sum deleted file mode 100644 index 0fbc5b0..0000000 --- a/snowboy-2022/go.sum +++ /dev/null @@ -1,22 +0,0 @@ -github.com/Kitt-AI/snowboy v1.3.0 h1:PjBVN84M/9tAzDBQXILAKMoJMxt/fT0nhJ1rhKtVRUc= -github.com/Kitt-AI/snowboy v1.3.0/go.mod h1:sDzzMXFQ1wFkXkZaX/ant0xJsizGVq/9hyKb7ZB3cNI= -github.com/brentnd/go-snowboy v0.0.0-20190301212623-e19133c572af h1:ijY5OHNQs3CdzTN2XT+zByIsR1QVyXTvOUSkQcBm6pw= -github.com/brentnd/go-snowboy v0.0.0-20190301212623-e19133c572af/go.mod h1:XcT4k8Tn9hrM5SLVvu5hNQbAC6GojXM0MXz1Rt8CL68= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gordonklaus/portaudio v0.0.0-20221027163845-7c3b689db3cc h1:yYLpN7bJxKYILKnk20oczGQOQd2h3/7z7/cxdD9Se/I= -github.com/gordonklaus/portaudio v0.0.0-20221027163845-7c3b689db3cc/go.mod h1:WY8R6YKlI2ZI3UyzFk7P6yGSuS+hFwNtEzrexRyD7Es= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/snowboy-2022/main.go b/snowboy-2022/main.go deleted file mode 100644 index 69f42af..0000000 --- a/snowboy-2022/main.go +++ /dev/null @@ -1,122 +0,0 @@ -// This example streams the microphone thru Snowboy to listen for the hotword, -// by using the PortAudio interface. -// -// HOW TO USE: -// go run examples/Go/listen/main.go [path to snowboy resource file] [path to snowboy hotword file] -// -package main - -import ( - "bytes" - "encoding/binary" - "flag" - "fmt" - "log" - "path" - "strings" - "time" - - "github.com/brentnd/go-snowboy" - "github.com/gordonklaus/portaudio" -) - -// Sound represents a sound stream implementing the io.Reader interface -// that provides the microphone data. -type Sound struct { - stream *portaudio.Stream - data []int16 -} - -// Init initializes the Sound's PortAudio stream. -func (s *Sound) Init() { - inputChannels := 1 - outputChannels := 0 - sampleRate := 16000 - s.data = make([]int16, 1024) - - // initialize the audio recording interface - err := portaudio.Initialize() - if err != nil { - fmt.Errorf("Error initialize audio interface: %s", err) - return - } - - // open the sound input stream for the microphone - stream, err := portaudio.OpenDefaultStream(inputChannels, outputChannels, float64(sampleRate), len(s.data), s.data) - if err != nil { - fmt.Errorf("Error open default audio stream: %s", err) - return - } - - err = stream.Start() - if err != nil { - fmt.Errorf("Error on stream start: %s", err) - return - } - - s.stream = stream -} - -// Close closes down the Sound's PortAudio connection. -func (s *Sound) Close() { - s.stream.Close() - portaudio.Terminate() -} - -// Read is the Sound's implementation of the io.Reader interface. -func (s *Sound) Read(p []byte) (int, error) { - s.stream.Read() - - buf := &bytes.Buffer{} - for _, v := range s.data { - binary.Write(buf, binary.LittleEndian, v) - } - - copy(p, buf.Bytes()) - return len(p), nil -} - -func main() { - resources := flag.String("r", "", "path to the .res 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 == "" || *models == "" { - panic("all flags must be set") - } - - // open the mic - mic := &Sound{} - mic.Init() - defer mic.Close() - - // open the snowboy detector - d := snowboy.NewDetector(*resources) - defer d.Close() - - // set the handlers - for _, modelStrC := range strings.Split(*models, ",") { - modelStr := modelStrC - d.HandleFunc(snowboy.NewHotword(path.Dir(modelStr), float32(*sensitivity)), func(string) { - if !*quiet { - log.Println(path.Base(modelStr)) - } - fmt.Println(path.Base(modelStr)) - }) - } - - d.HandleSilenceFunc(1*time.Second, func(string) { - if !*quiet { - log.Println("...") - } - }) - - // display the detector's expected audio format - sr, nc, bd := d.AudioFormat() - 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.pmdl b/snowboy-2022/model.pmdl deleted file mode 100644 index 598624f..0000000 Binary files a/snowboy-2022/model.pmdl and /dev/null differ diff --git a/snowboy-2022/model/default_hotword.pmdl b/snowboy-2022/model/default_hotword.pmdl deleted file mode 100644 index e9a9a94..0000000 Binary files a/snowboy-2022/model/default_hotword.pmdl and /dev/null differ diff --git a/snowboy-2022/model/down.pmdl b/snowboy-2022/model/down.pmdl deleted file mode 100644 index c7c69fa..0000000 Binary files a/snowboy-2022/model/down.pmdl and /dev/null differ diff --git a/snowboy-2022/model/jump.pmdl b/snowboy-2022/model/jump.pmdl deleted file mode 100644 index c46aa87..0000000 Binary files a/snowboy-2022/model/jump.pmdl and /dev/null differ diff --git a/snowboy-2022/model/left.pmdl b/snowboy-2022/model/left.pmdl deleted file mode 100644 index 875f8d4..0000000 Binary files a/snowboy-2022/model/left.pmdl and /dev/null differ diff --git a/snowboy-2022/model/right.pmdl b/snowboy-2022/model/right.pmdl deleted file mode 100644 index bb4530c..0000000 Binary files a/snowboy-2022/model/right.pmdl and /dev/null differ diff --git a/snowboy-2022/model/up.pmdl b/snowboy-2022/model/up.pmdl deleted file mode 100644 index 78cb0ab..0000000 Binary files a/snowboy-2022/model/up.pmdl and /dev/null differ diff --git a/snowboy-2022/pyautogui.sh b/snowboy-2022/pyautogui.sh deleted file mode 100644 index e736cb2..0000000 --- a/snowboy-2022/pyautogui.sh +++ /dev/null @@ -1,82 +0,0 @@ -#! /bin/bash - -main() { - cleanup() { - killall -9 $(jobs -p) - killall snowboy - } - trap cleanup EXIT - - if [ ! -e /tmp/stt.fifo ]; then - mkfifo /tmp/stt.fifo - fi - - echo starting in - for ((i=2; i>0; i--)); do - echo "...$i..." - sleep 1 - done - - local models=($( - cat pyautogui.yaml \ - | gojq -r -c --yaml-input ' - to_entries[] | "model/"+.key+".pmdl/"+.key - ' \ - | tr '\n' ',' \ - | sed 's/,$//' - )) - echo models=$models - - ./snowboy -r resources.res -ms $models "$@" > /tmp/stt.fifo & - - python3 -c ' -import pyautogui -import time - -keys = set() - -def toggle(key): - global keys - if key in keys: - release(key) - else: - hold(key) - -def hold(key): - global keys - for keyin in [todrop for todrop in keys]: - if keyin != key: - release(keyin) - keys = set() - keys.add(key) - print() - print("pressing", key) - print() - pyautogui.keyDown(key) - -def release(key): - print() - print("releasing", key) - print() - pyautogui.keyUp(key) - -def main(): - with open("/tmp/stt.fifo", "r") as q: - for line in q: - handle(line.strip()) - -import yaml -mapping = yaml.safe_load(open("./pyautogui.yaml", "r")) -print(mapping) - -def handle(cmd): - global mapping - hold(mapping.get(cmd)) - -main() - ' -} - -if [ "$0" == "$BASH_SOURCE" ]; then - main "$@" -fi diff --git a/snowboy-2022/pyautogui.yaml b/snowboy-2022/pyautogui.yaml deleted file mode 100644 index 7bd2bac..0000000 --- a/snowboy-2022/pyautogui.yaml +++ /dev/null @@ -1,5 +0,0 @@ -up: w -down: s -left: a -right: d -jump: w diff --git a/snowboy-2022/resources.res b/snowboy-2022/resources.res deleted file mode 100644 index fe6fa95..0000000 Binary files a/snowboy-2022/resources.res and /dev/null differ