FallbackAdapter is a TTS wrapper that provides automatic failover between multiple TTS providers.

When the primary TTS fails, it automatically switches to the next available provider in the list. Failed providers are monitored in the background and restored when they recover.

Features:

  • Automatic failover to backup TTS providers on failure
  • Background health checks to restore recovered providers
  • Automatic audio resampling when TTS providers have different sample rates
  • Support for both streaming and non-streaming TTS providers

Example

import { FallbackAdapter } from '@livekit/agents';
import { TTS as OpenAITTS } from '@livekit/agents-plugin-openai';
import { TTS as ElevenLabsTTS } from '@livekit/agents-plugin-elevenlabs';

const fallbackTTS = new FallbackAdapter({
ttsInstances: [
new OpenAITTS(), // Primary
new ElevenLabsTTS(), // Fallback
],
maxRetryPerTTS: 2, // Retry each TTS twice before moving to next
recoveryDelayMs: 1000, // Check recovery every 1 second
});

Hierarchy (view full)

Constructors

Properties

label: string = ...
maxRetryPerTTS: number

Number of retries per TTS instance before falling back to the next one.

recoveryDelayMs: number

Delay in milliseconds before attempting to recover a failed TTS instance.

ttsInstances: tts.TTS[]

The list of TTS instances used for fallback (in priority order).

Accessors

  • get numChannels(): number
  • Returns the channel count of audio frames returned by this TTS

    Returns number

  • get sampleRate(): number
  • Returns the sample rate of audio frames returned by this TTS

    Returns number

  • get status(): TTSStatus[]
  • Returns the current status of all TTS instances, including availability and recovery state.

    Returns TTSStatus[]

Methods

  • Close the FallbackAdapter and all underlying TTS instances. This cancels any ongoing recovery tasks and cleans up resources.

    Returns Promise<void>