import Emittery from 'emittery';
import GatewayService from '@/services/GatewayService';
import FramePlayer from '@/utils/framePlayer';
export type VoiceState = 'SLEEPING' | 'IDLE' | 'LISTENING' | 'THINKING' | 'SPEAKING' | 'COOLDOWN';
type TTSPlaybackContext = 'graceful_exit_prompt' | 'graceful_exit_phase2_prompt';
export interface VoiceError {
    code: 'WEBRTC_FAILED' | 'ASR_ERROR' | 'LLM_TIMEOUT' | 'LLM_ERROR' | 'TTS_FAILED' | 'GATEWAY_DISCONNECTED';
    message: string;
    recoverable: boolean;
}
export interface VoiceConversationEvents {
    stateChange: {
        state: VoiceState;
        prevState: VoiceState;
    };
    wakeUp: {
        trigger: 'word' | 'manual';
        word?: string;
    };
    sleep: {
        trigger: 'word' | 'timeout' | 'manual' | 'server';
    };
    bargeIn: {
        text: string;
        type?: 'supplement' | 'interrupt';
    };
    transcript: {
        text: string;
        isFinal: boolean;
    };
    response: {
        text: string;
    };
    speaking: {
        text: string;
    };
    speakEnd: void;
    error: VoiceError;
    webrtcReady: void;
    webrtcReconnecting: {
        attempt: number;
        maxAttempts: number;
    };
    interruptHintShow: {
        words: string[];
    };
    interruptHintHide: void;
    interrupted: {
        text: string;
        feedback: string;
        vad?: boolean;
    };
    postExitIdle: void;
    wakeConfirm: {
        text: string;
    };
}
export interface VoiceConversationConfig {
    gateway: GatewayService;
    renderer: any;
    framePlayer: FramePlayer;
    characterId: string;
    wakeWords?: string[];
    exitWords?: string[];
    interruptWords?: string[];
    idleTimeout?: number;
    silenceTimeout?: number;
    autoWake?: boolean;
    echoDetection?: boolean;
    ttsTransport?: 'auto' | 'webrtc' | 'websocket';
    voiceEngine?: 'pipeline' | 'doubao_pipeline' | 'doubao_e2e';
    bargeInSensitivity?: 'high' | 'medium' | 'low';
    interruptAck?: 'none' | 'short';
    interruptFeedback?: string;
    welcomeAsrResumeDelayMs?: number;
    enableInterrupt?: boolean;
    cooldownDuration?: number;
    doubleWakeWord?: boolean;
    wakeConfirmText?: string;
    syntheticTexts?: string[];
    gracefulExitEnabled?: boolean;
    gracefulExitPrompt?: string;
    gracefulExitPhase2Prompt?: string;
    gracefulExitPhase2Silence?: number;
    gracefulExitPhase3Silence?: number;
    bargeInStrictMode?: boolean;
    continuousWindowMs?: number;
    bargeInCooldownMs?: number;
    llmTimeoutMs?: number;
    llmMaxRetry?: number;
    webrtcMaxReconnectAttempts?: number;
    webrtcReconnectInterval?: number;
    vadGateWindowMs?: number;
    vadGraceMs?: number;
    interruptFollowUpWindowMs?: number;
    interruptWordFilterMs?: number;
    animations?: {
        wake?: string;
        idle?: string;
        talk?: string | string[];
    };
    onStateChange?: (state: VoiceState, prevState: VoiceState) => void;
    onTranscript?: (text: string, isFinal: boolean) => void;
    onResponse?: (text: string) => void;
    onError?: (error: VoiceError) => void;
}
interface InternalConfig extends Required<Omit<VoiceConversationConfig, 'onStateChange' | 'onTranscript' | 'onResponse' | 'onError' | 'animations' | 'interruptAck' | 'interruptFeedback' | 'enableInterrupt' | 'cooldownDuration' | 'doubleWakeWord' | 'wakeConfirmText' | 'syntheticTexts' | 'gracefulExitEnabled' | 'gracefulExitPrompt' | 'gracefulExitPhase2Prompt' | 'gracefulExitPhase2Silence' | 'gracefulExitPhase3Silence' | 'bargeInStrictMode' | 'continuousWindowMs' | 'ttsTransport' | 'voiceEngine' | 'bargeInCooldownMs' | 'llmTimeoutMs' | 'llmMaxRetry' | 'webrtcMaxReconnectAttempts' | 'webrtcReconnectInterval' | 'vadGateWindowMs' | 'vadGraceMs' | 'interruptFollowUpWindowMs' | 'interruptWordFilterMs'>> {
    onStateChange?: (state: VoiceState, prevState: VoiceState) => void;
    onTranscript?: (text: string, isFinal: boolean) => void;
    onResponse?: (text: string) => void;
    onError?: (error: VoiceError) => void;
    animations: {
        wake?: string;
        idle: string;
        talk: string | string[];
    };
    interruptAck?: 'none' | 'short';
    interruptFeedback?: string;
    enableInterrupt: boolean;
    doubleWakeWord: boolean;
    wakeConfirmText?: string;
    syntheticTexts: string[];
    gracefulExitEnabled: boolean;
    gracefulExitPrompt: string;
    gracefulExitPhase2Prompt: string;
    gracefulExitPhase2Silence: number;
    gracefulExitPhase3Silence: number;
    bargeInStrictMode: boolean;
    continuousWindowMs?: number;
    ttsTransport: 'auto' | 'webrtc' | 'websocket';
    voiceEngine: 'pipeline' | 'doubao_pipeline' | 'doubao_e2e';
    bargeInCooldownMs: number;
    llmTimeoutMs: number;
    llmMaxRetry: number;
    webrtcMaxReconnectAttempts: number;
    webrtcReconnectInterval: number;
    vadGateWindowMs: number;
    vadGraceMs: number;
    interruptFollowUpWindowMs: number;
    interruptWordFilterMs: number;
}
export declare class VoiceConversation extends Emittery {
    private _config;
    private _state;
    private _conversationId;
    private _isStarted;
    private isTransitioning;
    private pendingTransition;
    private textBuffer;
    private committedTranscript;
    private silenceTimer;
    private idleTimer;
    private currentRequestId;
    private activeLLMRequestId;
    private activeLLMResolve;
    private activeLLMReject;
    private activeLLMTimeout;
    private ttsStartTime;
    private lastBargeInTime;
    private speakingTextBuffer;
    private lastUserQuery;
    private static readonly CONTINUATION_WINDOW_MS;
    private static readonly BARGE_IN_MIN_TEXT_LENGTH;
    private static readonly DEFAULT_BARGE_IN_COOLDOWN_MS;
    private static readonly DEFAULT_WELCOME_ASR_RESUME_DELAY_MS;
    private interruptDetectionTimer;
    private interruptHintTimer;
    private interruptFollowUpTimer;
    private welcomeAsrResumeTimer;
    private interruptDetectionEnabled;
    private vadGateTimer;
    private vadGateActiveUntil;
    private vadGateEnabled;
    private lastVadTriggerTime;
    private static readonly DEFAULT_VAD_GATE_WINDOW_MS;
    private static readonly VAD_DUCK_GAIN;
    private static readonly VAD_DUCK_MS;
    private static readonly DEFAULT_VAD_GRACE_MS;
    private static readonly VAD_START_DELAY_MS;
    private static readonly DEFAULT_INTERRUPT_FOLLOW_UP_WINDOW_MS;
    private static readonly CORE_INTERRUPT_WORDS;
    private isPlayingWelcomeTTS;
    private currentPlaybackContext;
    private allowFollowUpDuringPlayback;
    private gracefulExitFollowUpBuffer;
    private isPlayingInterruptFeedback;
    private isHandlingInterrupt;
    private lastInterruptTime;
    private static readonly DEFAULT_INTERRUPT_WORD_FILTER_MS;
    private isPlayingTTSLocked;
    private dataChannelEndTimer;
    private vadStartTimer;
    private webrtcReconnectAttempts;
    private webrtcReconnectTimer;
    private llmRetryCount;
    private _isReconnecting;
    private llmRequestCancelled;
    private _asrSuspended;
    private ttsEndTimestampForASRDiag;
    private static readonly DEFAULT_MAX_WEBRTC_RECONNECT_ATTEMPTS;
    private static readonly DEFAULT_WEBRTC_RECONNECT_INTERVAL;
    private static readonly DEFAULT_MAX_LLM_RETRY_COUNT;
    private static readonly DEFAULT_LLM_TIMEOUT_MS;
    private echoDetector;
    private ttsTimeline;
    private llmDataEnded;
    private ttsDataEnded;
    private a2fDataEnded;
    private webrtcAudioClockBound;
    private currentA2fStreamId;
    private lastA2fOffset;
    private a2fOffsetBase;
    private ttsPlaybackState;
    private activeTTSTransport;
    private llmTTSStreamPrepared;
    private static readonly DEFAULT_WAKE_WORDS;
    private static readonly DEFAULT_EXIT_WORDS;
    private static readonly DEFAULT_INTERRUPT_WORDS;
    private static readonly SUPPLEMENT_WORDS;
    private static readonly HARD_INTERRUPT_WORDS;
    private static readonly DEFAULT_IDLE_TIMEOUT;
    private static readonly DEFAULT_SILENCE_TIMEOUT;
    private static readonly DEFAULT_GRACEFUL_EXIT_PROMPT;
    private static readonly DEFAULT_GRACEFUL_EXIT_PHASE2_PROMPT;
    private static readonly DEFAULT_GRACEFUL_EXIT_PHASE2_SILENCE;
    private static readonly DEFAULT_GRACEFUL_EXIT_PHASE3_SILENCE;
    private exitPromptTimer;
    private isInPostExitIdle;
    private pendingPostExitIdleEmit;
    private gracefulExitGeneration;
    private gracefulExitPhase;
    private effectiveInterruptWords;
    private configuredInterruptWords;
    constructor(config: VoiceConversationConfig);
    private resolveEnableInterrupt;
    get state(): VoiceState;
    get config(): Readonly<InternalConfig>;
    get coreInterruptWords(): readonly string[];
    get isStarted(): boolean;
    get isReconnecting(): boolean;
    get conversationId(): string;
    start(): Promise<void>;
    stop(): Promise<void>;
    wake(): void;
    sleep(): void;
    suspendASR(): void;
    resumeASR(): void;
    private isGracefulExitPromptContext;
    private shouldCaptureGracefulExitFollowUp;
    private bufferGracefulExitFollowUp;
    private flushGracefulExitFollowUpBuffer;
    get isASRSuspended(): boolean;
    sendText(text: string): Promise<void>;
    playTTS(text: string, options?: {
        dialect?: string;
        synthetic?: boolean;
        playbackContext?: TTSPlaybackContext;
        allowFollowUpDuringPlayback?: boolean;
    }): Promise<void>;
    private transitionTo;
    private syncStateToGateway;
    private onEnterState;
    private handleASRResult;
    private processASRText;
    private clearTranscriptDisplay;
    private handleASRInSleeping;
    private _isSameUtterance;
    private _isWakeWordOnly;
    private handleASRInIdle;
    private handleASRInListening;
    private handleASRInThinking;
    private handleVoiceInterrupt;
    private playInterruptFeedback;
    private getBargeInThresholds;
    private shouldTriggerBargeIn;
    private handleBargeIn;
    private handleBargeInTransition;
    private classifyBargeIn;
    private sendToLLM;
    private sendToLLMWithRetry;
    private isRetryableError;
    private handleLLMResponse;
    private checkAllDataEnded;
    private resetDataEndedFlags;
    private registerEventListeners;
    private unregisterEventListeners;
    private handleGatewayStatePush;
    private getRandomTalkAnimation;
    private handleTTSPlayStart;
    private enableInterruptDetection;
    private handleVADDirectInterrupt;
    private openVadGate;
    private isVadGateOpen;
    private isVadRecent;
    private matchExplicitInterruptPhrase;
    private hasExplicitInterruptIntent;
    private hasWakeWordInterrupt;
    private clearInterruptTimers;
    private startInterruptFollowUpWindow;
    private clearInterruptFollowUpWindow;
    private handleTTSPlayEnd;
    private scheduleWelcomeASRResume;
    private clearWelcomeAsrResumeTimer;
    private handleAudioPlaybackStart;
    private handleAnimationEnd;
    private handleGatewayDisconnect;
    private handleGatewayReconnecting;
    private handleWebRTCStateChange;
    private attemptWebRTCReconnect;
    private clearWebRTCReconnectTimer;
    private _expandedWakeWords;
    private sendExpandedWakeWords;
    private handleSleep;
    private handleInterrupt;
    private shouldAllowShortFollowUp;
    private shouldUseWebRTCTTS;
    private bindActiveLLMRequest;
    private clearActiveLLMTimeout;
    private clearActiveLLMRequest;
    private resolveActiveLLMRequest;
    private cancelActiveLLMRequest;
    private startSilenceTimer;
    private clearSilenceTimer;
    private flushTextBuffer;
    private resetIdleTimer;
    private handleGracefulExitPhase1;
    private handleGracefulExitPhase2;
    private waitForGracefulExitPlayEnd;
    private clearIdleTimer;
    private generateRequestId;
    private emitError;
}
export default VoiceConversation;
//# sourceMappingURL=voice-conversation.d.ts.map