worried-kite-20319
08/28/2025, 7:35 PMtall-airline-16756
08/28/2025, 7:35 PMtall-airline-16756
08/28/2025, 7:36 PMupdate_options method from the TTS plugin. This handy feature lets you tweak settings like voice, model, language, speed, and more—without having to pause or restart your session. Keep in mind, the exact options you can change depend on which TTS provider you're using.
Here are some examples for different providers to help you get started:
• Cartesia TTS: You can update the model, language, voice, speed, and even emotion controls. For example:
tts.update_options(
model="sonic-2-2025-03-07",
language="es",
voice="new-voice-id",
speed=1.2,
emotion=["happy"]
)
• Google TTS: Adjust language, gender, voice name, speaking rate, and volume gain. Here's how:
tts.update_options(
language="es-ES",
gender="female",
voice_name="es-ES-Neural2-A",
speaking_rate=1.1,
volume_gain_db=5.0
)
• Neuphonic TTS: Change voice_id, language code, speed, and sample rate like this:
tts.update_options(
voice_id="new-voice-id",
lang_code="es",
speed=1.3,
sample_rate=24000
)
When you switch agents, a good approach is to use function tools that return a new agent instance with the TTS settings you want. You can use the on_enter method of the new agent to announce the change and set up the TTS configuration right away. Or, if you prefer, you can just update the TTS options on the existing agent using update_options.
If you’d like a hand with the implementation or have any questions, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-playai/livekit/plugins/playai/tts.py | pipeline-tts/tts_comparison.pyworried-kite-20319
08/28/2025, 7:41 PMtall-airline-16756
08/28/2025, 7:42 PM@function_tool
async def switch_to_cartesia(self):
"""Switch to Cartesia TTS voice"""
return CartesiaAgent() # Returns agent with Cartesia TTS configuration
@function_tool
async def switch_to_openai(self):
"""Switch to OpenAI TTS voice"""
return OpenAIAgent() # Returns agent with OpenAI TTS configuration
When you switch, just make sure each agent is properly set up with its own TTS settings. You can even use the on_enter method of the new agent to announce the change and get everything initialized smoothly.
If you want me to walk you through this or have any questions, just give me a shout!worried-kite-20319
08/28/2025, 7:44 PMtall-airline-16756
08/28/2025, 7:45 PMfrom livekit.plugins import cartesia, openai
class CartesiaAgent(CharacterAgent):
def __init__(self, chat_ctx):
super().__init__(chat_ctx=chat_ctx, tts=cartesia.TTS(model="sonic-preview", voice="voice-id"))
class OpenAIAgent(CharacterAgent):
def __init__(self, chat_ctx):
super().__init__(chat_ctx=chat_ctx, tts=openai.TTS(model="gpt-4"))
2. Switch Agents Dynamically
Whenever you create a new agent instance, just pass in the TTS provider you want. Like this:
new_agent = CartesiaAgent(chat_ctx=fresh_chat_ctx)
session.userdata.character_agent_ref = new_agent
And if you want to switch back, simply create the other agent:
new_agent = OpenAIAgent(chat_ctx=fresh_chat_ctx)
session.userdata.character_agent_ref = new_agent
3. Use on_enter for Announcements
Each agent can use the on_enter method to let everyone know about the change:
async def on_enter(self):
await self.session.say("Hello! I am now using the Cartesia TTS voice.")
This way, you get smooth transitions between TTS providers without losing the session flow. If you want me to help you with anything else, just give me a shout!
Sources: multi-agent/long_or_short_agent.py | OpenAI Realtime API integration guide | LiveKit Docs | Gemini Live API integration guide | LiveKit Docs | Text-to-speech (TTS) integrations | LiveKit Docs | LiveKit integration guides | LiveKit Docs