From d77ed9948da7d8748ac65413aac19f8ea622e06d Mon Sep 17 00:00:00 2001 From: James Hush Date: Wed, 30 Apr 2025 16:04:38 +0800 Subject: [PATCH] Save order --- examples/simple-chatbot/server/bot-openai.py | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/examples/simple-chatbot/server/bot-openai.py b/examples/simple-chatbot/server/bot-openai.py index 07c56aa28..dd91bebb1 100644 --- a/examples/simple-chatbot/server/bot-openai.py +++ b/examples/simple-chatbot/server/bot-openai.py @@ -32,13 +32,17 @@ from pipecat.frames.frames import ( BotStartedSpeakingFrame, BotStoppedSpeakingFrame, Frame, + InterimTranscriptionFrame, OutputImageRawFrame, SpriteFrame, + STTMuteFrame, + TranscriptionFrame, ) from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext +from pipecat.processors.filters.stt_mute_filter import STTMuteConfig, STTMuteFilter, STTMuteStrategy from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.processors.frameworks.rtvi import RTVIConfig, RTVIObserver, RTVIProcessor from pipecat.services.elevenlabs.tts import ElevenLabsTTSService @@ -103,6 +107,30 @@ class TalkingAnimation(FrameProcessor): await self.push_frame(frame, direction) +class TranscriptionMuteProcessor(FrameProcessor): + def __init__(self): + super().__init__() + self._is_muted = False + + async def process_frame(self, frame: Frame, direction: FrameDirection): + await super().process_frame(frame, direction) + + if isinstance(frame, STTMuteFrame): + self._is_muted = frame.mute + + if isinstance( + frame, + (TranscriptionFrame, InterimTranscriptionFrame), + ): + # Only pass VAD-related frames when not muted + if not self._is_muted: + await self.push_frame(frame, direction) + else: + logger.trace( + f"{frame.__class__.__name__} suppressed - Transcription currently muted" + ) + + async def main(): """Main bot execution function. @@ -183,10 +211,23 @@ async def main(): # rtvi = RTVIProcessor(config=RTVIConfig(config=[])) + # Configure the mute processor with both strategies + stt_mute_processor = STTMuteFilter( + config=STTMuteConfig( + strategies={ + STTMuteStrategy.ALWAYS, + } + ), + ) + + transcription_mute_processor = TranscriptionMuteProcessor() + pipeline = Pipeline( [ transport.input(), rtvi, + stt_mute_processor, # Add the mute processor before STT + transcription_mute_processor, context_aggregator.user(), llm, tts,