fix: add minimum Opus bitrate floor in encoder

Add a defensive floor of 8000 bps in the Encode method, preventing the
encoder from being configured with an invalidly low bitrate even if
AudioDataBytes is somehow set to a very small value.
This commit is contained in:
Brandon McGinty (deepseek)
2026-08-08 19:18:35 -04:00
committed by Brandon McGinty
parent 64a3ea6c32
commit 181b325c2d
+3
View File
@@ -68,6 +68,9 @@ func (e *Encoder) Encode(pcm []int16, _, maxDataBytes int) ([]byte, error) {
// Opus encodes best when the bitrate target is set properly rather than
// relying on truncation, which can produce incomplete or corrupt frames.
bitrate := maxDataBytes * 8 * 100
if bitrate < 8000 {
bitrate = 8000 // Opus minimum viable bitrate for voice
}
_ = e.Encoder.SetBitrate(bitrate)
buf := make([]byte, maxDataBytes)