import { WebSocket } from 'ws';
import { ConnectionPool } from '../connection_pool.js';
import { type LanguageCode } from '../language.js';
import type { ChunkedStream } from '../tts/index.js';
import { SynthesizeStream as BaseSynthesizeStream, TTS as BaseTTS } from '../tts/index.js';
import { type APIConnectOptions } from '../types.js';
import { type AnyString } from './utils.js';
export type CartesiaModels = 'cartesia/sonic-3.5' | 'cartesia/sonic-3' | 'cartesia/sonic-2' | 'cartesia/sonic-turbo' | 'cartesia/sonic' | 'cartesia/sonic-3-latest' | 'cartesia/sonic-latest';
export type DeepgramTTSModels = 'deepgram/aura' | 'deepgram/aura-2';
export type ElevenlabsModels = 'elevenlabs/eleven_flash_v2' | 'elevenlabs/eleven_flash_v2_5' | 'elevenlabs/eleven_turbo_v2' | 'elevenlabs/eleven_turbo_v2_5' | 'elevenlabs/eleven_multilingual_v2' | 'elevenlabs/eleven_v3';
export type InworldModels = 'inworld/inworld-tts-2' | 'inworld/inworld-tts-1.5-max' | 'inworld/inworld-tts-1.5-mini' | 'inworld/inworld-tts-1.5' | 'inworld/inworld-tts-1-max' | 'inworld/inworld-tts-1';
export type RimeModels = 'rime/arcana' | 'rime/coda' | 'rime/mistv2' | 'rime/mistv3' | 'rime/mist';
export type XaiTTSModels = 'xai/tts-1';
export interface CartesiaOptions {
    emotion?: string;
    /** Maximum duration of audio in seconds. */
    duration?: number;
    /** Speech speed. Default: not specified. */
    speed?: 'slow' | 'normal' | 'fast' | number;
    volume?: number;
    max_buffer_delay_ms?: number;
    add_timestamps?: boolean;
    add_phoneme_timestamps?: boolean;
    use_normalized_timestamps?: boolean;
}
export interface ElevenlabsOptions {
    /** Inactivity timeout in seconds. Default: 60. */
    inactivity_timeout?: number;
    /** Text normalization mode. Default: "auto". */
    apply_text_normalization?: 'auto' | 'off' | 'on';
    auto_mode?: boolean;
    enable_logging?: boolean;
    enable_ssml_parsing?: boolean;
    sync_alignment?: boolean;
    language_code?: string;
    /** Voice stability tuning, typically in the range [0, 1]. */
    stability?: number;
    /** Voice similarity tuning, typically in the range [0, 1]. */
    similarity_boost?: number;
    /** Style exaggeration tuning, typically in the range [0, 1]. */
    style?: number;
    /** Speech speed multiplier. */
    speed?: number;
    use_speaker_boost?: boolean;
    chunk_length_schedule?: number[];
    preferred_alignment?: string;
}
export interface DeepgramTTSOptions {
    /** Default: false. */
    mip_opt_out?: boolean;
}
export interface RimeOptions {
    /** Maximum number of tokens to generate. */
    max_tokens?: number;
    /** Values above 1 slow down audio; values below 1 speed it up. */
    time_scale_factor?: number;
    /** Default 1.0, <1 = faster, >1 = slower. */
    speed_alpha?: number;
    /** Default false. */
    pause_between_brackets?: boolean;
    /** Default false. */
    phonemize_between_brackets?: boolean;
    /** Comma-separated speed factors for [bracketed] words. */
    inline_speed_alpha?: string;
    /** Default false. */
    no_text_normalization?: boolean;
}
export interface InworldOptions {
    /** Range >0.5, <=1.5. */
    speaking_rate?: number;
    /** Range 0-2. */
    temperature?: number;
    timestamp_type?: 'TIMESTAMP_TYPE_UNSPECIFIED' | 'WORD' | 'CHARACTER';
    apply_text_normalization?: 'APPLY_TEXT_NORMALIZATION_UNSPECIFIED' | 'ON' | 'OFF';
    /** @deprecated Backward-compatible alias. Use `apply_text_normalization`. */
    text_normalization?: 'ON' | 'OFF';
}
export interface XaiTTSOptions {
    /** Output bit rate in bits per second. */
    bit_rate?: 32000 | 64000 | 96000 | 128000 | 192000;
}
type _TTSModels = CartesiaModels | DeepgramTTSModels | ElevenlabsModels | RimeModels | InworldModels | XaiTTSModels;
export type TTSModels = CartesiaModels | DeepgramTTSModels | ElevenlabsModels | RimeModels | InworldModels | XaiTTSModels | AnyString;
export type ModelWithVoice = `${_TTSModels}:${string}` | TTSModels;
export type TTSOptions<TModel extends TTSModels> = TModel extends CartesiaModels ? CartesiaOptions : TModel extends DeepgramTTSModels ? DeepgramTTSOptions : TModel extends ElevenlabsModels ? ElevenlabsOptions : TModel extends RimeModels ? RimeOptions : TModel extends InworldModels ? InworldOptions : TModel extends XaiTTSModels ? XaiTTSOptions : Record<string, unknown>;
/** Parse a model string into [model, voice]. Voice is undefined if not specified. */
export declare function parseTTSModelString(model: string): [string, string | undefined];
/**
 * Whether the given Inference TTS provider+options combination emits aligned
 * (word- or character-level) timestamps alongside the synthesized audio.
 *
 * Mirrors the Python implementation: support is opt-in through the provider's
 * `extra_kwargs` / `modelOptions` payload — the gateway only emits
 * `output_alignment` events when the provider-specific flag is set.
 */
export declare function hasAlignedTranscript(model: string | undefined, modelOptions: Record<string, unknown> | undefined): boolean;
/** Inference Fallback Adapter: configuration for a fallback TTS model that runs server-side in LiveKit Inference, providing automatic fallback between providers. */
export interface TTSFallbackModel {
    /** Model name (e.g. "cartesia/sonic", "elevenlabs/eleven_flash_v2", "rime/arcana"). */
    model: string;
    /** Voice to use for the model. */
    voice: string;
    /** Extra configuration for the model. */
    extraKwargs?: Record<string, unknown>;
}
export type TTSFallbackModelType = TTSFallbackModel | string;
/** Normalize a single or list of FallbackModelType into TTSFallbackModel[]. */
export declare function normalizeTTSFallback(fallback: TTSFallbackModelType | TTSFallbackModelType[]): TTSFallbackModel[];
type TTSEncoding = 'pcm_s16le';
export interface InferenceTTSOptions<TModel extends TTSModels> {
    model?: TModel;
    voice?: string;
    language?: LanguageCode;
    encoding: TTSEncoding;
    sampleRate: number;
    baseURL: string;
    apiKey: string;
    apiSecret: string;
    /** Flat provider-specific inference options forwarded as the `extra` payload field. */
    modelOptions: TTSOptions<TModel>;
    fallback?: TTSFallbackModel[];
    connOptions?: APIConnectOptions;
}
/**
 * Livekit Cloud Inference TTS
 */
export declare class TTS<TModel extends TTSModels> extends BaseTTS {
    #private;
    private opts;
    private streams;
    pool: ConnectionPool<WebSocket>;
    constructor(opts: {
        model: TModel;
        voice?: string;
        language?: string;
        baseURL?: string;
        encoding?: TTSEncoding;
        sampleRate?: number;
        apiKey?: string;
        apiSecret?: string;
        /** Flat provider-specific inference options forwarded as the `extra` payload field. */
        modelOptions?: TTSOptions<TModel>;
        fallback?: TTSFallbackModelType | TTSFallbackModelType[];
        connOptions?: APIConnectOptions;
    });
    get label(): string;
    get model(): string;
    get provider(): string;
    get capabilities(): {
        streaming: boolean;
        alignedTranscript: boolean;
    };
    static fromModelString(modelString: string): TTS<AnyString>;
    updateOptions(opts: Partial<Pick<InferenceTTSOptions<TModel>, 'model' | 'voice' | 'language' | 'modelOptions'>>): void;
    synthesize(_: string): ChunkedStream;
    stream(options?: {
        connOptions?: APIConnectOptions;
    }): SynthesizeStream<TModel>;
    connectWs(timeout: number): Promise<WebSocket>;
    closeWs(ws: WebSocket): Promise<void>;
    prewarm(): void;
    close(): Promise<void>;
}
export declare class SynthesizeStream<TModel extends TTSModels> extends BaseSynthesizeStream {
    #private;
    private opts;
    private tts;
    constructor(tts: TTS<TModel>, opts: InferenceTTSOptions<TModel>, connOptions: APIConnectOptions);
    get label(): string;
    updateOptions(opts: Partial<Pick<InferenceTTSOptions<TModel>, 'model' | 'voice' | 'language' | 'modelOptions'>>): void;
    protected run(): Promise<void>;
}
export {};
//# sourceMappingURL=tts.d.ts.map