Skip to content

API reference

@video-ultra/captions

Optional on-device auto-captions: speech to timed words in a worker, nothing uploaded.

npm install @video-ultra/captions

Functions

chooseModel

function

Picks the model and runtime for this device: base on WebAssembly, tiny where the device says it's short of memory. Under 4 GB of memory or 4 cores it isn't offered on the device (a host transcriber can still be used). Browser APIs are read here, never at import time (SSR safe).

function chooseModel(options?: Pick<OnDeviceTranscriberOptions, 'model' | 'device'>): Promise<DeviceSupport>;

An on-device Transcriber for English speech. The worker and model load on the first transcribe() call (call dispose() to free them).

function createOnDeviceTranscriber(options?: OnDeviceTranscriberOptions): Transcriber;

Types

Model sizes: tiny (fastest, least memory), base (more accurate).

type CaptionModel = 'tiny' | 'base';

What the device can run, and the setup used for it.

interface DeviceSupport {
  /** False on devices too small to caption well on their own (use a host transcriber there). */
  ok: boolean;
  device: 'webgpu' | 'wasm';
  model: CaptionModel;
  /** Approximate one-time download, in MB. */
  downloadMB: number;
  /** Roughly how fast it hears (× real time) on a typical laptop; phones are 2–4× slower. */
  speed: number;
  /** Why not, when `ok` is false. */
  reason?: string;
}
interface OnDeviceTranscriberOptions {
  /** Model size; default picks for the device (see {@link chooseModel}). */
  model?: CaptionModel | 'auto';
  /** Runtime; default WebAssembly (as fast as WebGPU for these models, and lighter). */
  device?: 'webgpu' | 'wasm' | 'auto';
  /**
   * Where model files come from — self-host them by mirroring the model repos: files are fetched
   * from `<modelHost>/onnx-community/whisper-<size>_timestamped/resolve/main/<file>`.
   * Default `https://huggingface.co`.
   */
  modelHost?: string;
  /** Where the speech runtime's `.wasm` files are served (default: next to its JS module). */
  runtimePath?: string;
  /**
   * Keep the model loaded between jobs (faster next time, holds ~0.3–1 GB). Default false: the
   * worker closes after each job and its memory goes back to the page; the downloaded files stay
   * cached, so the next job only waits a few seconds.
   */
  keepLoaded?: boolean;
}