initial commit
This commit is contained in:
33
http/hw/stream/audio.go
Normal file
33
http/hw/stream/audio.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user