Reorder frame pushing for STTMuteFilter, update STTMuteFrame to SystemFrame

This commit is contained in:
Mark Backman
2025-02-12 15:51:18 -05:00
parent 2e87a019a8
commit ee93e2a2b1
2 changed files with 19 additions and 14 deletions

View File

@@ -618,6 +618,13 @@ class FunctionCallInProgressFrame(SystemFrame):
arguments: str arguments: str
@dataclass
class STTMuteFrame(SystemFrame):
"""System frame to mute/unmute the STT service."""
mute: bool
@dataclass @dataclass
class TransportMessageUrgentFrame(SystemFrame): class TransportMessageUrgentFrame(SystemFrame):
message: Any message: Any
@@ -752,13 +759,6 @@ class TTSUpdateSettingsFrame(ServiceUpdateSettingsFrame):
pass pass
@dataclass
class STTMuteFrame(ControlFrame):
"""Control frame to mute/unmute the STT service."""
mute: bool
@dataclass @dataclass
class STTUpdateSettingsFrame(ServiceUpdateSettingsFrame): class STTUpdateSettingsFrame(ServiceUpdateSettingsFrame):
pass pass

View File

@@ -155,24 +155,25 @@ class STTMuteFilter(FrameProcessor):
"""Processes incoming frames and manages muting state.""" """Processes incoming frames and manages muting state."""
await super().process_frame(frame, direction) 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): if isinstance(frame, FunctionCallInProgressFrame):
self._function_call_in_progress = True 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): elif isinstance(frame, FunctionCallResultFrame):
self._function_call_in_progress = False self._function_call_in_progress = False
await self._handle_mute_state(await self._should_mute()) should_mute = await self._should_mute()
# Handle bot speaking state changes
elif isinstance(frame, BotStartedSpeakingFrame): elif isinstance(frame, BotStartedSpeakingFrame):
self._bot_is_speaking = True self._bot_is_speaking = True
await self._handle_mute_state(await self._should_mute()) should_mute = await self._should_mute()
elif isinstance(frame, BotStoppedSpeakingFrame): elif isinstance(frame, BotStoppedSpeakingFrame):
self._bot_is_speaking = False self._bot_is_speaking = False
if not self._first_speech_handled: if not self._first_speech_handled:
self._first_speech_handled = True 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( if isinstance(
frame, frame,
( (
@@ -190,3 +191,7 @@ class STTMuteFilter(FrameProcessor):
else: else:
# Pass all other frames through # Pass all other frames through
await self.push_frame(frame, direction) 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)