remote-mic/main.go

58 lines
894 B
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"
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-29 18:48:55 +00:00
pulsectl := audio.NewPulsectl()
err := pulsectl.LoadPipeSourceModule()
if err != nil {
panic(err)
}
2020-04-28 21:42:45 +00:00
time.Sleep(10 * time.Second)
2020-04-29 18:48:55 +00:00
pulsectl.UnloadPipeSourceModule()
2020-04-28 21:42:45 +00:00
}
2020-04-29 12:33:39 +00:00
func micStreamExample() {
2020-04-29 18:48:55 +00:00
mic, err := audio.NewMicrophone()
if err != nil {
panic(err)
2020-04-29 12:33:39 +00:00
}
2020-04-29 18:48:55 +00:00
err = mic.Start()
2020-04-29 12:33:39 +00:00
if err != nil {
panic(err)
}
2020-04-29 18:48:55 +00:00
defer mic.Stop()
for {
io.Copy(os.Stdout, mic.AudioStream())
}
2020-04-29 12:33:39 +00:00
}
func main() {
2020-04-29 19:12:33 +00:00
micStreamExample()
2020-04-29 12:33:39 +00:00
}