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 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/coda' | 'rime/mistv2' | 'rime/mistv3' | 'rime/mist';
export type XaiTTSModels = 'xai/tts-1';
export type FishAudioModels = 'fishaudio' | 'fishaudio/s2.1-pro' | 'fishaudio/s2.1-pro-free' | 'fishaudio/s2-pro';
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 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;
    /** Controls output variation on inworld-tts-2 only. */
    delivery_mode?: 'DELIVERY_MODE_UNSPECIFIED' | 'STABLE' | 'BALANCED' | 'CREATIVE';
    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;
    /** Speaking-rate multiplier. Default: 1.0. */
    speed?: number;
}
/** See https://docs.fish.audio/api-reference/endpoint/websocket/tts-live */
export interface FishAudioOptions {
    /** Prosody speaking-rate multiplier, 1.0 is natural. */
    speed?: number;
    /** Prosody loudness adjustment in dB, 0 is natural. */
    volume?: number;
    /** Consistent output loudness; S2-Pro family only. */
    normalize_loudness?: boolean;
    /** Range 0-1, higher is more varied/expressive. */
    temperature?: number;
    /** Nucleus sampling probability mass, range 0-1. */
    top_p?: number;
    /** Normalize numbers/dates/abbreviations before synthesis. */
    normalize?: boolean;
    /** Streaming latency mode. */
    latency?: 'normal' | 'balanced' | 'low';
    /** Characters buffered before auto-synthesis, range 100-300. */
    chunk_length?: number;
    /** Max audio tokens per text chunk, default 1024. */
    max_new_tokens?: number;
    /** Min characters before splitting a new chunk, range 0-100. */
    min_chunk_length?: number;
    /** Use prior audio as context for consistency. */
    condition_on_previous_chunks?: boolean;
    /** Early-stopping threshold for batching, range 0-1. */
    early_stop_threshold?: number;
}
type _TTSModels = CartesiaModels | DeepgramTTSModels | RimeModels | InworldModels | XaiTTSModels | FishAudioModels;
export type TTSModels = CartesiaModels | DeepgramTTSModels | RimeModels | InworldModels | XaiTTSModels | FishAudioModels | AnyString;
export type ModelWithVoice = `${_TTSModels}:${string}` | TTSModels;
export type TTSOptions<TModel extends TTSModels> = TModel extends CartesiaModels ? CartesiaOptions : TModel extends DeepgramTTSModels ? DeepgramTTSOptions : TModel extends RimeModels ? RimeOptions : TModel extends InworldModels ? InworldOptions : TModel extends XaiTTSModels ? XaiTTSOptions : TModel extends FishAudioModels ? FishAudioOptions : 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", "deepgram/aura-2", "rime/coda"). */
    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;
    /**
     * Key the shared markup tables off the gateway model's provider.
     *
     * `llmInstructions` / `normalize` / `convert` are inherited from the base markup helper,
     * keyed on this.
     */
    protected markupProviderKey(): 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;
    /**
     * Snapshot whether expressive is active now, while the framework holds it fixed for this
     * synthesis (set synchronously before `stream()`). Reading it lazily in `run` would race
     * with the next turn/session mutating the shared TTS instance.
     */
    private expressive;
    /**
     * Alignment arrives finer-grained than a cue, so `dropBracketCues` parks the tail of an
     * unclosed span here between messages.
     */
    private heldTokens;
    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