/**
 * SpeechRTC — VolcEngine bidirectional TTS client with managed session reuse.
 *
 * https://www.volcengine.com/docs/6561/1329505?lang=zh
 *
 * Browser callers work with text streams rather than raw WebSocket lifecycle.
 * The SDK opens connections lazily, reuses pooled stream objects created via
 * createTextStream(), auto-finishes an idle session after 10 seconds by
 * default, and closes an underlying connection after 60 seconds of silence by
 * default. Repeated createTextStream() calls with matching voice/connection
 * settings will reuse an existing pooled stream instead of allocating a fresh
 * one, up to maxParallelSessions pooled streams per SpeechRTC instance.
 *
 * Example usage:
 * const speechRTC = new SpeechRTC(window.keepwork, {
 *   // appId and accessToken are optional when the proxy provides defaults.
 *   proxyUrl: 'wss://tts.keepwork.com/ws/tts/',
 *   voiceType: 'zh_female_tianmeiyueyue_moon_bigtts',
 * });
 *
 * const stream = speechRTC.createTextStream();
 * stream.on('audioChunk', ({ bytes }) => console.log('audio chunk', bytes?.byteLength));
 * stream.on('sentenceEnd', ({ text }) => console.log('sentence end', text));
 *
 * await stream.beginText('你好，欢迎使用 SpeechRTC。');
 * await stream.appendText('这一段会继续发送到同一个会话。');
 * const result = await stream.finish();
 *
 * // Or forward model output incrementally:
 * await speechRTC.synthesizeChunks(asyncChunkSource);
 */
declare const DEFAULT_WS_URL = "wss://openspeech.bytedance.com/api/v3/tts/bidirection";
declare const DEFAULT_PROXY_URL = "wss://speechrtc.keepwork.com/tts";
declare const DEFAULT_RESOURCE_ID = "volc.service_type.10029";
declare const DEFAULT_NAMESPACE = "BidirectionalTTS";
declare const DEFAULT_FORMAT = "pcm";
declare const DEFAULT_SAMPLE_RATE = 24000;
declare const DEFAULT_SPEAKER = "zh_female_tianmeiyueyue_moon_bigtts";
declare const EVENT: {
    NONE: number;
    START_CONNECTION: number;
    FINISH_CONNECTION: number;
    CONNECTION_STARTED: number;
    CONNECTION_FAILED: number;
    CONNECTION_FINISHED: number;
    START_SESSION: number;
    CANCEL_SESSION: number;
    FINISH_SESSION: number;
    SESSION_STARTED: number;
    SESSION_CANCELED: number;
    SESSION_FINISHED: number;
    SESSION_FAILED: number;
    USAGE_RESPONSE: number;
    TASK_REQUEST: number;
    UPDATE_CONFIG: number;
    AUDIO_MUTED: number;
    TTS_SENTENCE_START: number;
    TTS_SENTENCE_END: number;
    TTS_RESPONSE: number;
    TTS_ENDED: number;
    PODCAST_ROUND_START: number;
    PODCAST_ROUND_RESPONSE: number;
    PODCAST_ROUND_END: number;
    SOURCE_SUBTITLE_START: number;
    SOURCE_SUBTITLE_RESPONSE: number;
    SOURCE_SUBTITLE_END: number;
    TRANSLATION_SUBTITLE_START: number;
    TRANSLATION_SUBTITLE_RESPONSE: number;
    TRANSLATION_SUBTITLE_END: number;
};
declare const SESSION_STATE: {
    IDLE: string;
    CONNECTING: string;
    CONNECTED: string;
    STARTING: string;
    ACTIVE: string;
    FINISHING: string;
    FINISHED: string;
    CANCELED: string;
    CLOSED: string;
    FAILED: string;
};
declare const MESSAGE_TYPE: {
    INVALID: number;
    FULL_CLIENT_REQUEST: number;
    AUDIO_ONLY_REQUEST: number;
    FULL_SERVER_RESPONSE: number;
    AUDIO_ONLY_RESPONSE: number;
    FRONT_END_RESULT_RESPONSE: number;
    ERROR_INFORMATION: number;
};
declare const MESSAGE_FLAG: {
    NO_SEQUENCE: number;
    POSITIVE_SEQUENCE: number;
    LAST_NO_SEQUENCE: number;
    NEGATIVE_SEQUENCE: number;
    WITH_EVENT: number;
};
declare const VERSION_BITS: {
    VERSION_1: number;
};
declare const HEADER_SIZE_BITS: {
    HEADER_SIZE_4: number;
};
declare const SERIALIZATION: {
    RAW: number;
    JSON: number;
};
declare const COMPRESSION: {
    NONE: number;
    GZIP: number;
};
declare const CONNECTION_EVENTS: Set<number>;
declare const CONNECT_ID_EVENTS: Set<number>;
/** _waitForEvent 等待者 */
interface SpeechRTCWaiter {
    values: unknown[];
    resolve: (payload: unknown) => void;
    reject: (error: unknown) => void;
}
declare function randomId(prefix?: string, length?: number): string;
declare function clamp(value: unknown, min: number, max: number, fallback: number): number;
declare function ensureObject(value: unknown): Record<string, unknown>;
declare function mergeDeep(base: unknown, extra: unknown): Record<string, unknown>;
declare function concatUint8Arrays(chunks: Uint8Array[]): Uint8Array;
declare function shouldIncludeSessionId(eventCode: number): boolean;
declare function shouldIncludeConnectId(eventCode: number): boolean;
declare function inferResourceId(voiceType: unknown): string;
declare function pcm16ToFloat32(bytes: Uint8Array): Float32Array;
declare function isSessionTerminalState(state: unknown): boolean;
declare function positiveNumberOr(value: unknown, fallback: number): number;
declare function stableJson(value: unknown): string;
declare function iterateTextChunks(input: unknown): AsyncGenerator<string>;
declare const DEFAULT_SESSION_IDLE_TIMEOUT_MS = 10000;
declare const DEFAULT_CONNECTION_IDLE_TIMEOUT_MS = 60000;
declare const DEFAULT_CONNECTION_MAX_LIFETIME_MS: number;
declare class SpeechRTCTransport {
    speechRTC: Record<string, unknown>;
    sdk: unknown;
    ws: WebSocket | null;
    isConnected: boolean;
    connectId: string;
    _connectionPromise: Promise<unknown> | null;
    _waiters: Map<unknown, SpeechRTCWaiter[]>;
    _activeSession: Record<string, unknown> | null;
    _connectionOptions: Record<string, unknown> | null;
    _connectionSignature: string;
    _restartPending: boolean;
    _socketOpenedAt: number;
    _lastActivityAt: number;
    _connectionIdleTimer: ReturnType<typeof setTimeout> | null;
    baseOptions: Record<string, unknown>;
    [key: string]: unknown;
    constructor(speechRTC: Record<string, unknown>, options?: Record<string, unknown>);
    updateBaseOptions(options?: Record<string, unknown>): void;
    prepareSession(session: Record<string, unknown>): Promise<void>;
    releaseSession(session: Record<string, unknown>): void;
    /**
     * Fire-and-forget CANCEL_SESSION for a session that failed locally but may
     * still be alive on the Volcengine server. Silently ignored if the socket
     * is not open.
     */
    _tryCancelStaleSession(sessionId: string): void;
    sendEvent(eventCode: number, payload: unknown, sessionId?: string): Promise<void>;
    shutdown(options?: {
        graceful?: boolean;
        timeout?: number;
    }): Promise<void>;
    _applyConnectionOptions(options?: Record<string, unknown>): void;
    _shouldRestartConnection(): boolean;
    _ensureConnected(): Promise<WebSocket | null | unknown>;
    _createWebSocket(): unknown;
    _buildHandshakeHeaders(): Record<string, unknown>;
    _sendConnectionStart(): Promise<void>;
    _handleMessage(data: unknown): Promise<void>;
    _handleTransportFailure(error: unknown, source: string): void;
    _sendBinary(buffer: ArrayBufferLike | ArrayBufferView): void;
    _touchActivity(): void;
    _scheduleConnectionIdleTimer(): void;
    _clearConnectionIdleTimer(): void;
    _waitForEvent(eventCodes: unknown, timeout?: number): Promise<unknown>;
    _resolveWaiters(key: unknown, payload: unknown): void;
    _resolveAllWaiters(error: unknown): void;
    _removeWaiter(waiter: SpeechRTCWaiter, skipKey?: unknown): void;
    _createProtocolError(frame: Record<string, unknown>, message: string): Error;
    _closeSocket(options?: {
        preserveWaiters?: boolean;
    }): void;
}
export { SpeechRTCTransport, DEFAULT_WS_URL, DEFAULT_PROXY_URL, DEFAULT_RESOURCE_ID, DEFAULT_NAMESPACE, DEFAULT_FORMAT, DEFAULT_SAMPLE_RATE, DEFAULT_SPEAKER, DEFAULT_SESSION_IDLE_TIMEOUT_MS, DEFAULT_CONNECTION_IDLE_TIMEOUT_MS, DEFAULT_CONNECTION_MAX_LIFETIME_MS, EVENT, SESSION_STATE, MESSAGE_TYPE, MESSAGE_FLAG, VERSION_BITS, HEADER_SIZE_BITS, SERIALIZATION, COMPRESSION, CONNECTION_EVENTS, CONNECT_ID_EVENTS, randomId, clamp, ensureObject, mergeDeep, concatUint8Arrays, shouldIncludeSessionId, shouldIncludeConnectId, inferResourceId, positiveNumberOr, stableJson, pcm16ToFloat32, isSessionTerminalState, iterateTextChunks, };
//# sourceMappingURL=SpeechRTC.transport.d.ts.map