can you dynamically update the agent's TTS provide...
# ask-ai
j
can you dynamically update the agent's TTS provider?
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.
Yes, you can dynamically update the agent's TTS provider in LiveKit, and there are two main approaches depending on your needs: 1. Updating TTS Options Within the Same Provider If you want to update configuration options like voice, language, speed, or emotion within the same TTS provider, you can use the provider's
update_options
method. For example, with Cartesia TTS:
Copy code
tts.update_options(
    model="sonic-2",
    language="en", 
    voice="new_voice_id",
    speed=1.2,
    emotion=["happy"]
)
Other providers like Google TTS and Neuphonic offer similar functionality for updating voice settings, speaking rate, and other parameters during runtime. 2. Switching Between Different TTS Providers If you need to switch between completely different TTS providers (e.g., from OpenAI to Cartesia), you can implement this using function tools that return new Agent instances. Here's an example:
Copy code
class RimeAgent(Agent):
    def __init__(self):
        super().__init__(
            tts=rime.TTS(sample_rate=44100, model="mistv2", speaker="abbie"),
            # other configurations...
        )

    @function_tool
    async def switch_to_cartesia(self):
        """Switch to Cartesia TTS voice"""
        return CartesiaAgent()

class CartesiaAgent(Agent):
    def __init__(self):
        super().__init__(
            tts=cartesia.TTS(
                sample_rate=44100,
                model="sonic-preview", 
                voice="87bc56aa-ab01-4baa-9071-77d497064686"
            ),
            # other configurations...
        )
Each agent class uses a different TTS provider, and you can switch providers by returning new agent instances. When a switch occurs, the
on_enter
method is called to announce the change to the user. This approach allows for complete flexibility, enabling you to change not just voice characteristics but the entire TTS engine and its capabilities. Sources: livekit-plugins/livekit-plugins-playai/livekit/plugins/playai/tts.py | pipeline-tts/tts_comparison.py