dcaというコマンドをGoプログラムを利用して実行したい
<
dcawavdcaGo
dca -i hello.wav --raw > hello.dca
package main
import (
"io"
"io/ioutil"
"os"
"os/exec"
)
func main() {
b, err := ioutil.ReadFile("hello.wav")
if err != nil {
panic(err)
}
cmd := exec.Command("dca", "--raw", "-i", "pipe:0")
stdin, _ := cmd.StdinPipe()
io.WriteString(stdin, string(b))
stdin.Close()
out, err := cmd.Output()
if err != nil {
panic(err)
}
f, err := os.Create("hello.dca")
if err != nil {
panic(err)
}
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()
if _, err := f.Write(out); err != nil {
panic(err)
}
}
xcX3v84RxoQ-4GxG32940ukFUIEgYdPy
09d4277205c787281310ff2d6ba27fde