A dictation that audio is pushed into.

Returned by client.dictation.openLive(). The request starts the moment the session opens; write() hands it audio, close() ends the audio, and result() resolves with the transcript. Built for callback-driven sources: a microphone library, a WebRTC track, a telephony media stream, a websocket handler receiving frames. Sources that already are streams or async iterables, and audio held whole, go to client.dictation.transcribeLive() instead.

Everything transcribeLive() says about the 120 s audio cap, the server-side silence abort and errors surfacing mid-upload applies here unchanged.

const session = client.dictation.openLive({ sample_rate: 16000, channels: 1 });
mic.on("data", (chunk) => session.write(chunk));
mic.on("end", () => session.close());
const { final_text } = await session.result();

Hierarchy

Constructors

Accessors

Methods

Constructors

Accessors

  • get closed(): boolean
  • Whether the audio has ended, by close(), result() or abort().

    Returns boolean

Methods

  • Drop the request without a result. The connection is closed and nothing the server may still return is kept; result() rejects afterwards. Idempotent, and a no-op once the request has completed.

    Returns Promise<void>

    A promise that resolves once the request has been let go of.

  • End the audio. The server transcribes what was sent and result() resolves with it. Idempotent, and never blocks.

    Returns void

  • Wait for the result, ending the audio first if it is still open.

    Returns Promise<DictationResponse>

    A promise that resolves to the finished response.

    Error when the request failed — including a rejection the server sent while the upload was still in flight — or when the session was aborted.

  • A WritableStream that feeds this session, for piping a web stream of audio into it: source.pipeTo(session.stream()). Closing the writable closes the session; aborting it aborts the session.

    Returns WritableStream<Uint8Array>

    The writable end of the session.

  • Queue a piece of audio for upload. Never blocks, so it is safe to call from an audio library's capture callback.

    Once the audio has ended — by close(), result(), abort(), or the request settling on its own — a late write is dropped, not thrown. write() is meant to be called from a capture callback that the caller may not have stopped in lockstep with teardown, and throwing into that callback can take down the process; silently ignoring the trailing chunks is safer. A genuine type error is still surfaced at once, while the session is open.

    Parameters

    • chunk: ArrayBuffer | Uint8Array

      Audio bytes, in order: a Uint8Array, Buffer or ArrayBuffer.

    Returns void

    TypeError when chunk is not bytes and the session is still open.