From 34384881bcca7850691caac54ef9509c01a3e846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 22 May 2024 16:30:43 -0700 Subject: [PATCH] transport(base): clear audio output buffer if interrupted --- CHANGELOG.md | 2 ++ src/pipecat/processors/utils/audio.py | 25 ------------------------- src/pipecat/transports/base_output.py | 3 +-- 3 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 src/pipecat/processors/utils/audio.py diff --git a/CHANGELOG.md b/CHANGELOG.md index daf55d3ee..bae0c5361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Clear the audio output buffer if we are interrupted. + - Re-add exponential smoothing after volume calculation. This makes sure the volume value being used doesn't fluctuate so much. diff --git a/src/pipecat/processors/utils/audio.py b/src/pipecat/processors/utils/audio.py deleted file mode 100644 index cb7c17052..000000000 --- a/src/pipecat/processors/utils/audio.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright (c) 2024, Daily -# -# SPDX-License-Identifier: BSD 2-Clause License -# - -from typing import List - -from pipecat.frames.frames import AudioRawFrame - - -def maybe_split_audio_frame(frame: AudioRawFrame, largest_write_size: int) -> List[AudioRawFrame]: - """Subdivide large audio frames to enable interruption.""" - frames: List[AudioRawFrame] = [] - if len(frame.audio) > largest_write_size: - for i in range(0, len(frame.audio), largest_write_size): - chunk = frame.audio[i: i + largest_write_size] - frames.append( - AudioRawFrame( - audio=chunk, - sample_rate=frame.sample_rate, - num_channels=frame.num_channels)) - else: - frames.append(frame) - return frames diff --git a/src/pipecat/transports/base_output.py b/src/pipecat/transports/base_output.py index 377dcbab8..6106eaefa 100644 --- a/src/pipecat/transports/base_output.py +++ b/src/pipecat/transports/base_output.py @@ -175,8 +175,7 @@ def _sink_thread_handler(self): self._internal_push_frame(frame), self.get_event_loop()) future.result() else: - # Send any remaining audio - self._send_audio_truncated(buffer, bytes_size_10ms) + # If we get interrupted just clear the output buffer. buffer = bytearray() if isinstance(frame, EndFrame):