import { ManualFinalizeEmitter, ManualFinalizeStreamMessage } from "./internal-base.js"; import { type WebSocketLike } from "../../../internal/ws-adapter.js"; import { type RawWebSocketData, type ReconnectingEvent, type ReconnectingOverrides } from "../../../internal/ws.js"; import * as STTAPI from "../stt.js"; import * as ManualFinalizeAPI from "./manual-finalize.js"; import { Cartesia } from "../../../client.js"; export interface ManualFinalizeWSParameters extends Record { /** * The encoding format for audio data sent to the STT WebSocket. */ encoding: STTAPI.STTEncoding; /** * Models that support realtime speech-to-text (manual finalize). This mode expects * you to send the `finalize` command to trigger transcription. See * [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for * all options. */ model: ManualFinalizeAPI.STTManualFinalizeModel; /** * Sample rate in Hz. */ sample_rate: number; /** * The language of the input audio in ISO-639-1 format. Defaults to `en`. See * [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for * current language support. */ language?: 'en'; /** * Used by `ink-whisper` models only. Maximum duration of silence (in seconds) * before the API automatically finalizes the transcript. Lower values finalize * more aggressively; higher values allow longer pauses within utterances. */ max_silence_duration_secs?: number; /** * Used by `ink-whisper` models only. Controls what is considered silence for * automatic transcript finalization. Lower values pick up quiet audio; higher * values filter noisy audio more aggressively. */ min_volume?: number; } export interface ManualFinalizeWSReconnectOptions { /** * Called before each reconnect attempt. Return an object with * `parameters` to override query parameters for the next connection. */ onReconnecting(event: ReconnectingEvent): ReconnectingOverrides | void; /** * Maximum number of reconnection attempts. Default: 5. * Set to 0 to disable reconnection entirely. */ maxRetries?: number; /** * Initial backoff delay in milliseconds. Default: 500. */ initialDelay?: number; /** * Maximum backoff delay in milliseconds. Default: 8000. */ maxDelay?: number; } export interface ManualFinalizeWSBaseOptions { /** * Options for automatic reconnection on recoverable close codes. * Automatic reconnection is only enabled when this has a non-null value. */ reconnect?: ManualFinalizeWSReconnectOptions | null | undefined; /** * Maximum size of the outgoing message queue in bytes. * Messages queued while the socket is connecting or reconnecting are held * in memory up to this limit. Once the limit is reached, new messages are * discarded and an `error` event is emitted. * Default: 1 MB */ maxQueueSize?: number | undefined; } export declare abstract class ManualFinalizeWSBase extends ManualFinalizeEmitter { url: URL; socket: TSocket; protected _client: Cartesia; protected _parameters: ManualFinalizeWSParameters | null | undefined; private _reconnectOptions; private _sendQueue; private _isReconnecting; private _intentionallyClosed; private _closeCode; private _closeReason; private _lastCloseCode; private _lastCloseReason; private _internalEvents; constructor(client: Cartesia, parameters: ManualFinalizeWSParameters, options?: ManualFinalizeWSBaseOptions | undefined); /** Establishes the initial WebSocket connection. */ protected _connectInitial(): void; /** Creates a platform-specific WebSocket for the given URL and auth headers. */ protected abstract _createSocket(url: URL, authHeaders: Record): TSocket; send(event: ManualFinalizeAPI.STTManualFinalizeWebsocketRequest): void; sendRaw(data: RawWebSocketData): void; close(props?: { code: number; reason: string; }): void; /** * Returns an async iterator over WebSocket lifecycle and message events, * providing an alternative to the event-based `.on()` API. * The iterator will exit if the socket closes but exiting the iterator * does not close the socket. * * @example * ```ts * for await (const event of client.stream()) { * switch (event.type) { * case 'message': * console.log('received:', event.message); * break; * case 'error': * console.error(event.error); * break; * case 'close': * console.log('connection closed'); * break; * } * } * ``` */ stream(): AsyncIterableIterator; [Symbol.asyncIterator](): AsyncIterableIterator; private _connect; private _canReconnect; private _reconnect; /** * Resolves once the socket is open, rejects if it errors or closes first */ private _awaitOpen; private _flushSendQueue; /** * Emits the public `close` event with unsent messages and the internal * `close` event used by the async iterator. */ private _emitPermanentClose; protected _authHeaders(): Record; } //# sourceMappingURL=ws-base.d.ts.map