import type { WebSocket } from 'ws';
import { type LanguageCode } from '../language.js';
import { STT as BaseSTT, SpeechStream as BaseSpeechStream, type SpeechEvent } from '../stt/index.js';
import { type APIConnectOptions } from '../types.js';
import { type AudioBuffer } from '../utils.js';
import { type VAD } from '../vad.js';
import { type AnyString } from './utils.js';
export type DeepgramModels = 'deepgram/nova-3' | 'deepgram/nova-3-medical' | 'deepgram/nova-2' | 'deepgram/nova-2-medical' | 'deepgram/nova-2-conversationalai' | 'deepgram/nova-2-phonecall';
export type DeepgramFluxModels = 'deepgram/flux-general' | 'deepgram/flux-general-en' | 'deepgram/flux-general-multi';
export type CartesiaModels = 'cartesia/ink-whisper' | 'cartesia/ink-2';
export type AssemblyaiModels = 'assemblyai/universal-streaming' | 'assemblyai/universal-streaming-multilingual' | 'assemblyai/u3-rt-pro' | 'assemblyai/universal-3-5-pro';
export type XaiSTTModels = 'xai/stt-1';
export type SpeechmaticsModels = 'speechmatics/enhanced' | 'speechmatics/standard' | 'speechmatics/linden-1';
export type InworldSTTModels = 'inworld/inworld-stt-1';
export type GoogleSTTModels = 'google/gemini-3.5-transcribe-live';
export interface CartesiaOptions {
    /** Minimum volume threshold. Ink Whisper only. Default: not specified. */
    min_volume?: number;
    /** Maximum silence duration in seconds. Ink Whisper only. Default: not specified. */
    max_silence_duration_secs?: number;
    /** Turn-start threshold (0.5-0.9). Default: 0.8. */
    turn_start_threshold?: number;
    /** Eager turn-end threshold (0.3-0.6). Default: 0.4. */
    turn_eager_end_threshold?: number;
    /** Turn-end threshold (0.05-0.5). Default: 0.2. */
    turn_end_threshold?: number;
    /** Turn-end timeout in milliseconds (640-11200). Default: 5600. */
    turn_end_timeout_ms?: number;
    /** Key terms, up to 100 terms totaling 1200 characters. */
    keyterm?: string | string[];
}
export interface DeepgramOptions {
    /** Enable filler words. Default: true. */
    filler_words?: boolean;
    /** Enable interim results. Default: true. */
    interim_results?: boolean;
    /** Endpointing timeout in milliseconds. Default: 25. */
    endpointing?: number;
    /** Enable punctuation. Default: false. */
    punctuate?: boolean;
    /** Enable smart formatting. */
    smart_format?: boolean;
    /** Keywords with boost values. */
    keywords?: Array<[string, number]>;
    /** Key terms for recognition. */
    keyterm?: string | string[];
    /** Enable profanity filter. */
    profanity_filter?: boolean;
    /** Convert spoken numbers to numerals. */
    numerals?: boolean;
    /** Opt out of model improvement program. */
    mip_opt_out?: boolean;
    /** Enable speaker diarization. Default: false. */
    diarize?: boolean;
}
export interface DeepgramFluxOptions {
    /** Eager end-of-turn threshold (0.3–0.9). Enables preflight transcripts for preemptive generation. Default: 0.5. */
    eager_eot_threshold?: number;
    /** End-of-turn threshold (0.5–0.9). */
    eot_threshold?: number;
    /** End-of-turn timeout in milliseconds. */
    eot_timeout_ms?: number;
    /** Key terms for recognition. */
    keyterm?: string | string[];
    /** Opt out of model improvement program. Default: false. */
    mip_opt_out?: boolean;
    /** Language hint. */
    language_hint?: string;
    /** Enable automatic language detection. */
    detect_language?: boolean;
}
export interface AssemblyAIOptions {
    /** Enable turn formatting. Default: false. */
    format_turns?: boolean;
    /** End of turn confidence threshold. Default: 0.01. */
    end_of_turn_confidence_threshold?: number;
    /** Minimum silence duration in milliseconds when confident about end of turn. Default: 0. */
    min_end_of_turn_silence_when_confident?: number;
    /** Maximum turn silence in milliseconds. Default: not specified. */
    max_turn_silence?: number;
    /** Key terms prompt for recognition. Default: not specified. */
    keyterms_prompt?: string[];
    /** Enable speaker diarization. Default: false. */
    speaker_labels?: boolean;
    /** Context to bias recognition. Only supported with u3-rt-pro. Max 1500 chars. */
    agent_context?: string;
    /** Isolate the primary voice. Only supported with u3-rt-pro. */
    voice_focus?: 'near-field' | 'far-field';
    /** Background suppression strength. Only supported with u3-rt-pro. */
    voice_focus_threshold?: number;
    /** Accuracy/latency preset. Only supported with u3-rt-pro. */
    mode?: 'min_latency' | 'balanced' | 'max_accuracy';
}
export interface XaiOptions {
    /** Enable speaker diarization. Default: false. */
    diarize?: boolean;
    /** Silence duration in ms before utterance-final (0-5000). */
    endpointing?: number;
    /** Enable Inverse Text Normalization. Requires language. */
    format?: boolean;
    /** Default true; set false to opt out of interim transcripts. */
    interim_results?: boolean;
}
export interface SpeechmaticsOptions {
    /** Domain to use, for example "finance". */
    domain?: string;
    /** BCP-47 locale for output formatting. */
    output_locale?: string;
    /** Maximum delay in seconds. Valid range is 0.7-4.0. Default: 1.0. RT only. */
    max_delay?: number;
    /** Maximum delay mode. RT only. */
    max_delay_mode?: 'flexible' | 'fixed' | string;
    /** Enable diarization for modes other than "none". */
    diarization?: 'none' | 'speaker' | 'channel' | 'channel_and_speaker_change' | 'speaker_change' | string;
    /** Speaker diarization sensitivity. Valid range is 0.0-1.0. */
    speaker_sensitivity?: number;
    /** Maximum number of speakers to detect. */
    max_speakers?: number;
    /** Prefer grouping nearby words as the current speaker. */
    prefer_current_speaker?: boolean;
    /** Enable partial results. Default: true, overridden by the gateway. */
    enable_partials?: boolean;
    /** Enable entity recognition. RT only. */
    enable_entities?: boolean;
    /** Punctuation override configuration. */
    punctuation_overrides?: Record<string, unknown>;
    /** Additional vocabulary entries for custom dictionary support. RT only. */
    additional_vocab?: Array<Record<string, unknown>>;
    /** Seconds of silence before finalizing an utterance. RT only. */
    end_of_utterance_silence_trigger?: number;
    /** Audio filtering configuration. RT only. */
    audio_filtering_config?: Record<string, unknown>;
    /** Transcript filtering configuration. RT only. */
    transcript_filtering_config?: Record<string, unknown>;
}
export interface InworldSTTOptions {
    /** Enable Voice Profile detection. Default: true. */
    enable_voice_profile?: boolean;
    /** Max labels per category in voice-profile responses (1–20). Default: 10. */
    voice_profile_top_n?: number;
    /** Enable word-level timestamps. Default: true. */
    include_word_timestamps?: boolean;
    /** Wire-format encoding sent to Inworld. Default: LINEAR16. */
    audio_encoding?: 'LINEAR16' | 'AUTO_DETECT';
    /** Stop transcription after this many seconds of silence; 0 disables. */
    inactivity_timeout_seconds?: number;
    /** End-of-turn confidence threshold (0.0–1.0). Default: 0.5. */
    end_of_turn_confidence_threshold?: number;
    /** Domain-specific contextual hints passed to the model. */
    prompts?: string[];
    /** Minimum end-of-turn silence in milliseconds when confident. */
    min_end_of_turn_silence_when_confident?: number;
    /** VAD threshold (0.0–1.0). Default: 0.5. */
    vad_threshold?: number;
}
export interface GoogleSTTOptions {
    /** BCP-47 language codes. Omit or pass an empty list to detect the language. */
    language_codes?: string[];
    /** Up to 1000 terms that bias recognition. */
    custom_vocabulary?: string[];
}
export type STTLanguages = 'multi' | 'en' | 'de' | 'es' | 'fr' | 'ja' | 'pt' | 'zh' | 'hi' | AnyString;
type _STTModels = DeepgramModels | DeepgramFluxModels | CartesiaModels | AssemblyaiModels | XaiSTTModels | SpeechmaticsModels | InworldSTTModels | GoogleSTTModels;
export type STTModels = _STTModels | 'auto' | AnyString;
export type ModelWithLanguage = `${_STTModels}:${STTLanguages}` | STTModels;
export type STTOptions<TModel extends STTModels> = TModel extends DeepgramFluxModels ? DeepgramFluxOptions : TModel extends DeepgramModels ? DeepgramOptions : TModel extends CartesiaModels ? CartesiaOptions : TModel extends AssemblyaiModels ? AssemblyAIOptions : TModel extends XaiSTTModels ? XaiOptions : TModel extends SpeechmaticsModels ? SpeechmaticsOptions : TModel extends InworldSTTModels ? InworldSTTOptions : TModel extends GoogleSTTModels ? GoogleSTTOptions : Record<string, unknown>;
/** Inference Fallback Adapter: configuration for a fallback STT model that runs server-side in LiveKit Inference, providing automatic fallback between providers. Extra fields are passed through to the provider. */
export interface STTFallbackModel {
    /** Model name (e.g. "deepgram/nova-3", "assemblyai/universal-streaming", "cartesia/ink-whisper"). */
    model: string;
    /** Extra configuration for the model. */
    extraKwargs?: Record<string, unknown>;
}
export type STTFallbackModelType = STTFallbackModel | string;
/** Parse a model string into [model, language]. Language is undefined if not specified. */
export declare function parseSTTModelString(model: string): [string, LanguageCode | undefined];
/** Normalize a single or list of FallbackModelType into STTFallbackModel[]. */
export declare function normalizeSTTFallback(fallback: STTFallbackModelType | STTFallbackModelType[]): STTFallbackModel[];
export type STTEncoding = 'pcm_s16le';
export interface InferenceSTTOptions<TModel extends STTModels> {
    model?: TModel;
    language?: LanguageCode;
    encoding: STTEncoding;
    sampleRate: number;
    baseURL: string;
    apiKey: string;
    apiSecret: string;
    modelOptions: STTOptions<TModel>;
    fallback?: STTFallbackModel[];
    connOptions?: APIConnectOptions;
}
/**
 * Livekit Cloud Inference STT
 */
export declare class STT<TModel extends STTModels> extends BaseSTT {
    #private;
    private opts;
    private streams;
    private vad?;
    private _vadPromise?;
    /** framework-managed; merged into modelOptions @internal */
    _sessionKeyterms: string[];
    /**
     * Resolves to the VAD instance for the current model, or `undefined` if the model
     * handles endpointing server-side. Lazily computed on first read.
     */
    get vadPromise(): Promise<VAD | undefined>;
    constructor(opts?: {
        model?: ModelWithLanguage;
        language?: STTLanguages;
        baseURL?: string;
        encoding?: STTEncoding;
        sampleRate?: number;
        apiKey?: string;
        apiSecret?: string;
        modelOptions?: STTOptions<TModel>;
        fallback?: STTFallbackModelType | STTFallbackModelType[];
        connOptions?: APIConnectOptions;
        vad?: VAD;
    });
    get label(): string;
    get model(): string;
    get provider(): string;
    static fromModelString(modelString: string): STT<AnyString>;
    protected _recognize(_: AudioBuffer): Promise<SpeechEvent>;
    updateOptions(opts: Partial<Pick<InferenceSTTOptions<TModel>, 'model' | 'language' | 'modelOptions'>>): void;
    _updateSessionKeyterms(keyterms: string[]): void;
    stream(options?: {
        language?: STTLanguages | string;
        connOptions?: APIConnectOptions;
    }): SpeechStream<TModel>;
    connectWs(timeout: number): Promise<WebSocket>;
}
export declare class SpeechStream<TModel extends STTModels> extends BaseSpeechStream {
    #private;
    private opts;
    private requestId;
    private speaking;
    /** @internal */
    _pendingExtra?: Record<string, unknown>;
    private speechDuration;
    private reconnectEvent;
    private stt;
    private connOptions;
    private activeWs?;
    constructor(sttImpl: STT<TModel>, opts: InferenceSTTOptions<TModel>, connOptions: APIConnectOptions);
    get label(): string;
    /** @internal */
    get _speaking(): boolean;
    updateOptions(opts: Partial<Pick<InferenceSTTOptions<TModel>, 'model' | 'language' | 'modelOptions'>>): void;
    private onEndOfSpeech;
    protected run(): Promise<void>;
    /** Onset reported by a provider that detects it server-side (e.g. Cartesia Ink-2).
     *
     * Without this the first transcript has to stand in for onset, which lands about
     * 800ms late because it waits for a word to be decoded.
     */
    private processStartOfSpeech;
    private processTranscript;
}
export {};
//# sourceMappingURL=stt.d.ts.map