remote-mic/main.go

71 lines
1.0 KiB
Go
Raw Normal View History

2020-04-28 21:42:45 +00:00
package main
import (
"fmt"
2020-04-29 12:33:39 +00:00
"os"
"io"
2020-04-28 21:42:45 +00:00
"time"
"remote-mic/socketops"
"remote-mic/pulsectl"
2020-04-29 12:33:39 +00:00
"remote-mic/audio"
2020-04-28 21:42:45 +00:00
)
2020-04-29 12:33:39 +00:00
func socketExample() {
2020-04-28 21:42:45 +00:00
fmt.Print("Listening for TCP connection on port 8080... ")
conn, err := socketops.AcceptConn(":8080")
if err != nil {
panic(err)
}
defer conn.Close()
fmt.Println("Connection accepted!")
data := make(chan []byte, 10)
go socketops.HandleConn(conn, data)
socketops.HandleData(data)
fmt.Println("Exiting.")
}
2020-04-29 12:33:39 +00:00
func pulsectlExample() {
2020-04-28 21:42:45 +00:00
pulsectl.LoadPipeSource(pulsectl.PipeSourceConfig{
"remote-mic",
"/dev/shm",
"s16le",
44100,
2,
})
time.Sleep(10 * time.Second)
pulsectl.UnloadPipeSource()
}
2020-04-29 12:33:39 +00:00
func micStreamExample() {
cmd := audio.StreamMic(audio.MicStreamConfig{
"avfoundation",
":0",
"s16le",
44100,
2,
})
pipe, _ := cmd.StdoutPipe()
cmd.Start()
for {
io.Copy(os.Stdout, pipe)
}
}
func getDeviceExample() {
device, err := audio.GetMicDevice()
if err != nil {
panic(err)
}
fmt.Println(device)
}
func main() {
getDeviceExample()
}