Bridge incoming websocket control messages into Pipecat frames.
| 52 | |
| 53 | |
| 54 | class RealtimeInputControlProcessor(FrameProcessor): |
| 55 | """Bridge incoming websocket control messages into Pipecat frames.""" |
| 56 | |
| 57 | def __init__(self, voice_route: str): |
| 58 | super().__init__() |
| 59 | self._voice_route = voice_route |
| 60 | |
| 61 | async def process_frame(self, frame: Frame, direction: FrameDirection): |
| 62 | await super().process_frame(frame, direction) |
| 63 | |
| 64 | if isinstance(frame, InputTransportMessageFrame): |
| 65 | message = frame.message if isinstance(frame.message, dict) else {} |
| 66 | msg_type = message.get("type") |
| 67 | msg = message.get("msg") |
| 68 | |
| 69 | if msg_type == "instruction" and msg == "end_of_speech": |
| 70 | if self._voice_route == "gem_live": |
| 71 | await self.push_frame(VADUserStoppedSpeakingFrame(), FrameDirection.DOWNSTREAM) |
| 72 | else: |
| 73 | await self.push_frame( |
| 74 | EmulateUserStoppedSpeakingFrame(), FrameDirection.DOWNSTREAM |
| 75 | ) |
| 76 | await self.push_frame(STTMuteFrame(mute=True), FrameDirection.DOWNSTREAM) |
| 77 | return |
| 78 | |
| 79 | if msg_type == "instruction" and msg == "INTERRUPT": |
| 80 | await self.push_frame(InterruptionFrame(), FrameDirection.DOWNSTREAM) |
| 81 | if self._voice_route != "gem_live": |
| 82 | await self.push_frame(STTMuteFrame(mute=False), FrameDirection.DOWNSTREAM) |
| 83 | return |
| 84 | |
| 85 | await self.push_frame(frame, direction) |
| 86 | |
| 87 | |
| 88 | class RealtimeOutputControlProcessor(FrameProcessor): |