is possible to turn off tts and stt via rpc during...
# ask-ai
c
is possible to turn off tts and stt via rpc during session?
t
Thanks for reaching out, Babken. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can turn off TTS (text-to-speech) and STT (speech-to-text) using RPC during a LiveKit session—it's pretty straightforward! If you want to disable STT, you just need to turn off the audio input with an RPC method like this:
Copy code
@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:
Copy code
@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