You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
700 B
Go

package cmd
import (
"bytes"
"os"
"os/exec"
"strings"
)
var rawPiperCmd = strings.Split("piper --model /home/toor/piper_models/en_US-ryan-medium.onnx --output-raw", " ")
var rawAplayCmd = strings.Split("aplay -r 22050 -f S16_LE -t raw -", " ")
func Say(msg []byte) error {
buf := new(bytes.Buffer)
buf.Write(msg)
r, w, err := os.Pipe()
if err != nil {
return err
}
defer r.Close()
piperCmd := exec.Command(rawPiperCmd[0], rawPiperCmd[1:]...)
piperCmd.Stdin = buf
piperCmd.Stdout = w
err = piperCmd.Start()
if err != nil {
return err
}
w.Close()
defer piperCmd.Wait()
aplayCmd := exec.Command(rawAplayCmd[0], rawAplayCmd[1:]...)
aplayCmd.Stdin = r
return aplayCmd.Run()
}