How to change tts while agent is active ?
# ask-ai
b
How to change tts while agent is active ?
t
Thanks for reaching out, Mustafa. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To change TTS (Text-to-Speech) settings while an agent is active, you can use one of the following methods: • Using the
update_options()
Method:
Most TTS providers allow updating their configuration during runtime. For example, with ElevenLabs TTS, you can dynamically change the language: `if self.tts is not None: self.tts.update_options(language="es") # Switch to Spanish`This method supports various options depending on the TTS provider, such as language, voice, speed, and more. • Using Participant Attributes for Dynamic Voice Changes: You can listen to participant attribute changes and update the TTS configuration accordingly. For example: `@ctx.room.on("participant_attributes_changed") def on_participant_attributes_changed(changed_attributes: dict[str, str], participant: rtc.Participant): if "voice" in changed_attributes: voice_id = participant.attributes.get("voice") # Update TTS configuration based on the new voice ID`This is useful for user-initiated voice changes in interactive applications. • Switching Between Different TTS Providers: You can create agents with different TTS configurations and switch between them dynamically. For example:
Copy code
class CartesiaAgent(Agent):
    def __init__(self):
        super().__init__(
            tts=cartesia.TTS(voice="voice_id_here")
        )

    async def switch_to_elevenlabs(self):
        return ElevenLabsAgent()
• Overriding TTS in Agent Constructor: You can override the TTS configuration when creating agents:
Copy code
class AssistantManager(Agent):
    def __init__(self):
        super().__init__(
            tts=cartesia.TTS(voice="voice_id_here")
        )
The most flexible approach is using the
update_options()
method, as it allows you to change TTS settings without recreating the entire agent or TTS instance. Let me know if you need further details on any of these methods. Sources: livekit-plugins/livekit-plugins-hume/livekit/plugins/hume/tts.py | multi-agent/long_or_short_agent.py | agent/main.py | Workflows | LiveKit Docs