Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

897 B
Raw Blame
// A take heard: parakeet-mlx's tokens joined into words, the one place it's done. `raea cut` (native.ts) and the feed's
// host (apps/app/host/take.ts) both import it.

/** A word heard, in the take's own seconds */
export type Heard = { text: string; start: number; end: number };

/** Parakeet's tokens as words: a token starting with a space starts one, and so does a digit after a letter
 *  ("just" "2%" come as "just" + "2%" with no space). */
export function wordsOf(tokens: Heard[]): Heard[] {
  const out: Heard[] = [];
  for (const t of tokens) {
    const last = out[out.length - 1];
    const starts = t.text.startsWith(" ") || !last || (/^\d/.test(t.text) && /[a-z]$/i.test(last.text));
    if (starts) {
      if (t.text.trim()) out.push({ text: t.text.trim(), start: t.start, end: t.end });
    } else {
      last.text += t.text;
      last.end = t.end;
    }
  }
  return out;
}