58 lines
893 B
Go
58 lines
893 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"io"
|
|
"time"
|
|
"remote-mic/socketops"
|
|
"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 := audio.NewPulsectl()
|
|
err := pulsectl.LoadPipeSourceModule()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
time.Sleep(10 * time.Second)
|
|
pulsectl.UnloadPipeSourceModule()
|
|
}
|
|
|
|
func micStreamExample() {
|
|
mic, err := audio.NewMicrophone()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = mic.Start()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer mic.Stop()
|
|
|
|
for {
|
|
io.Copy(os.Stdout, mic.AudioStream())
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
pulsectlExample()
|
|
}
|