From df10c1312c7afa94720f07f7a98a074e4c057b30 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Thu, 23 Jan 2020 09:44:04 -0800 Subject: [PATCH] Do not initialize speaker when streaming to fd --- audio.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/audio.go b/audio.go index e5ab19a..8278e00 100644 --- a/audio.go +++ b/audio.go @@ -111,14 +111,16 @@ func play(audioFile *audioFile) { } } - if audioFile.Format.SampleRate != playingSampleRate { - err := speaker.Init(audioFile.Format.SampleRate, audioFile.Format.SampleRate.N(bufferSize)) - if err != nil { - log.Fatalf("failed to initialize audio device: %s", err) + if streamFdInt == -1 { + if audioFile.Format.SampleRate != playingSampleRate { + err := speaker.Init(audioFile.Format.SampleRate, audioFile.Format.SampleRate.N(bufferSize)) + if err != nil { + log.Fatalf("failed to initialize audio device: %s", err) + } + playingSampleRate = audioFile.Format.SampleRate + } else { + speaker.Clear() } - playingSampleRate = audioFile.Format.SampleRate - } else { - speaker.Clear() } streamer := beep.Seq(audioFile.Streamer, beep.Callback(func() {