Class FallbackTTSProxy

A TextToSpeechProvider that wraps an ordered chain of TTS providers and implements automatic failover.

Retry Chain Logic

Identical to FallbackSTTProxy: providers are tried left-to-right, the first successful synthesis result is returned, and provider_fallback events are emitted on each intermediate failure.

Voice Listing

Voice listing is delegated to the first provider in the chain that exposes a listAvailableVoices() method. If no provider supports this, an empty array is returned. This is a best-effort approach — the voice list may not reflect the provider that actually handles synthesis if the primary fails.

See

ProviderFallbackEvent for the event payload shape See SpeechProviderResolver.resolveTTS() for how this proxy is created.

Example

const proxy = new FallbackTTSProxy([elevenlabsProvider, openaiTtsProvider], emitter);
const audio = await proxy.synthesize('Hello world');
// If ElevenLabs fails, OpenAI TTS is tried automatically.

Implements

Constructors

  • Creates a new FallbackTTSProxy wrapping the given provider chain.

    Parameters

    • chain: TextToSpeechProvider[]

      Ordered list of TTS providers to try.

    • emitter: EventEmitter<DefaultEventMap>

      EventEmitter on which provider_fallback events are published.

    Returns FallbackTTSProxy

    Example

    const proxy = new FallbackTTSProxy(
    [elevenlabsProvider, openaiTtsProvider],
    resolver,
    );

Methods

  • Attempt synthesis using each provider in the chain in order.

    Emits a provider_fallback event (typed as ProviderFallbackEvent) whenever a non-final provider throws. Re-throws the last provider's error when the entire chain is exhausted.

    Parameters

    • text: string

      The text to synthesize into speech.

    • Optional options: SpeechSynthesisOptions

      Optional synthesis settings (voice, speed, format, etc.).

    Returns Promise<SpeechSynthesisResult>

    The synthesis result from the first provider that succeeds.

    Throws

    'No providers in fallback chain' when the chain is empty.

    Throws

    The last provider's error when all providers in the chain fail.

    Example

    const result = await proxy.synthesize('Hello world', { voice: 'nova' });
    
  • Returns the human-readable name of the primary (first) provider.

    Returns string

    The provider name string, or 'fallback' if the chain is empty.

    Example

    proxy.getProviderName(); // 'ElevenLabs' (from the first chain entry)
    
  • Returns the voice list from the first provider in the chain that supports listAvailableVoices().

    Iterates through the chain looking for any provider that implements this optional method. Returns an empty array when no provider supports voice listing. This is a best-effort approach — if the primary provider fails during synthesis and a fallback provider handles it, the returned voice list may not match the provider that actually produced the audio.

    Returns Promise<SpeechVoice[]>

    A promise resolving to an array of available voices, or an empty array if no provider in the chain supports voice listing.

    Example

    const voices = await proxy.listAvailableVoices();
    // voices from the first provider that implements the method

Properties

id: string

Unique identifier derived from the first provider in the chain. Falls back to 'fallback-tts' for empty chains.

displayName: string

Human-readable name showing the full chain for debugging and logging. Format: "Fallback TTS (provider1 -> provider2 -> ...)".

supportsStreaming: boolean

Whether the proxy supports streaming. Only reflects the first provider's capability — see FallbackSTTProxy.supportsStreaming for rationale.