big-controller-60015
08/07/2025, 7:33 AMtall-airline-16756
08/07/2025, 7:33 AMtall-airline-16756
08/07/2025, 7:34 AMbig-controller-60015
08/07/2025, 7:36 AMtall-airline-16756
08/07/2025, 7:36 AMfrom livekit.agents.tts import FallbackAdapter
from livekit.plugins.elevenlabs import TTS as ElevenLabsTTS
from livekit.plugins.groq import TTS as GroqTTS
tts_instances = [
ElevenLabsTTS(...), # Just configure these as you need
GroqTTS(...) # Same here, tailor to your setup
]
# Now, create the FallbackAdapter
tts_fallback = FallbackAdapter(
tts=tts_instances,
max_retry_per_tts=2,
sample_rate=48000 # Optional, adjust if you need a specific sample rate
)
For STT:
from livekit.agents.stt import FallbackAdapter
from livekit.plugins.assemblyai import STT as AssemblyAISTT
from livekit.plugins.deepgram import STT as DeepgramSTT
stt_instances = [
AssemblyAISTT(...), # Configure these as you like
DeepgramSTT(...) # Same here, just set them up as needed
]
# Let’s create the FallbackAdapter for STT
stt_fallback = FallbackAdapter(
stt=stt_instances,
attempt_timeout=10.0, # How long to wait for each attempt
max_retry_per_stt=1, # How many times to retry per STT instance
retry_interval=5 # Time between retries
)
Event Handling: Want to keep an eye on availability changes? Here’s a simple way to do that:
def on_availability_changed(event):
# This will let you know when STT or TTS availability changes
print(f"STT: {event.stt.label} is {'available' if event.available else 'unavailable'}")
stt_fallback.on("stt_availability_changed", on_availability_changed)
tts_fallback.on("tts_availability_changed", on_availability_changed)
These examples should help you add some solid redundancy and failover for both TTS and STT in your LiveKit agent apps. If you have any questions or want to chat more about it, just let me know!