From d0afa23575133892c2562cd3cefae44f7ff434cc Mon Sep 17 00:00:00 2001 From: Sergey Evsegneev Date: Sun, 10 Jul 2022 13:57:14 +0300 Subject: [PATCH] Fix for Incorrect duration when sample rate is not 48kHz --- pyogg/opus_buffered_encoder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyogg/opus_buffered_encoder.py b/pyogg/opus_buffered_encoder.py index 7179051..1f22b72 100644 --- a/pyogg/opus_buffered_encoder.py +++ b/pyogg/opus_buffered_encoder.py @@ -107,12 +107,16 @@ def buffered_encode(self, ) pcm_ctypes = Buffer.from_buffer(pcm_bytes) + samples_multiplier = 48000 // self._samples_per_second # Either store the encoded packet to return at the end of the # method or immediately call the callback with the encoded # packet. def store_or_callback(encoded_packet: memoryview, samples: int, end_of_stream: bool = False) -> None: + # As far as the audio is decoded in 48kHz, the position in a stream should be stored + # according to this rate, not the original one + samples *= samples_multiplier if callback is None: # Store the result results.append((