diff options
-rw-r--r-- | soundbox/pipewire.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/soundbox/pipewire.go b/soundbox/pipewire.go index fbae73b..fcb5968 100644 --- a/soundbox/pipewire.go +++ b/soundbox/pipewire.go @@ -18,6 +18,20 @@ import ( var pipewireAudio = make(chan []byte, 5) +func s16leDropSilence(input []byte) []byte { + output := make([]byte, 0) + + for i := 0; i < (len(input)-1); i+=2 { + if input[i] == byte(0) && input[i+1] == byte(0) { + continue + } + output = append(output, input[i]) + output = append(output, input[i+1]) + } + + return output +} + func StreamPipewireContext(ctx context.Context, targets []net.HardwareAddr) error { cmd := exec.CommandContext( ctx, @@ -51,7 +65,7 @@ func StreamPipewireContext(ctx context.Context, targets []net.HardwareAddr) erro go func() { for buffer := range pipewireAudio { - tempReader := bytes.NewReader(buffer) + tempReader := bytes.NewReader(s16leDropSilence(buffer)) _, err := io.Copy(stdin, tempReader) if err != nil { log.Println("Failed to copy from PipeWire to ffmpeg.") |