From f807f233bd9b1df0651936a2702bdb6499b572c1 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Thu, 14 Nov 2024 17:11:51 -0500 Subject: [PATCH] Suppress UserStartedSpeakingFrame and UserStoppedSpeakingFrame when muted --- examples/foundational/24-stt-mute-processor.py | 2 +- src/pipecat/processors/filters/stt_mute.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/foundational/24-stt-mute-processor.py b/examples/foundational/24-stt-mute-processor.py index 2353b057d..4259a9558 100644 --- a/examples/foundational/24-stt-mute-processor.py +++ b/examples/foundational/24-stt-mute-processor.py @@ -51,7 +51,7 @@ async def main(): stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) # Configure the mute processor to mute only during first speech stt_mute_processor = STTMuteProcessor( - stt_service=stt, config=STTMuteConfig(strategy=STTMuteStrategy.ALWAYS) + stt_service=stt, config=STTMuteConfig(strategy=STTMuteStrategy.FIRST_SPEECH) ) tts = DeepgramTTSService(api_key=os.getenv("DEEPGRAM_API_KEY"), voice="aura-helios-en") diff --git a/src/pipecat/processors/filters/stt_mute.py b/src/pipecat/processors/filters/stt_mute.py index 5fae94fb7..60315094b 100644 --- a/src/pipecat/processors/filters/stt_mute.py +++ b/src/pipecat/processors/filters/stt_mute.py @@ -17,6 +17,8 @@ from pipecat.frames.frames import ( StartInterruptionFrame, StopInterruptionFrame, STTMuteFrame, + UserStartedSpeakingFrame, + UserStoppedSpeakingFrame, ) from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.services.ai_services import STTService @@ -60,7 +62,7 @@ class STTMuteProcessor(FrameProcessor): async def _handle_mute_state(self, should_mute: bool): """Handles both STT muting and interruption control.""" if should_mute != self.is_muted: - logger.info(f"STT {'muting' if should_mute else 'unmuting'}") + logger.debug(f"STT {'muting' if should_mute else 'unmuting'}") await self.push_frame(STTMuteFrame(mute=should_mute)) async def _should_mute(self) -> bool: @@ -90,12 +92,20 @@ class STTMuteProcessor(FrameProcessor): await self._handle_mute_state(await self._should_mute()) # Handle frame propagation - if isinstance(frame, (StartInterruptionFrame, StopInterruptionFrame)): - # Only pass interruption frames when not muted + if isinstance( + frame, + ( + StartInterruptionFrame, + StopInterruptionFrame, + UserStartedSpeakingFrame, + UserStoppedSpeakingFrame, + ), + ): + # Only pass VAD-related frames when not muted if not self.is_muted: await self.push_frame(frame, direction) else: - logger.debug("Interruption frame suppressed - STT currently muted") + logger.debug(f"{frame.__class__.__name__} suppressed - STT currently muted") else: # Pass all other frames through await self.push_frame(frame, direction)