red-accountant-48215
05/16/2025, 9:39 AMtall-airline-16756
05/16/2025, 9:39 AMtall-airline-16756
05/16/2025, 9:39 AMFallbackAdapter
. The system logs warnings when a TTS (Text-to-Speech) service fails and switches to the next available service. Additionally, it emits an event called tts_availability_changed
to indicate changes in the availability of the TTS services. These mechanisms allow you to monitor both fallback triggers and service recoveries effectively.
Sources: livekit.agents.tts API documentation | livekit.agents.tts API documentationred-accountant-48215
05/16/2025, 9:40 AMtall-airline-16756
05/16/2025, 9:41 AMFallbackAdapter
changing to a different provider and printing the provider name. However, the concept involves logging or emitting events when a fallback occurs. If you have a specific implementation in mind, I can assist further or escalate this to a specialist for more detailed guidance.red-accountant-48215
05/16/2025, 9:41 AMtall-airline-16756
05/16/2025, 9:42 AMfrom livekit.agents import stt
from livekit.plugins import deepgram, openai, silero, cartesia, playai
# Create a VAD (Voice Activity Detection) instance
vad = silero.VAD.load()
# Create a fallback STT (Speech-to-Text) adapter
# If Deepgram fails, it will fall back to OpenAI
fallback_stt = stt.FallbackAdapter([
deepgram.STT(),
stt.StreamAdapter(stt=openai.STT(), vad=vad),
])
# Create a fallback LLM (Language Learning Model) adapter
# If OpenAI fails, it will fall back to Azure
fallback_llm = llm.FallbackAdapter([
openai.LLM(),
openai.LLM.with_azure(),
])
# Create a fallback TTS (Text-to-Speech) adapter
# If Cartesia fails, it will fall back to PlayAI
fallback_tts = tts.FallbackAdapter([
cartesia.TTS(),
playai.TTS(),
])
# Use these fallback adapters in a voice pipeline agent
agent = VoicePipelineAgent(
vad=vad,
stt=fallback_stt,
llm=fallback_llm,
tts=fallback_tts,
chat_ctx=initial_ctx,
fnc_ctx=fnc_ctx,
)
This example demonstrates how to set up fallback adapters for STT, LLM, and TTS components. Each adapter takes a list of services in priority order, and if the first service fails, it automatically switches to the next one in the list.
Sources: Tree View: | dse-workbenchred-accountant-48215
05/16/2025, 9:42 AMtall-airline-16756
05/16/2025, 9:42 AMtts_availability_changed
event in a FallbackAdapter
, you can listen for the event and take appropriate actions. Here's how the event is emitted and how you can handle it:
# When a TTS instance becomes unavailable
self._tts.emit(
"tts_availability_changed",
AvailabilityChangedEvent(tts=tts, available=False),
)
# When a TTS instance recovers and becomes available again
self._tts.emit(
"tts_availability_changed",
AvailabilityChangedEvent(tts=tts, available=True),
)
The AvailabilityChangedEvent
contains the TTS instance and its availability status. You can set up a listener for this event to handle it:
def on_availability_changed(event):
if event.available:
print(f"TTS provider {event.tts.label} is now available.")
else:
print(f"TTS provider {event.tts.label} is now unavailable.")
# Subscribe to the event
fallback_tts._tts.on("tts_availability_changed", on_availability_changed)
This will allow you to monitor and respond to changes in the availability of TTS providers.
Sources: livekit.agents.tts API documentation | livekit.agents.tts.fallback_adapter API documentationred-accountant-48215
05/16/2025, 9:47 AMtall-airline-16756
05/16/2025, 9:47 AM