// A VIDEO'S WORD TIMINGS — `data//words.json` (release 36, lane A). // // The clip finder cuts on words: a clip's edges snap to the word the speaker // starts or finishes on, never to a caption line's wrap. Release 35 made them // by hand (`pnpm ops transcribe {path, words: true, out: /words.json}`) // into one umtool project. The find-clips job makes them ONCE per video, // here, beside the transcript they belong to, so every project cut from this // recording reads the same file (umtool copies it in as `/words.json`) // and the step is skipped the next time. // // THE SHAPE IS THE TRANSCRIBE RESULT'S (controller/transcribeFile.ts // TranscribeFileResult) without its cues and text — {version, path, window, // worker, transcriptFormat, transcribedAt, durationMs, waitedMs, words} — so a // release-35 words.json and this file read the same (umtool reads // `doc.words`, umtool/lib/report/reactions.mjs loadRecording). A file with no // words array reads as absent; one with an EMPTY array is never written (an // engine that keeps no word timestamps — the job says so and goes on). // // TEXT, not media: it stays in the real data// on the corpus disk and is // never tiered (lib/mediaTier.ts tiers by name; this name is not one). import { sidecar, sidecarField } from "./sidecar-server"; export const WORD_TIMINGS_FILENAME = "words.json"; export type TimedWord = { w: string; start: number; end: number; conf?: number }; export type WordTimingsRecord = { version: 1; // The file the engine read (the video's audio or saved container). path: string; window: { start: number; end: number | null } | null; worker: { id: string; name: string; appId: string; model: string | null; device: string | null }; transcriptFormat: string; transcribedAt: string; durationMs: number; waitedMs: number; words: TimedWord[]; }; function isWord(w: unknown): w is TimedWord { if (!w || typeof w !== "object") return false; const o = w as Record; return typeof o.w === "string" && typeof o.start === "number" && typeof o.end === "number"; } export function coerceWordTimings(value: unknown): WordTimingsRecord | null { if (!value || typeof value !== "object" || Array.isArray(value)) return null; const v = value as Record; if (!Array.isArray(v.words) || v.words.length === 0 || !v.words.every(isWord)) return null; return value as WordTimingsRecord; } export const wordTimingsSidecar = sidecar(WORD_TIMINGS_FILENAME, sidecarField(coerceWordTimings), { indent: 0, }); export const loadWordTimings = wordTimingsSidecar.load; export const writeWordTimings = wordTimingsSidecar.write;