What is best practice to handle failing tts_node
# ask-ai
a
What is best practice to handle failing tts_node
t
Thanks for reaching out, Jaihee. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you asked about handling a failing
tts_node
in LiveKit! A great way to manage this smoothly is by using the built-in FallbackAdapter mechanism. It’s designed to take care of failures and recovery automatically, so you can feel confident your TTS instances stay reliable. Here’s a friendly overview of how it works: • Automated Fallback: The
FallbackAdapter
keeps an eye on multiple TTS instances and will seamlessly switch to the next available service if one happens to fail. • Recovery Attempts: When a TTS instance fails, it’s marked as unavailable, but don’t worry—background tasks regularly check to see if it’s back up and running. • Resilient Workflow: The system logs warnings when failures occur but keeps things moving by using the next available instance. If, by chance, all instances fail, it will raise an
APIConnectionError
. • Configuration: You can easily set up the adapter with multiple TTS providers to keep things running smoothly and ensure high availability. Here’s how you can get started: 1. Initialize the
FallbackAdapter
with your list of TTS instances. 2. Use the
stream()
or
synthesize()
methods just like you normally would—the adapter takes care of any hiccups behind the scenes. 3. Keep an eye on your logs for
tts_availability_changed
events to stay informed about recovery attempts. This method helps make your speech synthesis experience much more robust and hassle-free, with the system thoughtfully designed to self-heal and keep things running smoothly. If you have any questions or need a hand setting this up, I’m here to help! Sources: Pipeline nodes and hooks | LiveKit docs | livekit-agents/livekit/agents/voice/agent.py
a
we override tts_node() of agent. in this case we also benefit from fallbackadapter?
t
Absolutely! Overriding
tts_node()
in your agent still works perfectly with
FallbackAdapter
, as long as your override plays nicely with the default implementation. Think of
FallbackAdapter
as your safety net at the TTS service level—it handles failover and recovery smoothly behind the scenes. Here’s a simple way to make sure everything fits together: 1. Override
tts_node()
to include your custom touches, like text preprocessing. 2. Within your override, call
Agent.default.tts_node()
, passing along the processed text and model settings. 3. Set up your agent’s TTS instance as a
FallbackAdapter
, specifying your primary and backup TTS providers. For instance, you might want to preprocess text by replacing emoticons in your override, then hand off the synthesis to the default node. The
FallbackAdapter
will take care of any failover or recovery seamlessly, giving you reliable speech synthesis. If you’d like, I’m here to help walk you through the implementation or clarify anything further—just let me know! Sources: livekit-agents/livekit/agents/tts/__init__.py | Events and error handling | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs | docs/index.yaml