Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A server that starts and stops audio recording with websocket messages
package main
import (
"net/http"
"fmt"
"os/exec"
"time"
"code.google.com/p/go.net/websocket"
)
// Echo the data received on the WebSocket.
func EchoServer(ws *websocket.Conn) {
//io.Copy(ws, ws)
c := make(chan bool)
for {
var message string
websocket.Message.Receive(ws, &message)
if message == "Stop" {
c<-true
fmt.Println(message)
}
if message=="Start"{
fmt.Println(message)
go newrecording(c)
}
websocket.Message.Send(ws, "message")
}
}
// This example demonstrates a trivial echo server.
func ExampleHandler() {
http.Handle("/echo", websocket.Handler(EchoServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
func newrecording(c <-chan bool){
filename := fmt.Sprintf("recs/%d.wav",time.Now().Unix())
cmd := exec.Command("arecord","-f","cd","-t","wav",filename)
cmd.Start()
//fmt.Print(cmd.Process.Pid)
select{
case <- c:
cmd.Process.Kill()
}
}
func main(){
ExampleHandler()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.