how do i change TTS engine dynamically
# ask-ai
j
how do i change TTS engine dynamically
t
Thanks for reaching out, Tyler. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can change the TTS (Text-to-Speech) engine dynamically in LiveKit using these approaches: • Switching Between Different TTS Providers: Create separate Agent classes for each TTS provider, then switch between them using function tools. For example, you can define a
RimeAgent
and an
ElevenLabsAgent
, each with its own TTS configuration, and provide a function tool to switch between them at runtime. • Using `session.update_agent()`: Programmatically switch agents with different TTS engines by calling
session.update_agent()
and passing a new agent instance with the desired TTS configuration. • Updating TTS Options Within the Same Engine: For some providers (like Hume), you can update parameters such as voice, description, or speed during the session using
session.tts.update_options()
. The changes take effect on the next utterance. Switching agents is the most flexible method, as it allows you to change not only the TTS provider but also other agent parameters as needed. Each agent can include an
on_enter()
method to announce the switch and confirm the new TTS voice.
j
well i just want to change the voice setting so each can, based on diff session context, can have diff tts voice
t
Hey there! Want to know a cool trick? You can actually switch up the TTS voice within the same engine during your session, and it's super easy with the
update_options
method. It's like having a voice chameleon that can change on the fly! Check out this neat example with Hume TTS:
Copy code
session.tts.update_options(
    voice=hume.VoiceByName(name="Colton Rivers", provider=hume.VoiceProvider.hume),
    description="The voice exudes calm, serene, and peaceful qualities, like a gentle stream flowing through a quiet forest.",
    speed=2,
)
And guess what? This isn't just a Hume thing! Other engines like Cartesia, Google, Neuphonic, LMNT, Speechify, and Inworld also support
update_options
with their own voice tweaks. Pretty flexible, right? The best part? You can adjust your TTS voice based on what's happening in your session, all without the hassle of switching engines or starting over. How cool is that? Sources: Hume TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-speechify/livekit/plugins/speechify/tts.py | agent/main.py