-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using PortAudio with Snowboy with Golang #311
Comments
I haven't really played with the Go example. @brentnd could you please help? |
I literally just figured it out moments after I posted this! I was not copying the slice correctly. This is the code that works: package main
import (
"bytes"
"encoding/binary"
"fmt"
"time"
"github.com/brentnd/go-snowboy"
"github.com/gordonklaus/portaudio"
)
func chkErr(err error) error {
if err != nil {
fmt.Errorf("%s", err)
return err
}
return nil
}
type Sound struct {
stream *portaudio.Stream
data []int16
}
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() {
inputChannels := 1
outputChannels := 0
sampleRate := 16000
framesPerBuffer := make([]int16, 1024)
err := portaudio.Initialize()
chkErr(err)
defer portaudio.Terminate()
stream, err := portaudio.OpenDefaultStream(inputChannels, outputChannels, float64(sampleRate), len(framesPerBuffer), framesPerBuffer)
chkErr(err)
defer stream.Close()
d := snowboy.NewDetector("/home/ron/Development/snowboy/resources/common.res")
defer d.Close()
d.HandleFunc(snowboy.NewHotword("/home/ron/Development/snowboy/resources/snowboy.umdl", 0.5), func(string) {
fmt.Println("Handle func in snowboy.NewDefaultHotword")
})
d.HandleSilenceFunc(500*time.Millisecond, func(string) {
fmt.Println("silence detected")
})
sr, nc, bd := d.AudioFormat()
fmt.Printf("sample rate=%d, num channels=%d, bit depth=%d\n", sr, nc, bd)
err = stream.Start()
chkErr(err)
sounder := &Sound{stream, framesPerBuffer}
err = d.ReadAndDetect(sounder)
chkErr(err)
}
Thanks again for the cool lib. |
@deadprogram Ron thanks for figuring this out. Could you please submit a PR to |
Hi @xuchen I've done so, thanks again for this cool project! |
Hello, everyone. Thanks for working on this interesting lib.
I am trying to use Snowboy from the Golang wrappers https://github.com/brentnd/go-snowboy created by @brentnd that wraps the https://github.com/Kitt-AI/snowboy/tree/master/swig/Go package in this project, along with the PortAudio Golang wrapper https://github.com/gordonklaus/portaudio from @gordonklaus
I am able to grab data from the mic, and pump it into Snowboy, but it seems like must be in the wrong format or something?
This is my code:
I know I am getting data, here is my output:
Note that the buffer does contain some kind of data, but for whatever reason Snowboy is not recognizing it.
Anyone have any ideas on how to debug this? Seems like it would be a useful demo, I'd love to contribute. Thanks!
The text was updated successfully, but these errors were encountered: