Class FallbackAudioProxy

An IAudioGenerator that wraps an ordered chain of audio providers and implements automatic failover for every operation.

Retry chain logic

Providers are tried left-to-right (index 0 first). The first provider that succeeds returns immediately. When a provider throws:

  • If it is NOT the last provider: an audio:generate:fallback event is emitted and the next provider is tried.
  • If it IS the last provider: an AggregateError containing every collected error is thrown.
  • If the chain is empty: an Error('No providers in audio fallback chain') is thrown immediately.

For generateMusic, providers whose IAudioGenerator.supports returns false for 'music' are silently skipped. For generateSFX, providers that don't support 'sfx' (or lack the method entirely) are skipped.

Implements

Constructors

  • Creates a new FallbackAudioProxy wrapping the given provider chain.

    Parameters

    • chain: IAudioGenerator[]

      Ordered list of audio providers to try. Must contain at least one entry for operations to succeed (an empty chain always throws).

    • emitter: EventEmitter<DefaultEventMap>

      EventEmitter on which audio:generate:fallback events are published so callers can observe the failover path.

    Returns FallbackAudioProxy

    Example

    const proxy = new FallbackAudioProxy(
    [sunoProvider, stableAudioProvider],
    new EventEmitter(),
    );

Methods

Properties

providerId: string

Identifier derived from the first provider in the chain.

isInitialized: boolean = true

Always true — the proxy is ready as soon as it is constructed.

defaultModelId?: string

Default model from the first provider, if set.