numerous-vr-95901
11/15/2025, 3:03 AMtall-airline-16756
11/15/2025, 3:03 AMtall-airline-16756
11/15/2025, 3:03 AMupdate_options method available on TTS instances. This method works smoothly across different TTS plugins and LiveKit’s unified inference gateway.
Here’s a friendly step-by-step guide to get you started:
1. Set up a listener for participant_attributes_changed so you can detect when a user picks a new voice.
2. Make sure to validate the selected voice ID to confirm it’s valid and supported.
3. Call tts.update_options(voice="new_voice_id") to update the voice. The change will take effect the next time the system speaks.
4. It’s a nice touch to provide user feedback, like confirming the voice switch, especially when the agent isn’t speaking.
This method works well with all supported TTS providers, including Cartesia, ElevenLabs, and Google Cloud. If you’d like, I’m here to help with any part of the implementation or answer any questions you might have!
Sources: agent/main.py | livekit-plugins/livekit-plugins-neuphonic/livekit/plugins/neuphonic/tts.py | Hume TTS plugin guide | LiveKit Docs | Introducing LiveKit Inference: A unified model interface for voice AInumerous-vr-95901
11/15/2025, 3:07 AMtall-airline-16756
11/15/2025, 3:07 AMswitch_to_hume() and switch_to_elevenlabs() that return the new agent instance.
3. When the user says something like "Switch to ElevenLabs," the function tool will handle the agent transfer, keeping your session state and context intact.
Another option is to use LiveKit Inference, which offers a simpler API. With this, switching providers just means reinitializing the agent with a new TTS string. If you’d like, I’m more than happy to provide detailed code examples or walk you through the process—just let me know!
Sources: docs/index.yaml | examples/src/comprehensive_test.ts | livekit-plugins/livekit-plugins-hume/livekit/plugins/hume/tts.py | Introducing LiveKit Inference: A unified model interface for voice AI | Hume TTS plugin guide | LiveKit Docsnumerous-vr-95901
11/15/2025, 3:08 AMtall-airline-16756
11/15/2025, 3:09 AMparticipant_attributes_changed event handler! Here's a friendly approach you can try:
1. First, listen for changes in participant attributes with the participant_attributes_changed event.
2. Then, check if there’s a specific attribute (like tts_provider) that tells you which TTS provider to use.
3. Finally, based on that attribute’s value, you can reinitialize the TTS instance or switch to a new agent set up with the chosen provider.
Here’s a simple example to illustrate:
@ctx.room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes, participant):
if "tts_provider" in changed_attributes:
provider = participant.attributes.get("tts_provider")
if provider == "hume":
tts = hume.TTS(...)
elif provider == "elevenlabs":
tts = elevenlabs.TTS(...)
# Update the agent or session with the new TTS instance
This way, you can update TTS providers in real-time based on what the user chooses. If you’d like, I’m here to walk you through more detailed steps or clarify anything—just let me know!
Sources: Participant attributes and metadata | LiveKit docs | agent/main.py | pipeline-tts/changing_language/README.md | Introducing LiveKit Inference: A unified model interface for voice AI | Job lifecycle | LiveKit Docsnumerous-vr-95901
11/15/2025, 3:10 AMtall-airline-16756
11/15/2025, 3:11 AMAgentSession, you can use the update_options method on the TTS instance. However, if you need to switch the TTS provider entirely, you will need to reinitialize the agent with the new TTS configuration. Here’s how you can proceed:
For updating the TTS instance dynamically:
@ctx.room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes, participant):
if "tts_provider" in changed_attributes:
provider = participant.attributes.get("tts_provider")
if provider == "hume":
session.tts.update_options(voice="HumeVoiceID", model="hume_model")
elif provider == "elevenlabs":
session.tts.update_options(voice="ElevenLabsVoiceID", model="elevenlabs_model")
# Provide feedback
asyncio.create_task(session.say("TTS provider updated successfully."))
If you need to switch providers entirely (e.g., from Hume to ElevenLabs), you will need to reinitialize the agent:
class HumeAgent(Agent):
def __init__(self):
super().__init__(
tts=hume.TTS(voice="HumeVoiceID"),
# other configurations
)
class ElevenLabsAgent(Agent):
def __init__(self):
super().__init__(
tts=elevenlabs.TTS(voice="ElevenLabsVoiceID"),
# other configurations
)
@ctx.room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes, participant):
if "tts_provider" in changed_attributes:
provider = participant.attributes.get("tts_provider")
if provider == "hume":
session = AgentSession(agent=HumeAgent())
elif provider == "elevenlabs":
session = AgentSession(agent=ElevenLabsAgent())
asyncio.create_task(session.say("Switched to the new TTS provider."))
I hope this helps you smoothly update or switch your TTS provider! If anything feels unclear or you’d like a hand with the implementation, please don’t hesitate to ask—I’m here to support you every step of the way.
Sources: OpenAI Realtime API plugin guide | LiveKit docs | Hume TTS plugin guide | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | pipeline-tts/tts_comparison/README.md | Text-to-speech (TTS) models | LiveKit Docsnumerous-vr-95901
11/15/2025, 3:33 AMtall-airline-16756
11/15/2025, 3:33 AMAgentSession to switch agents dynamically is a great approach. I’d like to share a few friendly tips to help make sure everything runs smoothly:
1. Make sure the new_agent is fully initialized with the TTS provider and configuration you want before starting the session.
2. Keep any important state or context from the previous session if needed—like user-specific data or room attributes—so nothing gets lost during the switch.
3. Try to handle any ongoing tasks or speech in the current session gently before switching over, to avoid any sudden interruptions.
Here’s a slightly polished version of your code that incorporates these ideas:
async def switch_agent(new_agent, voice_name, provider):
try:
# Create new session with the new agent
new_session = AgentSession(
vad=ctx.proc.userdata["vad"],
preemptive_generation=True
)
# Start the new session with the new agent
await new_session.start(agent=new_agent, room=ctx.room)
logger.info(f"âś… Successfully switched to voice '{voice_name}' (provider: {provider})")
print(f"âś… Agent switched to voice '{voice_name}' (provider: {provider})")
# Announce the switch using the new session
await new_session.say(f"Voice changed to {voice_name}.")
except Exception as e:
logger.error(f"Failed in switch_agent task: {e}")
logger.exception(e)
print(f"❌ Error in switch_agent: {e}")
This way, the new session gets set up properly and the voice change is kindly announced to everyone involved. If you have any questions or want to explore this further, just let me know—I’m here to help!numerous-vr-95901
11/15/2025, 3:39 AMtall-airline-16756
11/15/2025, 3:40 AMaclose() method on the current AgentSession. This helps tidy things up nicely and prevents multiple agents from speaking at the same time.
Here’s a friendly way to adjust your code:
async def switch_agent(new_agent, voice_name, provider):
try:
# Close the current session
if current_session:
await current_session.aclose()
# Create a new session with the new agent
new_session = AgentSession(
vad=ctx.proc.userdata["vad"],
preemptive_generation=True
)
# Start the new session with the new agent
await new_session.start(agent=new_agent, room=ctx.room)
logger.info(f"âś… Successfully switched to voice '{voice_name}' (provider: {provider})")
print(f"âś… Agent switched to voice '{voice_name}' (provider: {provider})")
# Announce the switch using the new session
await new_session.say(f"Voice changed to {voice_name}.")
except Exception as e:
logger.error(f"Failed in switch_agent task: {e}")
logger.exception(e)
print(f"❌ Error in switch_agent: {e}")
Just be sure to replace current_session with the actual reference to the active session you want to close. If anything feels unclear or you want to dive deeper, please don’t hesitate to ask—I’m here to help!
Sources: examples/warm-transfer/README.md | Job lifecycle | LiveKit Docsnumerous-vr-95901
11/15/2025, 10:01 PMtall-airline-16756
11/15/2025, 10:01 PMnumerous-vr-95901
11/15/2025, 10:02 PM