When AgentSession is started with RoomInputOptions...
# ask-ai
c
When AgentSession is started with RoomInputOptions(audio_enabled=False, text_enabled=True) for text-only mode, the audio subscription infrastructure isn't created at all. If I later enable STT/TTS on the agent and want to switch to voice mode, the audio still doesn't work because audio_enabled=False prevented the audio subscription setup during session.start(). Is there ANY way to change audio_enabled from False to True after session.start() has been called? Or must I always start with audio_enabled=True even for text-only mode?
t
Thanks for reaching out, Clovis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just so you know, you can easily switch
audio_enabled
from
False
to
True
anytime after you’ve started your
AgentSession
with
session.start()
. All you need to do is use
session.input.set_audio_enabled(True)
and
session.output.set_audio_enabled(True)
to turn the audio input and output on or off while your session is running. Here’s a quick example: say you start the session with audio turned off:
Copy code
session.input.set_audio_enabled(False)
session.output.set_audio_enabled(False)
await session.start(...)
Later on, if you want to enable audio, just do this:
Copy code
session.input.set_audio_enabled(True)
session.output.set_audio_enabled(True)
This way, you don’t have to start with
audio_enabled=True
if you want to keep things text-only at first, and you can smoothly switch back and forth between text and voice whenever you like. Sources: Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/voice/io.py