import { AutoFinalizeEmitter, AutoFinalizeStreamMessage } from "./internal-base.mjs"; import { type WebSocketLike } from "../../../internal/ws-adapter.mjs"; import { type RawWebSocketData, type ReconnectingEvent, type ReconnectingOverrides } from "../../../internal/ws.mjs"; import * as STTAPI from "../stt.mjs"; import * as AutoFinalizeAPI from "./auto-finalize.mjs"; import { Cartesia } from "../../../client.mjs"; export interface AutoFinalizeWSParameters extends Record { /** * The encoding format for audio data sent to the STT WebSocket. */ encoding: STTAPI.STTEncoding; /** * Models that support realtime speech-to-text (auto finalize). This mode detects * when the user is speaking and emits turn events. See * [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for * all options. */ model: AutoFinalizeAPI.STTAutoFinalizeModel; /** * Sample rate in Hz. */ sample_rate: number; /** * Key terms to improve the recall of specific words and phrases. * * Pass multiple values to boost multiple terms, up to 100 keyterms totaling 1200 * characters. To boost one multi-word phrase, join the words with a space. * * See [Keyterm prompting](https://docs.cartesia.ai/use-the-api/stt/keyterms) for * details. */ keyterm?: Array; /** * Threshold below which to eager end the turn. Default: 0.4. Range: 0.3-0.6. Must * stay between the end and start thresholds. * * See * [Configuring turn detection](https://docs.cartesia.ai/use-the-api/stt/turns#configuring-turn-detection) * for details. */ turn_eager_end_threshold?: number; /** * Threshold below which to end the turn. Default: 0.2. Range: 0.05-0.5. Must stay * below the eager end threshold. * * See * [Configuring turn detection](https://docs.cartesia.ai/use-the-api/stt/turns#configuring-turn-detection) * for details. */ turn_end_threshold?: number; /** * Maximum amount of time in milliseconds that the model will wait after the user * stops speaking before ending the turn. Default: 5600. Range: 640-11200. * * See * [Configuring turn detection](https://docs.cartesia.ai/use-the-api/stt/turns#configuring-turn-detection) * for details. */ turn_end_timeout_ms?: number; /** * Threshold above which to start the turn. Default: 0.8. Range: 0.5-0.9. Must stay * above the eager end threshold. * * See * [Configuring turn detection](https://docs.cartesia.ai/use-the-api/stt/turns#configuring-turn-detection) * for details. */ turn_start_threshold?: number; } export interface AutoFinalizeWSReconnectOptions { /** * 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 AutoFinalizeWSBaseOptions { /** * Options for automatic reconnection on recoverable close codes. * Automatic reconnection is only enabled when this has a non-null value. */ reconnect?: AutoFinalizeWSReconnectOptions | 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 AutoFinalizeWSBase extends AutoFinalizeEmitter { url: URL; socket: TSocket; protected _client: Cartesia; protected _parameters: AutoFinalizeWSParameters | null | undefined; private _reconnectOptions; private _sendQueue; private _isReconnecting; private _intentionallyClosed; private _closeCode; private _closeReason; private _lastCloseCode; private _lastCloseReason; private _internalEvents; constructor(client: Cartesia, parameters: AutoFinalizeWSParameters, options?: AutoFinalizeWSBaseOptions | 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: AutoFinalizeAPI.STTAutoFinalizeWebsocketRequest): 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.mts.map