import type { AudioFrame, VideoFrame } from '@livekit/rtc-node';
import { ChatContext } from './chat_context.js';
import type { DuplexModel, DuplexSession } from './duplex.js';
import { type GenerationCreatedEvent, RealtimeModel, RealtimeSession } from './realtime.js';
import type { ToolChoice, ToolContext } from './tool_context.js';
/** Decides which output frames carry speech worth playing. */
export interface AudioGate {
    /** Return whether this frame belongs to an active speech burst. */
    update(frame: AudioFrame): boolean;
    /** End the current burst while retaining the learned noise floor. */
    deactivate(): void;
}
/** Thresholds and timing used to distinguish speech from silence. */
export interface AudioGateOptions {
    /** RMS level relative to the silence floor that opens the gate. Defaults to 3. */
    activationRatio?: number;
    /** RMS level relative to the silence floor that starts the quiet timer. Defaults to 1.8. */
    deactivationRatio?: number;
    /** Duration of quiet audio that ends a burst, in milliseconds. Defaults to 500. */
    minSilenceDuration?: number;
}
/** An audio gate for a provider whose silence level is known. */
export declare class FixedGate implements AudioGate {
    private readonly floor;
    private readonly activationRatio;
    private readonly deactivationRatio;
    private readonly minSilenceDuration;
    private open;
    private quiet;
    /** Create a gate with a normalized PCM RMS silence level and optional thresholds. */
    constructor(silence: number, options?: AudioGateOptions);
    /** End the active burst while preserving the configured silence floor. */
    deactivate(): void;
    /** Update the gate from this frame's RMS level and audio duration. */
    update(frame: AudioFrame): boolean;
}
/** Options for learning a silence floor from the provider's continuous audio. */
export interface AdaptiveNoiseGateOptions extends AudioGateOptions {
    /** Duration of quiet history used to learn the floor, in milliseconds. Defaults to 10000. */
    window?: number;
}
/** Learns the noise floor from quiet stretches, so sustained speech cannot raise it. */
export declare class AdaptiveNoiseGate implements AudioGate {
    private readonly activationRatio;
    private readonly deactivationRatio;
    private readonly minSilenceDuration;
    private readonly window;
    private history;
    private historyDuration;
    private stretchSum;
    private stretchDuration;
    private open;
    private quiet;
    /** Create a gate that learns its silence floor from quiet audio. */
    constructor(options?: AdaptiveNoiseGateOptions);
    /** End the active burst while preserving the learned silence floor. */
    deactivate(): void;
    /** Update the learned floor and determine whether this frame belongs to a speech burst. */
    update(frame: AudioFrame): boolean;
}
/** Options for converting continuous duplex audio into realtime generations. */
export interface DuplexRealtimeAdapterOptions {
    /** Creates a separate gate for each session. Defaults to the model's gate or an adaptive gate. */
    gate?: () => AudioGate;
    /** Wait after the last frame's duration before ending a burst, in milliseconds. Defaults to 800. */
    audioTimeout?: number;
}
/** Segments a duplex model's continuous output into ordinary realtime generations. */
export declare class DuplexRealtimeAdapter extends RealtimeModel {
    /** Continuous audio model wrapped by this adapter. */
    readonly duplexModel: DuplexModel;
    private readonly options;
    /** Adapt a duplex model for the framework's realtime generation interface. */
    constructor(
    /** Continuous audio model wrapped by this adapter. */
    duplexModel: DuplexModel, options?: DuplexRealtimeAdapterOptions);
    /** Model identifier reported by the wrapped provider. */
    get model(): string;
    /** Provider identifier reported by the wrapped model. */
    get provider(): string;
    /** Create a provider session with its own audio gate and burst state. */
    session(): RealtimeSession;
    /** Release the wrapped model's shared resources. */
    close(): Promise<void>;
}
/** @internal */
export declare class DuplexRealtimeSession extends RealtimeSession {
    readonly duplexSession: DuplexSession;
    private readonly gate;
    private readonly audioTimeout;
    private burst?;
    private audioMs;
    private fragments;
    private waitingSinceMs;
    private pendingReply?;
    private _chatCtx;
    private audioReader?;
    private readonly segmentTask;
    private readonly unsubscribe;
    private closed;
    private closeTask?;
    constructor(adapter: DuplexRealtimeAdapter, duplexSession: DuplexSession, gate: AudioGate, audioTimeout: number);
    private listen;
    private segment;
    private onAudioFrame;
    private openBurst;
    private closeBurst;
    private onInputTranscription;
    private onFunctionCall;
    get chatCtx(): ChatContext;
    get tools(): ToolContext;
    _updateSession(instructions?: string, chatCtx?: ChatContext, tools?: ToolContext): Promise<void>;
    updateInstructions(instructions: string): Promise<void>;
    updateChatCtx(chatCtx: ChatContext): Promise<void>;
    updateTools(tools: ToolContext): Promise<void>;
    updateOptions(options: {
        toolChoice?: ToolChoice | null;
    }): void;
    pushAudio(frame: AudioFrame): void;
    pushVideo(frame: VideoFrame): void;
    generateReply(instructions?: string, options?: {
        signal?: AbortSignal;
    }): Promise<GenerationCreatedEvent>;
    commitAudio(): Promise<void>;
    clearAudio(): Promise<void>;
    interrupt(): Promise<void>;
    truncate(): Promise<void>;
    private failPendingReply;
    close(): Promise<void>;
    private closeImpl;
}
//# sourceMappingURL=duplex_adapter.d.ts.map