71 lines
1.0 KiB
Go
71 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"io"
|
|
"time"
|
|
"remote-mic/socketops"
|
|
"remote-mic/pulsectl"
|
|
"remote-mic/audio"
|
|
)
|
|
|
|
|
|
func socketExample() {
|
|
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.")
|
|
}
|
|
|
|
func pulsectlExample() {
|
|
pulsectl.LoadPipeSource(pulsectl.PipeSourceConfig{
|
|
"remote-mic",
|
|
"/dev/shm",
|
|
"s16le",
|
|
44100,
|
|
2,
|
|
})
|
|
time.Sleep(10 * time.Second)
|
|
pulsectl.UnloadPipeSource()
|
|
}
|
|
|
|
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()
|
|
}
|