import { AudioResampler } from '@livekit/rtc-node';
import { type APIConnectOptions } from '../types.js';
import { Task } from '../utils.js';
import { ChunkedStream, SynthesizeStream, TTS } from './tts.js';
/**
 * Internal status tracking for each TTS instance.
 * @internal
 */
interface TTSStatus {
    available: boolean;
    recoveringTask: Task<void> | null;
}
/**
 * Options for creating a FallbackAdapter.
 */
export interface FallbackAdapterOptions {
    /** List of TTS instances to use for fallback (in priority order). At least one is required. */
    ttsInstances: TTS[];
    /** Number of internal retries per TTS instance before moving to the next one. Defaults to 2. */
    maxRetryPerTTS?: number;
    /** Delay in milliseconds before attempting to recover a failed TTS instance. Defaults to 1000. */
    recoveryDelayMs?: number;
}
/**
 * Event emitted when a TTS instance's availability changes.
 */
export interface AvailabilityChangedEvent {
    /** The TTS instance whose availability changed. */
    tts: TTS;
    /** Whether the TTS instance is now available. */
    available: boolean;
}
/**
 * Agent Fallback Adapter for TTS. Manages multiple TTS instances, providing automatic fallback between 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
 * ```typescript
 * 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
 * });
 *
 * ```
 */
export declare class FallbackAdapter extends TTS {
    /** The list of TTS instances used for fallback (in priority order). */
    readonly ttsInstances: TTS[];
    /** Number of retries per TTS instance before falling back to the next one. */
    readonly maxRetryPerTTS: number;
    /** Delay in milliseconds before attempting to recover a failed TTS instance. */
    readonly recoveryDelayMs: number;
    private _status;
    private _logger;
    private _recoveryTimeouts;
    label: string;
    constructor(opts: FallbackAdapterOptions);
    private static aggregateCapabilities;
    private setupEventForwarding;
    /**
     * Returns the current status of all TTS instances, including availability and recovery state.
     */
    get status(): TTSStatus[];
    getStreamingInstance(index: number): TTS;
    /**
     * Creates a new AudioResampler for the given TTS index if needed.
     * Returns null if the TTS sample rate matches the adapter's output rate.
     * Each stream should create its own resampler to avoid concurrency issues.
     * @internal
     */
    createResamplerForTTS(index: number): AudioResampler | null;
    private emitAvailabilityChanged;
    private tryRecovery;
    markUnAvailable(index: number): void;
    /**
     * Receives text and returns synthesis in the form of a {@link ChunkedStream}
     */
    synthesize(text: string, connOptions?: APIConnectOptions, abortSignal?: AbortSignal): ChunkedStream;
    /**
     * Returns a {@link SynthesizeStream} that can be used to push text and receive audio data
     *
     * @param options - Optional configuration including connection options
     */
    stream(options?: {
        connOptions?: APIConnectOptions;
    }): SynthesizeStream;
    /**
     * Close the FallbackAdapter and all underlying TTS instances.
     * This cancels any ongoing recovery tasks and cleans up resources.
     */
    close(): Promise<void>;
}
export {};
//# sourceMappingURL=fallback_adapter.d.ts.map