Add direct muting to the STTMuteFilter

This commit is contained in:
Mark Backman
2025-05-02 14:46:00 -04:00
parent 8250736f5e
commit 8ac6ac5efb
4 changed files with 80 additions and 1 deletions

View File

@@ -287,3 +287,50 @@ class TestSTTMuteFilter(unittest.IsolatedAsyncioTestCase):
frames_to_send=frames_to_send,
expected_down_frames=expected_returned_frames,
)
async def test_direct_frame_muting(self):
"""Test that RequestSTTMuteFrame and RequestSTTUnmuteFrame directly control muting."""
from pipecat.frames.frames import RequestSTTMuteFrame, RequestSTTUnmuteFrame
# Create filter with no strategies to isolate direct frame control
filter = STTMuteFilter(config=STTMuteConfig(strategies=set()))
frames_to_send = [
# Initially unmuted - frames should pass through
UserStartedSpeakingFrame(),
InputAudioRawFrame(audio=b"", sample_rate=16000, num_channels=1),
UserStoppedSpeakingFrame(),
# Mute via frame - subsequent frames should be suppressed
RequestSTTMuteFrame(),
SleepFrame(sleep=0.1),
UserStartedSpeakingFrame(), # Should be suppressed
InputAudioRawFrame(
audio=b"", sample_rate=16000, num_channels=1
), # Should be suppressed
UserStoppedSpeakingFrame(), # Should be suppressed
# Unmute via frame - frames should pass through again
RequestSTTUnmuteFrame(),
SleepFrame(sleep=0.1),
UserStartedSpeakingFrame(),
InputAudioRawFrame(audio=b"", sample_rate=16000, num_channels=1),
UserStoppedSpeakingFrame(),
]
expected_returned_frames = [
UserStartedSpeakingFrame,
InputAudioRawFrame,
UserStoppedSpeakingFrame,
STTMuteFrame, # mute=True
RequestSTTMuteFrame,
STTMuteFrame, # mute=False
RequestSTTUnmuteFrame,
UserStartedSpeakingFrame,
InputAudioRawFrame,
UserStoppedSpeakingFrame,
]
await run_test(
filter,
frames_to_send=frames_to_send,
expected_down_frames=expected_returned_frames,
)