Emit a transcription callback when receiving a CancelFrame, update examples accordingly

This commit is contained in:
Mark Backman
2025-01-22 14:55:15 -05:00
parent e1430be9f9
commit 7167719761
4 changed files with 12 additions and 19 deletions

View File

@@ -16,8 +16,7 @@ from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import ( from pipecat.frames.frames import (
EndFrame, CancelFrame,
StartInterruptionFrame,
TranscriptionMessage, TranscriptionMessage,
TranscriptionUpdateFrame, TranscriptionUpdateFrame,
) )
@@ -170,10 +169,8 @@ async def main():
@transport.event_handler("on_participant_left") @transport.event_handler("on_participant_left")
async def on_participant_left(transport, participant, reason): async def on_participant_left(transport, participant, reason):
# Interrupt the TTS to stop the TTS generation # Stop the pipeline immediately when the participant leaves
await task.queue_frame(StartInterruptionFrame()) await task.queue_frame(CancelFrame())
# Stop the gracefully stop the pipeline
await task.queue_frame(EndFrame())
runner = PipelineRunner() runner = PipelineRunner()

View File

@@ -16,8 +16,7 @@ from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import ( from pipecat.frames.frames import (
EndFrame, CancelFrame,
StartInterruptionFrame,
TranscriptionMessage, TranscriptionMessage,
TranscriptionUpdateFrame, TranscriptionUpdateFrame,
) )
@@ -170,10 +169,8 @@ async def main():
@transport.event_handler("on_participant_left") @transport.event_handler("on_participant_left")
async def on_participant_left(transport, participant, reason): async def on_participant_left(transport, participant, reason):
# Interrupt the TTS to stop the TTS generation # Stop the pipeline immediately when the participant leaves
await task.queue_frame(StartInterruptionFrame()) await task.queue_frame(CancelFrame())
# Stop the gracefully stop the pipeline
await task.queue_frame(EndFrame())
runner = PipelineRunner() runner = PipelineRunner()

View File

@@ -16,8 +16,7 @@ from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import ( from pipecat.frames.frames import (
EndFrame, CancelFrame,
StartInterruptionFrame,
TranscriptionMessage, TranscriptionMessage,
TranscriptionUpdateFrame, TranscriptionUpdateFrame,
) )
@@ -180,10 +179,8 @@ async def main():
@transport.event_handler("on_participant_left") @transport.event_handler("on_participant_left")
async def on_participant_left(transport, participant, reason): async def on_participant_left(transport, participant, reason):
# Interrupt the TTS to stop the TTS generation # Stop the pipeline immediately when the participant leaves
await task.queue_frame(StartInterruptionFrame()) await task.queue_frame(CancelFrame())
# Stop the gracefully stop the pipeline
await task.queue_frame(EndFrame())
runner = PipelineRunner() runner = PipelineRunner()

View File

@@ -10,6 +10,7 @@ from loguru import logger
from pipecat.frames.frames import ( from pipecat.frames.frames import (
BotStoppedSpeakingFrame, BotStoppedSpeakingFrame,
CancelFrame,
EndFrame, EndFrame,
Frame, Frame,
StartInterruptionFrame, StartInterruptionFrame,
@@ -115,6 +116,7 @@ class AssistantTranscriptProcessor(BaseTranscriptProcessor):
- BotStoppedSpeakingFrame: Completes current utterance - BotStoppedSpeakingFrame: Completes current utterance
- StartInterruptionFrame: Completes current utterance due to interruption - StartInterruptionFrame: Completes current utterance due to interruption
- EndFrame: Completes current utterance at pipeline end - EndFrame: Completes current utterance at pipeline end
- CancelFrame: Completes current utterance due to cancellation
Args: Args:
frame: Input frame to process frame: Input frame to process
@@ -129,7 +131,7 @@ class AssistantTranscriptProcessor(BaseTranscriptProcessor):
self._current_text_parts.append(frame.text) self._current_text_parts.append(frame.text)
elif isinstance(frame, (BotStoppedSpeakingFrame, StartInterruptionFrame)): elif isinstance(frame, (BotStoppedSpeakingFrame, StartInterruptionFrame, CancelFrame)):
# Emit accumulated text when bot finishes speaking or is interrupted # Emit accumulated text when bot finishes speaking or is interrupted
await self._emit_aggregated_text() await self._emit_aggregated_text()