diff --git a/src/pipecat/frames/frames.py b/src/pipecat/frames/frames.py index 001a4116f..09d0a93b0 100644 --- a/src/pipecat/frames/frames.py +++ b/src/pipecat/frames/frames.py @@ -618,6 +618,13 @@ class FunctionCallInProgressFrame(SystemFrame): arguments: str +@dataclass +class STTMuteFrame(SystemFrame): + """System frame to mute/unmute the STT service.""" + + mute: bool + + @dataclass class TransportMessageUrgentFrame(SystemFrame): message: Any @@ -752,13 +759,6 @@ class TTSUpdateSettingsFrame(ServiceUpdateSettingsFrame): pass -@dataclass -class STTMuteFrame(ControlFrame): - """Control frame to mute/unmute the STT service.""" - - mute: bool - - @dataclass class STTUpdateSettingsFrame(ServiceUpdateSettingsFrame): pass diff --git a/src/pipecat/processors/filters/stt_mute_filter.py b/src/pipecat/processors/filters/stt_mute_filter.py index 3ea0cae2b..fcd492bb3 100644 --- a/src/pipecat/processors/filters/stt_mute_filter.py +++ b/src/pipecat/processors/filters/stt_mute_filter.py @@ -155,24 +155,25 @@ class STTMuteFilter(FrameProcessor): """Processes incoming frames and manages muting state.""" await super().process_frame(frame, direction) - # Handle function call state changes + # First determine if we need to change mute state + should_mute = None + if isinstance(frame, FunctionCallInProgressFrame): self._function_call_in_progress = True - await self._handle_mute_state(await self._should_mute()) + should_mute = await self._should_mute() elif isinstance(frame, FunctionCallResultFrame): self._function_call_in_progress = False - await self._handle_mute_state(await self._should_mute()) - # Handle bot speaking state changes + should_mute = await self._should_mute() elif isinstance(frame, BotStartedSpeakingFrame): self._bot_is_speaking = True - await self._handle_mute_state(await self._should_mute()) + should_mute = await self._should_mute() elif isinstance(frame, BotStoppedSpeakingFrame): self._bot_is_speaking = False if not self._first_speech_handled: self._first_speech_handled = True - await self._handle_mute_state(await self._should_mute()) + should_mute = await self._should_mute() - # Handle frame propagation + # Then push the original frame if isinstance( frame, ( @@ -190,3 +191,7 @@ class STTMuteFilter(FrameProcessor): else: # Pass all other frames through await self.push_frame(frame, direction) + + # Finally handle mute state change if needed + if should_mute is not None and should_mute != self.is_muted: + await self._handle_mute_state(should_mute)