69 lines
1.0 KiB
Go
69 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"remote-mic/audio"
|
|
"remote-mic/connection"
|
|
"time"
|
|
)
|
|
|
|
|
|
func socketExample() {
|
|
fmt.Print("Listening for connection on port 8080... ")
|
|
conn, err := connection.NewListen(":8080")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer conn.Close()
|
|
fmt.Println("Connection accepted!")
|
|
|
|
recvChan := conn.RecvChan()
|
|
go func() {
|
|
time.Sleep(10 * time.Second)
|
|
conn.Close()
|
|
}()
|
|
for {
|
|
buf, open := <-recvChan
|
|
if !open {
|
|
break
|
|
}
|
|
fmt.Printf("Bytes read: %d\n", len(buf))
|
|
fmt.Printf("Buf: %v\n", buf)
|
|
fmt.Printf("%v\n", string(buf))
|
|
}
|
|
|
|
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() {
|
|
socketExample()
|
|
}
|