clean-mouse-53726
08/20/2025, 12:32 PMtall-airline-16756
08/20/2025, 12:32 PMtall-airline-16756
08/20/2025, 12:32 PM@ctx.room.local_participant.register_rpc_method("toggle_input")
async def on_toggle_input(data: rtc.RpcInvocationData) -> None:
if data.payload == "audio_off":
session.input.set_audio_enabled(False) # This stops the STT processing
elif data.payload == "audio_on":
session.input.set_audio_enabled(True) # This turns STT back on
And if you’re looking to disable TTS, you can switch off the audio output similarly:
@ctx.room.local_participant.register_rpc_method("toggle_output")
async def on_toggle_output(data: rtc.RpcInvocationData) -> None:
if data.payload == "audio_off":
session.output.set_audio_enabled(False) # This stops the TTS output
elif data.payload == "audio_on":
session.output.set_audio_enabled(True) # This turns TTS back on
These handy methods give you the flexibility to control audio input and output on the fly during your session, making it easy to switch up how you interact.
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Text and transcriptions | LiveKit Docs