AudioBufferProcessor: fix user/bot audio buffers silence padding
This commit is contained in:
@@ -72,6 +72,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed an issue in `AudioBufferProcessor` where user callback would not be
|
- Fixed an issue in `AudioBufferProcessor` where user callback would not be
|
||||||
called on task cancellation.
|
called on task cancellation.
|
||||||
|
|
||||||
|
- Fixed an issue in `AudioBufferProcessor` that would cause wrong silence
|
||||||
|
padding in some cases.
|
||||||
|
|
||||||
- Fixed an issue where `ElevenLabsTTSService` messages would return a 1009
|
- Fixed an issue where `ElevenLabsTTSService` messages would return a 1009
|
||||||
websocket error by increasing the max message size limit to 16MB.
|
websocket error by increasing the max message size limit to 16MB.
|
||||||
|
|
||||||
|
|||||||
@@ -79,14 +79,20 @@ class AudioBufferProcessor(FrameProcessor):
|
|||||||
if isinstance(frame, InputAudioRawFrame):
|
if isinstance(frame, InputAudioRawFrame):
|
||||||
resampled = self._resample_audio(frame)
|
resampled = self._resample_audio(frame)
|
||||||
self._user_audio_buffer.extend(resampled)
|
self._user_audio_buffer.extend(resampled)
|
||||||
# Sync the bot's buffer to the user's buffer by adding silence if needed
|
# Sync the bot's buffer to the user's buffer by adding silence if needed.
|
||||||
if len(self._user_audio_buffer) > len(self._bot_audio_buffer):
|
if len(self._user_audio_buffer) > len(self._bot_audio_buffer):
|
||||||
silence = b"\x00" * len(resampled)
|
missing = len(self._user_audio_buffer) - len(self._bot_audio_buffer)
|
||||||
|
silence = b"\x00" * missing
|
||||||
self._bot_audio_buffer.extend(silence)
|
self._bot_audio_buffer.extend(silence)
|
||||||
# If the bot is speaking, include all audio from the bot.
|
# If the bot is speaking, include all audio from the bot.
|
||||||
elif isinstance(frame, OutputAudioRawFrame):
|
elif isinstance(frame, OutputAudioRawFrame):
|
||||||
resampled = self._resample_audio(frame)
|
resampled = self._resample_audio(frame)
|
||||||
self._bot_audio_buffer.extend(resampled)
|
self._bot_audio_buffer.extend(resampled)
|
||||||
|
# Sync the user's buffer to the bot's buffer by adding silence if needed.
|
||||||
|
if len(self._bot_audio_buffer) > len(self._user_audio_buffer):
|
||||||
|
missing = len(self._bot_audio_buffer) - len(self._user_audio_buffer)
|
||||||
|
silence = b"\x00" * missing
|
||||||
|
self._user_audio_buffer.extend(silence)
|
||||||
|
|
||||||
if self._buffer_size > 0 and len(self._user_audio_buffer) > self._buffer_size:
|
if self._buffer_size > 0 and len(self._user_audio_buffer) > self._buffer_size:
|
||||||
await self._call_on_audio_data_handler()
|
await self._call_on_audio_data_handler()
|
||||||
|
|||||||
Reference in New Issue
Block a user