From cedccdcbc0df7d955e87461280c86ba60f4564e5 Mon Sep 17 00:00:00 2001 From: James Hush Date: Wed, 27 Nov 2024 11:50:28 +0800 Subject: [PATCH] Add interruptions --- examples/foundational/race_bot.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/foundational/race_bot.py b/examples/foundational/race_bot.py index af8e2834b..3b24cc7d7 100644 --- a/examples/foundational/race_bot.py +++ b/examples/foundational/race_bot.py @@ -14,6 +14,8 @@ from loguru import logger from runner import configure from pipecat.frames.frames import ( + StartInterruptionFrame, + StopInterruptionFrame, TranscriptionFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame, @@ -72,13 +74,23 @@ async def main(): # participant joins. @transport.event_handler("on_first_participant_joined") async def on_first_participant_joined(transport, participant): - frames = [ - UserStartedSpeakingFrame(), - TranscriptionFrame("Tell a joke about dogs.", "user_id", time.time()), - UserStoppedSpeakingFrame(), - ] - - await task.queue_frames(frames) + # Create frames for 3 seconds + start_time = time.time() + while time.time() - start_time < 300: + timestamp = time.time() + frames = [ + UserStartedSpeakingFrame(), + TranscriptionFrame("Tell a joke about dogs.", "user_id", timestamp), + UserStoppedSpeakingFrame(), + ] + await task.queue_frames(frames) + await asyncio.sleep(5) # Small delay between frame sets + next_frames = [ + StartInterruptionFrame(), + TranscriptionFrame("Tell a joke about cats.", "user_id", timestamp), + StopInterruptionFrame(), + ] + await task.queue_frames(next_frames) await runner.run(task)