return byte(n)
}
-func makeCmd(cmd string) *exec.Cmd {
- args := strings.Fields(cmd)
- if len(args) == 1 {
- return exec.Command(args[0])
- }
- return exec.Command(args[0], args[1:]...)
-}
-
func incr(data []byte) {
for i := len(data) - 1; i >= 0; i-- {
data[i]++
panic("overflow")
}
-const soxParams = "--no-show-progress --buffer 1920 --channels 1 --endian little --encoding signed --rate 48000 --bits 16 --type raw -"
-
func main() {
srvAddr := flag.String("srv", "vors.home.arpa:"+strconv.Itoa(vors.DefaultPort),
"host:TCP/UDP port to connect to")
srvPubB64 := flag.String("pub", "", "server's public key, Base64")
- recCmd := flag.String("rec", "rec "+soxParams, "rec command")
- playCmd := flag.String("play", "play "+soxParams, "play command")
+ recCmd := flag.String("rec", "rec "+vors.SoxParams, "rec command")
+ playCmd := flag.String("play", "play "+vors.SoxParams, "play command")
vadRaw := flag.Uint("vad", 0, "VAD threshold")
passwd := flag.String("passwd", "", "protected room's password")
muteToggle := flag.String("mute-toggle", "", "path to FIFO to toggle mute")
opusEnc := newOpusEnc()
var mic io.ReadCloser
if *recCmd != "" {
- cmd := makeCmd(*recCmd)
+ cmd := vors.MakeCmd(*recCmd)
mic, err = cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
playerTx := make(chan []byte, 5)
var cmd *exec.Cmd
if *playCmd != "" {
- cmd = makeCmd(*playCmd)
+ cmd = vors.MakeCmd(*playCmd)
player, err = cmd.StdinPipe()
if err != nil {
log.Fatal(err)
"flag"
"fmt"
"io"
+ "log"
"os"
"strconv"
vors "go.stargrave.org/vors/internal"
)
+func usage() {
+ fmt.Fprintf(os.Stderr, "Usage: vors-vad [-rec ...] THRESHOLD\n")
+ flag.PrintDefaults()
+}
+
func main() {
+ recCmd := flag.String("rec", "rec "+vors.SoxParams, "rec command")
+ flag.Usage = usage
flag.Parse()
+ log.SetFlags(log.Lmicroseconds | log.Lshortfile)
if len(flag.Args()) != 1 {
- fmt.Fprintf(os.Stderr, "Usage: rec | vors-vad THRES\n")
+ usage()
os.Exit(1)
}
thres, err := strconv.ParseUint(flag.Arg(0), 10, 64)
if err != nil {
- panic(err)
+ log.Fatal(err)
}
buf := make([]byte, 2*vors.FrameLen)
pcm := make([]int16, vors.FrameLen)
+ cmd := vors.MakeCmd(*recCmd)
+ mic, err := cmd.StdoutPipe()
+ if err != nil {
+ log.Fatal(err)
+ }
+ err = cmd.Start()
+ if err != nil {
+ log.Fatal(err)
+ }
var rms uint64
var i int
for {
- _, err = io.ReadFull(os.Stdin, buf)
+ _, err = io.ReadFull(mic, buf)
if err != nil {
panic(err)
}
}
rms = vors.RMS(pcm)
if rms > thres {
- println(rms)
+ fmt.Println(rms)
}
}
}
@unnumbered VAD
Voice Activity Detection is off by default. You can use the
-@command{vors-vad THRES} command with feeding audio record in its stdin.
-It will print calculated sound RMS value if it exceeds the
+@command{vors-vad [-rec ...] THRES} command with feeding audio record in
+its stdin. It will print calculated sound RMS value if it exceeds the
@option{THRES} threshold. So you can manually try various @option{THRES}
values to see when it is comfortable to detect your voice. Pass the
-desired @option{THRES} value to @option{-vad} option of
-@command{vors-client}.
+desired @option{THRES} value to @option{-vad} option of @command{vors-client}.
@example
-$ rec [...] | vors-vad 100
+$ vors-vad 100
[talk and see if threshold is low/high enough]
[it is too sensible, let's try higher one]
-$ rec [...] | vors-vad 200
+$ vors-vad 200
[perfect!]
$ vors-client -vad 200 [...]
Bitrate = 24000
FrameLen = FrameMs * Rate / 1000
MaxLost = 32
+
+ SoxParams = "--no-show-progress --buffer 1920 --channels 1 --endian little --encoding signed --rate 48000 --bits 16 --type raw -"
)
--- /dev/null
+package internal
+
+import (
+ "os/exec"
+ "strings"
+)
+
+func MakeCmd(cmd string) *exec.Cmd {
+ args := strings.Fields(cmd)
+ if len(args) == 1 {
+ return exec.Command(args[0])
+ }
+ return exec.Command(args[0], args[1:]...)
+}