From 522d9319506e2ab5e5b88fcfd875c5286d4a1ba3 Mon Sep 17 00:00:00 2001 From: Adrian Cowham Date: Fri, 11 Oct 2024 10:33:12 -0700 Subject: [PATCH] better interruption handling by moving the processors after the transport output --- examples/canonical-metrics/bot.py | 2 +- examples/chatbot-audio-recording/bot.py | 2 +- .../processors/audio/audio_buffer_processor.py | 12 +----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/examples/canonical-metrics/bot.py b/examples/canonical-metrics/bot.py index 626af5f62..5b46b50fc 100644 --- a/examples/canonical-metrics/bot.py +++ b/examples/canonical-metrics/bot.py @@ -119,9 +119,9 @@ async def main(): user_response, llm, tts, + transport.output(), audio_buffer_processor, # captures audio into a buffer canonical, # uploads audio buffer to Canonical AI for metrics - transport.output(), assistant_response, ]) diff --git a/examples/chatbot-audio-recording/bot.py b/examples/chatbot-audio-recording/bot.py index b1955ddba..2d572fb90 100644 --- a/examples/chatbot-audio-recording/bot.py +++ b/examples/chatbot-audio-recording/bot.py @@ -103,8 +103,8 @@ async def main(): user_response, llm, tts, - audiobuffer, # used to buffer the audio in the pipeline transport.output(), + audiobuffer, # used to buffer the audio in the pipeline assistant_response, ]) diff --git a/src/pipecat/processors/audio/audio_buffer_processor.py b/src/pipecat/processors/audio/audio_buffer_processor.py index 8474466dc..1b6dc1856 100644 --- a/src/pipecat/processors/audio/audio_buffer_processor.py +++ b/src/pipecat/processors/audio/audio_buffer_processor.py @@ -33,8 +33,6 @@ class AudioBufferProcessor(FrameProcessor): self._assistant_audio_buffer = bytearray() self._num_channels = None self._sample_rate = None - self._assistant_audio = False - self._user_audio = False def _buffer_has_audio(self, buffer: bytearray): return ( @@ -87,14 +85,6 @@ class AudioBufferProcessor(FrameProcessor): if (isinstance(frame, AudioRawFrame) and self._sample_rate is None): self._sample_rate = frame.sample_rate - if isinstance(frame, BotStartedSpeakingFrame): - self._assistant_audio = True - - # this handles the case where the user starts speaking and interrupts the bot - if (isinstance(frame, BotStoppedSpeakingFrame) or - isinstance(frame, UserStartedSpeakingFrame)): - self._assistant_audio = False - # include all audio from the user if isinstance(frame, InputAudioRawFrame): self._user_audio_buffer.extend(frame.audio) @@ -105,7 +95,7 @@ class AudioBufferProcessor(FrameProcessor): self._assistant_audio_buffer.extend(silence) # if the assistant is speaking, include all audio from the assistant, - if (isinstance(frame, OutputAudioRawFrame)) and self._assistant_audio: + if (isinstance(frame, OutputAudioRawFrame)): self._assistant_audio_buffer.extend(frame.audio) # do not push the user's audio frame, doing so will result in echo