Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

4.2 KB
Raw Blame
/** One word within a segment, in milliseconds from the start of the recording. */
export interface TranscriptWord {
  startMs: number;
  endMs: number;
  text: string;
}

/** One spoken stretch, in milliseconds from the start of the recording. */
export interface TranscriptSegment {
  startMs: number;
  endMs: number;
  text: string;
  /** Speaker label when `diarize` is enabled and the provider reports one. */
  speaker?: string;
  /**
   * Per-word times, when the engine reports them. Every word lies within the
   * segment's [startMs, endMs] and the words stay in order. Unset for engines
   * that give no word-level times.
   */
  words?: TranscriptWord[];
}

export type LocalModelId = "english-fast" | "multilingual";

export interface HostedProviderConfig {
  apiKey: string;
  model?: string;
  baseUrl?: string;
  language?: string;
}

export interface OpenAICompatibleConfig extends HostedProviderConfig {
  model: string;
  baseUrl: string;
}

/**
 * Where the transcript comes from. `local` runs a downloaded model on this
 * machine; every other kind sends the audio to that provider with the user's
 * own key.
 *
 * `baseUrl` on the hosted providers is optional and only needed for a
 * regional endpoint, a proxy or a test server.
 * `language` is the spoken language as a lowercase ISO 639-1 code. Omit it
 * to use the engine's usual language selection.
 */
export type TranscriptionConfig =
  | { kind: "none" }
  | { kind: "local"; model: LocalModelId; language?: string }
  | ({ kind: "openai-compatible" } & OpenAICompatibleConfig)
  | ({ kind: "deepgram" | "assemblyai" | "elevenlabs" | "gemini" | "revai" } & HostedProviderConfig);

export interface TranscriptGap {
  startMs: number;
  endMs: number;
  reason: string;
}

export interface TranscribeResult {
  segments: TranscriptSegment[];
  /** Which engine produced the segments, e.g. `local:english-fast` or `deepgram:nova-3`. */
  engine: string;
  /**
   * The requested language, or else the engine's reported one. Either way a
   * lowercase ISO 639-1 code (`"en"`, `"zh"`), or for a language that has
   * none, its ISO 639-3 code (`"yue"`). Every engine reports this one form,
   * whatever its provider returned (`"english"`, `"eng"`, `"en_us"`). Absent
   * when no language was requested and the engine reports none or one that
   * cannot be recognised.
   */
  language?: string;
  /** Stretches of the recording that have no transcript, and why. */
  gaps: TranscriptGap[];
}

/**
 * Which audio of a file to transcribe when it has more than one audio track
 * (a recording that keeps the microphone and the system sound apart): one
 * track by its index among the audio tracks, from 0, or "mix" for every
 * audio track mixed together.
 */
export type AudioTrack = number | "mix";

export interface TranscribeProgress {
  stage: "extract" | "download" | "transcribe";
  fraction: number;
}

export interface TranscribeOptions {
  signal?: AbortSignal;
  modelDir?: string;
  onProgress?: (p: TranscribeProgress) => void;
  /**
   * The audio track to transcribe, or "mix" for all of them. Unset, ffmpeg
   * picks one track by its own rule (the one with the most channels), which
   * can be a system-sound track rather than the speech.
   */
  audioTrack?: AudioTrack;
  /**
   * Number of CPU threads for on-device transcription (1 to `availableParallelism()`).
   * Defaults to `max(1, min(4, floor(availableParallelism() / 2)))`.
   */
  threads?: number;
  /**
   * Path of the sherpa-onnx-node entry file for on-device transcription. The
   * engine is not a dependency of this package: the host installs it (the CLI
   * downloads it on first use) and says where. When absent it is resolved from
   * this package's location.
   */
  speechEngine?: string;
  /**
   * Ask the provider for speaker labels on each segment (`TranscriptSegment.speaker`).
   * Off (`false`) by default.
   *
   * Supported only for whole-file providers with diarization (`deepgram`,
   * `assemblyai`, `revai`). Chunked engines (`local`, `openai-compatible`, `gemini`)
   * transcribe each piece independently, so speaker labels from different
   * pieces would not match across cuts; passing `diarize: true` with an
   * unsupported engine throws an error rather than returning mismatched IDs.
   */
  diarize?: boolean;
}