initial commit

This commit is contained in:
root
2024-10-30 13:23:52 +01:00
commit 68ba48a3a2
29 changed files with 1977 additions and 0 deletions

33
http/hw/stream/audio.go Normal file
View File

@@ -0,0 +1,33 @@
package stream
import (
"github.com/gin-gonic/gin"
"io"
"net/http"
"os/exec"
)
func AudioHandler(c *gin.Context) {
cmd := exec.Command("ffmpeg",
"-f", "alsa",
"-i", "hw:0,0",
"-acodec", "aac",
"-f", "mp4", "-")
// ffmpeg -f alsa -i hw:0,0 -acodec aac -f mp4 -
stdout, err := cmd.StdoutPipe()
if err != nil {
c.String(http.StatusInternalServerError, "Failed to capture audio: %v", err)
return
}
if err := cmd.Start(); err != nil {
c.String(http.StatusInternalServerError, "Failed to start ffmpeg: %v", err)
return
}
defer cmd.Wait()
c.Header("Content-Type", "audio/mp4")
if _, err := io.Copy(c.Writer, stdout); err != nil {
c.String(http.StatusInternalServerError, "Failed to stream audio: %v", err)
return
}
}