Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(transcript): the pane follows the voice across an insertion, and highlights the added word

EtienneLescotf4bdb25ab99c
diff --git a/electron/ai-edition/document-service.ts b/electron/ai-edition/document-service.ts
index 1199bee50..d3eaa01d3 100644
--- a/electron/ai-edition/document-service.ts
+++ b/electron/ai-edition/document-service.ts
@@ -13,10 +13,7 @@
import fs, { type FileHandle } from "node:fs/promises";
import path from "node:path";
import { createId } from "../../src/lib/ai-edition/document/ids";
-import {
- parseStoredDocument,
- reconcileClipsWithInserts,
-} from "../../src/lib/ai-edition/document/load";
+import { parseStoredDocument, reconcileInsertions } from "../../src/lib/ai-edition/document/load";
import { removeClip } from "../../src/lib/ai-edition/document/timeline";
import {
type AxcutAsset,
@@ -277,7 +274,7 @@ export class DocumentService {
// back, and it is not persisted from here: the renderer saves the document
// it was given, as it does for any other load-time repair.
const migrated = migrateRawDocumentToCurrent(JSON.parse(raw));
- return reconcileClipsWithInserts(
+ return reconcileInsertions(
documentSchema.parse(await relinkProjectMedia(migrated, this.mediaRegistryDir)),
);
}
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 385df2a3d..d34184954 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -1347,6 +1347,7 @@ export function NewEditorShell() {
isMac,
togglePlay,
handleSeek,
+ openVoiceoverFlow,
]);
const showTimeline = mode !== "rec";
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 6892bdda7..83927970d 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -913,8 +913,8 @@ export function TranscriptPane({
const placements = activeLane === "voiceover" ? voiceover : clips;
const sections = useMemo(
- () => buildAggregatedSections(placements, transcripts, assets, removed),
- [placements, transcripts, assets, removed],
+ () => buildAggregatedSections(placements, transcripts, assets, removed, insertRanges),
+ [placements, transcripts, assets, removed, insertRanges],
);
// `currentTimeSec` is the RAW/document timeline (same referential as the ruler, see
@@ -923,8 +923,8 @@ export function TranscriptPane({
// id is something only the recording lane has — so the voiceover lane never
// highlighted. Raw seconds are the coordinate both lanes share.
const cueWordId = useMemo(
- () => findCueWordId(sections, currentTimeSec),
- [sections, currentTimeSec],
+ () => findCueWordId(sections, currentTimeSec, insertRanges),
+ [sections, currentTimeSec, insertRanges],
);
const laneSwitch =
@@ -1035,6 +1035,7 @@ export function TranscriptPane({
undefined
}
cueWordId={cueWordId}
+ insertRanges={insertRanges}
onSeek={onSeek}
onTrimTimelineSpan={onTrimTimelineSpan}
onRemoveTrimRanges={onRemoveTrimRanges}
@@ -1066,6 +1067,7 @@ const TranscriptClipBlock = memo(function TranscriptClipBlock({
busyLabel,
lane,
cueWordId,
+ insertRanges,
onSeek,
onTrimTimelineSpan,
onRemoveTrimRanges,
@@ -1081,6 +1083,10 @@ const TranscriptClipBlock = memo(function TranscriptClipBlock({
* CLIP frame, and a voiceover placement has no clip to hold. */
lane: TranscriptLane;
cueWordId: string | null;
+ /** The insertions this placement carries: the block maps its words' SOURCE spans onto
+ * the ruler to author a cut, and a clip carrying insertions is longer than its source
+ * window (issue #560). */
+ insertRanges: readonly AxcutInsertRange[];
onSeek: (sec: number) => void;
onTrimTimelineSpan: (startSec: number, endSec: number, reason: string) => void;
onRemoveTrimRanges: (trimIds: string[]) => void;
@@ -1100,13 +1106,14 @@ const TranscriptClipBlock = memo(function TranscriptClipBlock({
// to do with the word the user deleted.
const toRawSpan = useCallback(
(startSec: number, endSec: number): [number, number] => {
- const extent = placementRawExtent(clip);
+ const extent = placementRawExtent(clip, insertRanges);
const lo = extent?.startSec ?? clip.timelineStartSec;
const hi = extent?.endSec ?? Number.POSITIVE_INFINITY;
- const clamp = (sec: number) => Math.min(Math.max(placementRawSec(clip, sec), lo), hi);
+ const clamp = (sec: number) =>
+ Math.min(Math.max(placementRawSec(clip, sec, insertRanges), lo), hi);
return [clamp(startSec), clamp(endSec)];
},
- [clip],
+ [clip, insertRanges],
);
const filename = asset?.label ?? clip.assetId;
const sourceRangeLabel =
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index cefbc3082..143051b85 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -631,7 +631,7 @@ export function VirtualPreview({
pieces.set(groupId, takeProgramme(pill, removed, takeInsertsByGroup(groupId)));
}
return { pieces, heads };
- }, [audioTracks, clips, trimRanges, takeInsertsByGroup]);
+ }, [audioTracks, clips, trimRanges, takeInsertsByGroup, insertRanges]);
takePiecesRef.current = takeWalks.pieces;
takeHeadsRef.current = takeWalks.heads;
// Trim-narrowed (`resolvePlaybackSegments`) — used ONLY to detect "has the <video>'s own
@@ -1238,7 +1238,7 @@ export function VirtualPreview({
});
}
},
- [applySourceTime, clips, videoSources, sourceIndex, updateVirtualTime],
+ [applySourceTime, clips, videoSources, sourceIndex, updateVirtualTime, insertRanges],
);
const seekToSourceTime = useCallback(
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index b4db553ec..21e8ce26c 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -699,7 +699,7 @@ export function V4Timeline({
1,
clips.reduce((m, c) => Math.max(m, c.timelineEndSec), 0),
),
- [clips, inserts],
+ [clips],
);
const pctOf = useCallback((sec: number) => (sec / total) * 100, [total]);
const showLanes = variant === "edit";
@@ -873,7 +873,7 @@ export function V4Timeline({
});
}
},
- [setCurrentTime, total, inserts],
+ [setCurrentTime, total],
);
// Mousedown anywhere on the empty timeline (ruler, lanes background, or
diff --git a/src/lib/ai-edition/captions/captionLane.test.ts b/src/lib/ai-edition/captions/captionLane.test.ts
index 776578709..016f95f18 100644
--- a/src/lib/ai-edition/captions/captionLane.test.ts
+++ b/src/lib/ai-edition/captions/captionLane.test.ts
@@ -150,7 +150,6 @@ describe("captionLane", () => {
const paused = doc({
timeline: {
...doc().timeline,
- // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
insertRanges: [
{
id: "i1",
@@ -161,6 +160,7 @@ describe("captionLane", () => {
reason: "",
origin: "user",
},
+ // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
] as any,
},
});
diff --git a/src/lib/ai-edition/captions/captions.test.ts b/src/lib/ai-edition/captions/captions.test.ts
index 8599bdb55..9b0485479 100644
--- a/src/lib/ai-edition/captions/captions.test.ts
+++ b/src/lib/ai-edition/captions/captions.test.ts
@@ -710,15 +710,16 @@ describe("captions and a pause", () => {
describe("a caption line never mixes recorded words with added ones", () => {
function docWithAddedWord(): AxcutDocument {
const t = transcript();
- // "really" typed in after "friend", which ends at source 2. It fits in 0.2s of the
- // silence that is already there and buys 1.8s of inserted media for the rest.
+ // "really" typed in after "friend", which ends at source 2. An added word takes up NO
+ // source time — the seconds it is spoken in are the insertion it buys, which is how
+ // the real documents store it — so its span is degenerate at the moment it follows.
t.words = [
...t.words.slice(0, 3),
{
id: "synth_1",
segmentId: "seg_1",
startSec: 2,
- endSec: 2.2,
+ endSec: 2,
text: "really",
source: "synth",
// biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
@@ -731,14 +732,13 @@ describe("a caption line never mixes recorded words with added ones", () => {
transcripts: [t],
timeline: {
...base.timeline,
- clips: [{ ...base.timeline.clips[0], timelineEndSec: 11.8 }],
- // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
+ clips: [{ ...base.timeline.clips[0], timelineEndSec: 12 }],
insertRanges: [
{
id: "i1",
assetId: "asset-1",
- atSec: 2.2,
- durationSec: 1.8,
+ atSec: 2,
+ durationSec: 2,
wordId: "synth_1",
reason: "",
origin: "user",
@@ -761,6 +761,26 @@ describe("a caption line never mixes recorded words with added ones", () => {
expect(added[0].startMs).toBeGreaterThanOrEqual(2000);
});
+ it("lays the three lines out end to end across the insertion", () => {
+ // The whole rule in one assertion set: the recorded line stops where the added one
+ // begins, the added one spans the media it bought, and what follows is pushed along
+ // by exactly that length.
+ const cues = deriveCaptionCues(docWithAddedWord(), settings, {});
+ const recorded = cues.find((c) => c.text.toLowerCase().includes("hello"));
+ const added = cues.find((c) => c.text.includes("really"));
+ const after = cues.find((c) => c.text.includes("goodbye"));
+ expect(recorded).toBeDefined();
+ expect(added).toBeDefined();
+ expect(after).toBeDefined();
+ // The insertion opens at ruler 2000 and runs 2000ms. Three consecutive facts:
+ // the recorded line STOPS there, the added line COVERS it, and what follows is
+ // pushed along by exactly its length.
+ expect(recorded?.endMs).toBe(2000);
+ expect(added?.startMs).toBe(2000);
+ expect(added?.endMs).toBeGreaterThan(3900);
+ expect(after?.startMs).toBe(6000);
+ });
+
it("leaves the recorded line ending before the added one begins", () => {
const cues = deriveCaptionCues(docWithAddedWord(), settings, {});
const recorded = cues.find((c) => c.text.toLowerCase().includes("hello"));
diff --git a/src/lib/ai-edition/captions/cues.ts b/src/lib/ai-edition/captions/cues.ts
index 3eeaf08e8..9176faa84 100644
--- a/src/lib/ai-edition/captions/cues.ts
+++ b/src/lib/ai-edition/captions/cues.ts
@@ -128,6 +128,19 @@ export function captionLinesForAsset(
);
}
+function overlapsAdded(
+ word: CaptionSegment,
+ added: Array<{ startSec: number; endSec: number }>,
+): boolean {
+ return added.some(
+ (span) =>
+ (word.startSec < span.endSec && word.endSec > span.startSec) ||
+ // An added word's source span is DEGENERATE — the seconds it is spoken in are the
+ // insertion, not the recording — so a strict overlap never matches it.
+ (word.startSec >= span.startSec && word.endSec <= span.endSec),
+ );
+}
+
/** Where the transcript's ADDED words sit, in source time. */
function addedWordSpans(transcript: AxcutTranscript): Array<{ startSec: number; endSec: number }> {
return transcript.words
@@ -148,8 +161,7 @@ function captionRuns(
added: Array<{ startSec: number; endSec: number }>,
): CaptionSegment[][] {
if (added.length === 0) return [stream];
- const isAdded = (word: CaptionSegment) =>
- added.some((span) => word.startSec < span.endSec && word.endSec > span.startSec);
+ const isAdded = (word: CaptionSegment) => overlapsAdded(word, added);
const runs: CaptionSegment[][] = [];
let current: CaptionSegment[] = [];
let currentIsAdded: boolean | null = null;
@@ -220,11 +232,13 @@ export function sourceSpanToTimelineSpans(
const s = Math.max(startSec, clip.sourceStartSec);
const e = Math.min(endSec, clipSourceEnd);
if (e <= s) continue;
- // `"closes"` on the end: a line running up to an added word covers the media that
- // word inserted, so it stays on screen through it instead of going dark over the
- // one moment the word exists for.
out.push({
startSec: sourceToTimelineSec(clip, s, inserts, "opens"),
+ // `"closes"` on the end, unconditionally. For an ADDED line that is what gives it
+ // the width of the media it bought — its source span is degenerate. For a RECORDED
+ // line the two edges agree: `finalizeCaptionSegmentsForPlayback` has already
+ // trimmed its end back to just before the next line begins, which is the added
+ // word's own moment, so there is no insertion at or past it to count.
endSec: sourceToTimelineSec(clip, e, inserts, "closes"),
});
}
diff --git a/src/lib/ai-edition/document/load.test.ts b/src/lib/ai-edition/document/load.test.ts
index 589d49ca0..e6f8b3b2f 100644
--- a/src/lib/ai-edition/document/load.test.ts
+++ b/src/lib/ai-edition/document/load.test.ts
@@ -8,7 +8,7 @@
import { describe, expect, it } from "vitest";
import type { AxcutClip, AxcutDocument, AxcutInsertRange } from "../schema";
-import { reconcileClipsWithInserts } from "./load";
+import { reconcileClipsWithInserts, reconcileInsertions } from "./load";
function clip(over: Partial<AxcutClip> & { id: string }): AxcutClip {
return {
@@ -85,3 +85,54 @@ describe("reconcileClipsWithInserts", () => {
expect(second.timelineEndSec - second.timelineStartSec).toBeCloseTo(10, 6);
});
});
+
+// ─── An added word nobody marked ────────────────────────────────────────────
+// `source: "synth"` is how the whole pipeline recognises a word the user typed: it decides
+// whether the word gets an insertion, whether the film makes room for it, and whether the
+// caption line breaks around it. A row minted before that field existed answers no to all
+// three — its text plays over the recording and everything after it drifts. Found in the
+// live project: `synth_1`, zero-width at source 9.15, with no insertion at all (issue #560).
+
+describe("reconcileInsertions", () => {
+ function docWithUnmarkedWord(): AxcutDocument {
+ return {
+ assets: [{ id: "a1", kind: "video" }],
+ transcripts: [
+ {
+ assetId: "a1",
+ language: "en",
+ segments: [{ id: "s1", kind: "speech", startSec: 0, endSec: 6, text: "x", wordIds: [] }],
+ words: [
+ { id: "w1", segmentId: "s1", startSec: 0, endSec: 1, text: "hello" },
+ // Minted as an added word — the id says so — but never marked.
+ { id: "synth_1", segmentId: "s1", startSec: 1, endSec: 1, text: "a much longer thing" },
+ ],
+ },
+ ],
+ timeline: { clips: [clip({ id: "c1" })], insertRanges: [] },
+ } as unknown as AxcutDocument;
+ }
+
+ it("marks it, gives it an insertion, and makes room for it", () => {
+ const out = reconcileInsertions(docWithUnmarkedWord());
+ const word = out.transcripts[0].words.find((w) => w.id === "synth_1");
+ expect(word?.source).toBe("synth");
+ const range = out.timeline.insertRanges?.find((r) => r.wordId === "synth_1");
+ expect(range).toBeDefined();
+ expect(range?.durationSec ?? 0).toBeGreaterThan(0);
+ const [c] = out.timeline.clips;
+ expect(c.timelineEndSec - c.timelineStartSec).toBeCloseTo(10 + (range?.durationSec ?? 0), 6);
+ });
+
+ it("leaves a word that was never added alone", () => {
+ const out = reconcileInsertions(docWithUnmarkedWord());
+ expect(out.transcripts[0].words.find((w) => w.id === "w1")?.source).toBeUndefined();
+ });
+
+ it("is idempotent", () => {
+ const once = reconcileInsertions(docWithUnmarkedWord());
+ const twice = reconcileInsertions(once);
+ expect(twice.timeline.clips).toEqual(once.timeline.clips);
+ expect(twice.timeline.insertRanges).toEqual(once.timeline.insertRanges);
+ });
+});
diff --git a/src/lib/ai-edition/document/load.ts b/src/lib/ai-edition/document/load.ts
index e4a4b3087..a71b81e95 100644
--- a/src/lib/ai-edition/document/load.ts
+++ b/src/lib/ai-edition/document/load.ts
@@ -22,6 +22,20 @@
import type { AxcutDocument } from "../schema";
import { documentSchema, migrateRawDocumentToCurrent } from "../schema";
import { reflowClipsForInserts } from "./timeline";
+import { withInsertRangesForAllWords, withMarkedAddedWords } from "./transcript";
+
+/**
+ * The whole insertion invariant, in dependency order.
+ *
+ * A word is ADDED, an added word has an INSERTION, and a clip carrying insertions is
+ * LONGER. Each step feeds the next, and reconciling only the last one left a document
+ * carrying an unmarked added word looking perfectly consistent while playing its text over
+ * the recording. Every step is idempotent, so this runs on every load and changes nothing
+ * for a document already in step.
+ */
+export function reconcileInsertions(document: AxcutDocument): AxcutDocument {
+ return reconcileClipsWithInserts(withInsertRangesForAllWords(withMarkedAddedWords(document)));
+}
/** Clip geometry brought back in line with the document's insert ranges. Idempotent. */
export function reconcileClipsWithInserts(document: AxcutDocument): AxcutDocument {
@@ -42,5 +56,5 @@ export function reconcileClipsWithInserts(document: AxcutDocument): AxcutDocumen
/** Raw JSON (any stored version) → a validated, reconciled document. */
export function parseStoredDocument(raw: unknown): AxcutDocument {
- return reconcileClipsWithInserts(documentSchema.parse(migrateRawDocumentToCurrent(raw)));
+ return reconcileInsertions(documentSchema.parse(migrateRawDocumentToCurrent(raw)));
}
diff --git a/src/lib/ai-edition/document/transcript.ts b/src/lib/ai-edition/document/transcript.ts
index 8d9c49487..82df1928d 100644
--- a/src/lib/ai-edition/document/transcript.ts
+++ b/src/lib/ai-edition/document/transcript.ts
@@ -332,6 +332,49 @@ const MIN_PAUSE_SEC = 0.05;
* so no caller has to remember any of the three. `insertRangesMatchWords` is the same rule
* read back, for a test to hold this to.
*/
+/** `synth_N` — the id every added word has been minted with, and the one thing a row
+ * written before the `source` field carries to say what it is. */
+const SYNTH_WORD_ID = /^synth_\d+$/;
+
+/**
+ * Added words that never got marked as such, marked.
+ *
+ * `source: "synth"` is how the whole pipeline recognises a word the user typed: it decides
+ * whether the word gets an insertion, whether the film makes room for it, and whether the
+ * caption line breaks around it. A row minted before that field existed answers no to all
+ * three, so its text plays over the recording and everything after it drifts. The id is the
+ * evidence — `nextSynthWordId` has always minted exactly this shape, and the numbering scan
+ * already reads it back with the same pattern.
+ */
+export function withMarkedAddedWords(document: AxcutDocument): AxcutDocument {
+ let touched = false;
+ const transcripts = document.transcripts.map((transcript) => {
+ let changed = false;
+ const words = transcript.words.map((word) => {
+ if (word.source !== undefined || !SYNTH_WORD_ID.test(word.id)) return word;
+ changed = true;
+ return { ...word, source: "synth" as const };
+ });
+ if (!changed) return transcript;
+ touched = true;
+ return { ...transcript, words };
+ });
+ return touched ? { ...document, transcripts } : document;
+}
+
+/**
+ * Every asset's insert ranges brought back in line with its words.
+ *
+ * The per-asset reconciler applied to the whole document, so a load can enforce the
+ * invariant it maintains rather than waiting for the next word write to notice.
+ */
+export function withInsertRangesForAllWords(document: AxcutDocument): AxcutDocument {
+ return document.transcripts.reduce(
+ (doc, transcript) => withInsertRangesForWords(doc, transcript.assetId),
+ document,
+ );
+}
+
function withInsertRangesForWords(document: AxcutDocument, assetId: string): AxcutDocument {
// The reason is user-visible on the region, and it is not the same fact on both lanes:
// the film holds a FRAME, a take holds nothing but silence — no picture is involved
diff --git a/src/lib/ai-edition/store/projectStore.ts b/src/lib/ai-edition/store/projectStore.ts
index cee4be4ad..4af906cd4 100644
--- a/src/lib/ai-edition/store/projectStore.ts
+++ b/src/lib/ai-edition/store/projectStore.ts
@@ -5,7 +5,7 @@ import { toastText } from "@/i18n/toastText";
import { nativeBridgeClient } from "@/native/client";
import { placeAudioTrackInDocument } from "../document/audioTracks";
import { createId } from "../document/ids";
-import { reconcileClipsWithInserts } from "../document/load";
+import { reconcileInsertions } from "../document/load";
import { type Interval, replaceTimeline as replaceTimelineOp } from "../document/timeline";
import { type AxcutAsset, type AxcutDocument, createAudioTrack, documentSchema } from "../schema";
import { probeAudioDuration, probeVideoDimensions } from "../timeline/duration";
@@ -162,7 +162,7 @@ function parseDocument(value: unknown): AxcutDocument {
// Reconciled here too, not only in the main process: this is the renderer's own gate on
// every document it accepts, and it is idempotent, so a document that arrived correct
// passes through untouched.
- return reconcileClipsWithInserts(documentSchema.parse(value));
+ return reconcileInsertions(documentSchema.parse(value));
}
/**
diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts
index 08d63460d..d4aa314e5 100644
--- a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts
+++ b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts
@@ -143,6 +143,7 @@ describe("lanePlacements", () => {
[transcript as any],
[],
[],
+ [],
);
expect(sections).toHaveLength(1);
expect(sections[0].words.filter((w) => !w.word.id.startsWith("silence_"))).toHaveLength(2);
@@ -224,6 +225,7 @@ describe("one programme, two lanes", () => {
transcripts as any,
[],
removed,
+ [],
);
return { recording: build("recording"), voiceover: build("voiceover") };
}
@@ -263,6 +265,7 @@ describe("one programme, two lanes", () => {
[secondsTranscript("asset_vo", 14)] as any,
[],
removed,
+ [],
);
const w6 = sections.flatMap((s) => s.words).find((w) => w.word.id === "w6"); // raw 6..7
expect(w6?.kept).toBe(false);
@@ -281,6 +284,7 @@ describe("one programme, two lanes", () => {
[secondsTranscript("asset_vo", 20)] as any,
[],
removedRawSpans(CLIPS_2, [], []),
+ [],
);
const w15 = sections.flatMap((s) => s.words).find((w) => w.word.id === "w15");
expect(w15?.kept).toBe(true);
@@ -290,14 +294,14 @@ describe("one programme, two lanes", () => {
// The cue used to be resolved into a clip id, which only the recording lane has —
// so this returned null for every moment of every voiceover.
const { voiceover } = lanes([]);
- expect(findCueWordId(voiceover, 4.5)).toBe("vo_1:w4");
- expect(findCueWordId(voiceover, 0.5)).toBe("vo_1:w0");
+ expect(findCueWordId(voiceover, 4.5, [])).toBe("vo_1:w4");
+ expect(findCueWordId(voiceover, 0.5, [])).toBe("vo_1:w0");
});
it("reads a word's raw moment through its own placement", () => {
// A take starting 3s along the ruler, 5s into its file: its source 6 is raw 4.
const placement = { id: "p", assetId: "a", sourceStartSec: 5, timelineStartSec: 3 };
- expect(placementRawSec(placement, 6)).toBe(4);
+ expect(placementRawSec(placement, 6, [])).toBe(4);
});
it("contributes no placement for a looping take", () => {
@@ -338,25 +342,26 @@ describe("the karaoke highlight after a pause", () => {
[WORDS as any],
[],
[],
+ [],
);
it("tracks the voice with no insertion", () => {
- expect(findCueWordId(sectionsWith([]), 4.5)).toBe("vo:w4");
+ expect(findCueWordId(sectionsWith([]), 4.5, [])).toBe("vo:w4");
});
it("follows the word D later once a pause has pushed it there", () => {
// A one-second pause at source 3: source 4 is now heard at ruler 5.
const inserts = [{ id: "i1", wordId: "w3", atSourceSec: 3, durationSec: 1 }];
const sections = sectionsWith(inserts);
- expect(findCueWordId(sections, 5.5)).toBe("vo#1:w4");
+ expect(findCueWordId(sections, 5.5, [])).toBe("vo#1:w4");
// And it is NOT still answering with the pre-pause mapping.
- expect(findCueWordId(sections, 4.5)).not.toBe("vo:w4");
+ expect(findCueWordId(sections, 4.5, [])).not.toBe("vo:w4");
});
it("highlights nothing while the voice is parked", () => {
// No word is being said during the pause, so the karaoke goes quiet rather than
// leaving a word lit that has already been spoken.
const inserts = [{ id: "i1", wordId: "w3", atSourceSec: 3, durationSec: 1 }];
- expect(findCueWordId(sectionsWith(inserts), 3.5)).toBeNull();
+ expect(findCueWordId(sectionsWith(inserts), 3.5, [])).toBeNull();
});
});
diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.test.ts b/src/lib/ai-edition/timeline/aggregated-transcript.test.ts
index 987b5a3a5..085435091 100644
--- a/src/lib/ai-edition/timeline/aggregated-transcript.test.ts
+++ b/src/lib/ai-edition/timeline/aggregated-transcript.test.ts
@@ -63,7 +63,7 @@ describe("buildClipSection", () => {
{ id: "w3", segmentId: "s1", startSec: 2, endSec: 3, text: "friend" },
]);
- const section = buildClipSection(clip, transcript, makeAsset(), []);
+ const section = buildClipSection(clip, transcript, makeAsset(), [], []);
expect(section.words.map((cw) => cw.kept)).toEqual([true, true, true]);
expect(section.trimRuns).toEqual([]);
});
@@ -84,6 +84,7 @@ describe("buildClipSection", () => {
transcript,
makeAsset(),
removedRawSpans([clip], [trim], []),
+ [],
);
expect(section.words.map((cw) => cw.kept)).toEqual([true, false, false, false, true]);
expect(section.words.map((cw) => cw.trimIds)).toEqual([
@@ -122,6 +123,7 @@ describe("buildClipSection", () => {
transcript,
makeAsset(),
removedRawSpans([clip], trims, []),
+ [],
);
expect(section.trimRuns).toHaveLength(2);
expect(section.trimRuns[0]).toMatchObject({
@@ -163,6 +165,7 @@ describe("buildClipSection", () => {
[makeTranscript(words())],
[makeAsset()],
removedRawSpans(clips, [trim], []),
+ [],
);
expect(sections[0].words.map((cw) => cw.kept)).toEqual([true, true, true]);
@@ -182,6 +185,7 @@ describe("buildClipSection", () => {
[makeTranscript(words())],
[makeAsset()],
removedRawSpans(clips, [trim], []),
+ [],
);
expect(sections[0].trimRuns).toHaveLength(1);
expect(sections[1].trimRuns).toHaveLength(1);
@@ -201,6 +205,7 @@ describe("buildClipSection", () => {
transcript,
makeAsset(),
removedRawSpans([clip], [trim], []),
+ [],
);
// Trailing gap 2s→3s is a silence — the different-asset trim doesn't
// cover any of the three entries, so all stay kept.
@@ -215,7 +220,7 @@ describe("buildClipSection", () => {
{ id: "w3", segmentId: "s1", startSec: 2, endSec: 3, text: "Um," },
]);
- const section = buildClipSection(clip, transcript, makeAsset(), []);
+ const section = buildClipSection(clip, transcript, makeAsset(), [], []);
// ponytail: the LLM (not the renderer) decides what is a filler. Every
// word renders as plain text in the right pane.
expect(section.words.map((cw) => cw.kept)).toEqual([true, true, true]);
@@ -224,7 +229,7 @@ describe("buildClipSection", () => {
it("returns an empty words list when the clip has no matching transcript", () => {
const clip = makeClip({ sourceStartSec: 0, sourceEndSec: 5 });
- const section = buildClipSection(clip, null, makeAsset(), []);
+ const section = buildClipSection(clip, null, makeAsset(), [], []);
expect(section.words).toEqual([]);
expect(section.trimRuns).toEqual([]);
@@ -239,7 +244,7 @@ describe("buildClipSection", () => {
{ id: "w_after", segmentId: "s1", startSec: 5, endSec: 6, text: "trim" },
]);
- const section = buildClipSection(clip, transcript, makeAsset(), []);
+ const section = buildClipSection(clip, transcript, makeAsset(), [], []);
// Leading (2s→2.5s) and trailing (3.5s→4s) gaps are both silences.
expect(section.words.map((cw) => cw.word.id)).toEqual(["silence_1", "w_mid", "silence_2"]);
});
@@ -253,7 +258,7 @@ describe("silence gaps", () => {
{ id: "w2", segmentId: "s1", startSec: 1.3, endSec: 2, text: "there" },
]);
- const section = buildClipSection(clip, transcript, makeAsset(), []);
+ const section = buildClipSection(clip, transcript, makeAsset(), [], []);
const ids = section.words.map((cw) => cw.word.id);
expect(ids).toEqual(["w1", "silence_1", "w2", "silence_2"]);
expect(section.words.filter((cw) => isSilenceWord(cw.word))).toHaveLength(2);
@@ -267,7 +272,7 @@ describe("silence gaps", () => {
{ id: "w2", segmentId: "s1", startSec: 1.1, endSec: 2, text: "there" },
]);
- const section = buildClipSection(clip, transcript, makeAsset(), []);
+ const section = buildClipSection(clip, transcript, makeAsset(), [], []);
expect(section.words.map((cw) => cw.word.id)).toEqual(["w1", "w2"]);
});
@@ -284,6 +289,7 @@ describe("silence gaps", () => {
transcript,
makeAsset(),
removedRawSpans([clip], [trim], []),
+ [],
);
const silence = section.words.find((cw) => isSilenceWord(cw.word));
expect(silence?.kept).toBe(false);
@@ -324,7 +330,7 @@ describe("buildAggregatedSections", () => {
makeAsset({ id: "asset_2", label: "second.mp4" }),
];
- const sections = buildAggregatedSections(clips, transcripts, assets, []);
+ const sections = buildAggregatedSections(clips, transcripts, assets, [], []);
expect(sections).toHaveLength(2);
expect(sections[0]?.clip.id).toBe("c1");
expect(sections[1]?.clip.id).toBe("c2");
@@ -337,7 +343,7 @@ describe("buildAggregatedSections", () => {
const transcripts = [makeTranscript([])];
const assets = [makeAsset(), makeAsset({ id: "asset_2" })];
- const sections = buildAggregatedSections(clips, transcripts, assets, []);
+ const sections = buildAggregatedSections(clips, transcripts, assets, [], []);
expect(sections).toHaveLength(2);
expect(sections[0]?.transcript).toBeTruthy();
expect(sections[1]?.transcript).toBeNull();
@@ -381,7 +387,7 @@ describe("findCueWordId", () => {
it("returns null when there is no playhead", () => {
const section = makeSection("c1", "asset_1", [["w1", 0, 1]]);
- expect(findCueWordId([section], null)).toBeNull();
+ expect(findCueWordId([section], null, [])).toBeNull();
});
it("returns null when the head is before every section", () => {
@@ -389,7 +395,7 @@ describe("findCueWordId", () => {
timelineStartSec: 10,
timelineEndSec: 110,
});
- expect(findCueWordId([section], 2)).toBeNull();
+ expect(findCueWordId([section], 2, [])).toBeNull();
});
it("returns the word containing the head", () => {
@@ -398,7 +404,7 @@ describe("findCueWordId", () => {
["w2", 1, 2],
["w3", 2, 3],
]);
- expect(findCueWordId([section], 1.5)).toBe("c1:w2");
+ expect(findCueWordId([section], 1.5, [])).toBe("c1:w2");
});
it("returns the previous word when the head is between two words", () => {
@@ -406,7 +412,7 @@ describe("findCueWordId", () => {
["w1", 0, 1],
["w2", 2, 3],
]);
- expect(findCueWordId([section], 1.5)).toBe("c1:w1");
+ expect(findCueWordId([section], 1.5, [])).toBe("c1:w1");
});
it("returns null when the head is before the first word", () => {
@@ -414,7 +420,7 @@ describe("findCueWordId", () => {
["w1", 5, 6],
["w2", 7, 8],
]);
- expect(findCueWordId([section], 0.5)).toBeNull();
+ expect(findCueWordId([section], 0.5, [])).toBeNull();
});
it("returns the last word when the head is past the last word", () => {
@@ -422,7 +428,7 @@ describe("findCueWordId", () => {
["w1", 0, 1],
["w2", 1, 2],
]);
- expect(findCueWordId([section], 99)).toBe("c1:w2");
+ expect(findCueWordId([section], 99, [])).toBe("c1:w2");
});
it("reads the head through the section's own source clock", () => {
@@ -433,8 +439,8 @@ describe("findCueWordId", () => {
timelineStartSec: 20,
timelineEndSec: 30,
});
- expect(findCueWordId([section], 22)).toBe("c1:w1");
- expect(findCueWordId([section], 2)).toBeNull();
+ expect(findCueWordId([section], 22, [])).toBe("c1:w1");
+ expect(findCueWordId([section], 2, [])).toBeNull();
});
// Two clips over the same media project the SAME transcript words twice, so the cue
@@ -463,12 +469,12 @@ describe("findCueWordId", () => {
it("resolves the head against the clip that is playing", () => {
// Source 1.5 in both, but raw 4.5 is only inside c2.
- expect(findCueWordId(sections(), 4.5)).toBe("c2:w2");
- expect(findCueWordId(sections(), 1.5)).toBe("c1:w2");
+ expect(findCueWordId(sections(), 4.5, [])).toBe("c2:w2");
+ expect(findCueWordId(sections(), 1.5, [])).toBe("c1:w2");
});
it("returns an id that cannot match the other clip's copy of the same word", () => {
- const cue = findCueWordId(sections(), 4.5);
+ const cue = findCueWordId(sections(), 4.5, []);
// The whole point: `word.id` is "w2" in BOTH sections, so a bare word id lit up
// both blocks. Exactly one rendered word may claim the cue.
const claiming = sections().flatMap((s) => s.words.filter((cw) => cw.id === cue));
@@ -485,7 +491,7 @@ describe("findCueWordId", () => {
}),
];
// c2 has no words, and borrowing c1's would point at the wrong text.
- expect(findCueWordId(withEmptyC2, 4.5)).toBeNull();
+ expect(findCueWordId(withEmptyC2, 4.5, [])).toBeNull();
});
it("runs an open-ended placement up to the next one", () => {
@@ -502,8 +508,8 @@ describe("findCueWordId", () => {
timelineEndSec: 6,
}),
];
- expect(findCueWordId(open, 2)).toBe("c1:w1");
- expect(findCueWordId(open, 3.5)).toBe("c2:w1");
+ expect(findCueWordId(open, 2, [])).toBe("c1:w1");
+ expect(findCueWordId(open, 3.5, [])).toBe("c2:w1");
});
});
});
@@ -539,6 +545,7 @@ describe("clipWordId", () => {
[transcript],
[makeAsset()],
[],
+ [],
);
const rawIds = sections.flatMap((s) => s.words.map((cw) => cw.word.id));
const scopedIds = sections.flatMap((s) => s.words.map((cw) => cw.id));
@@ -547,3 +554,60 @@ describe("clipWordId", () => {
expect(new Set(scopedIds).size).toBe(scopedIds.length);
});
});
+
+// ─── The word an insertion is spoken over ───────────────────────────────────
+// The pane mapped source → ruler and back with two hand-written shifts that ignored the
+// media inserted inside the clip. Past an insertion the highlight ran ahead of the voice by
+// exactly the inserted time — it sat on the word AFTER the one being spoken — and the added
+// word itself was never highlighted at all, because the only seconds it is spoken in are the
+// insertion, and no source second exists inside one (issue #560).
+
+describe("the cue word across an insertion", () => {
+ // "b" is typed in after "a". It fits in 0.1s of existing silence and buys 2s of media.
+ const words = () => [
+ { id: "w_a", segmentId: "s1", startSec: 0, endSec: 1, text: "a" },
+ { id: "w_b", segmentId: "s1", startSec: 1, endSec: 1.1, text: "b", source: "synth" as const },
+ { id: "w_c", segmentId: "s1", startSec: 2, endSec: 3, text: "c" },
+ ];
+ // The clip carries the insertion, so it runs 0..12 for 10s of recording.
+ const clips = () => [makeClip({ sourceStartSec: 0, sourceEndSec: 10, timelineEndSec: 12 })];
+ const inserted = [
+ {
+ id: "i1",
+ assetId: "asset_1",
+ atSec: 1.1,
+ durationSec: 2,
+ wordId: "w_b",
+ reason: "",
+ origin: "user" as const,
+ },
+ ];
+ const sections = () =>
+ buildAggregatedSections(
+ clips(),
+ [makeTranscript(words())],
+ [makeAsset()],
+ removedRawSpans(clips(), [], inserted),
+ inserted,
+ );
+
+ it("highlights the added word for the whole stretch its insertion occupies", () => {
+ // The insertion opens at ruler 1.1 and closes at 3.1.
+ for (const at of [1.2, 2, 3.0]) {
+ expect(findCueWordId(sections(), at, inserted)).toBe(clipWordId("clip_1", "w_b"));
+ }
+ });
+
+ it("does not run ahead of the voice after the insertion", () => {
+ // Source 2..3 is "c", which the insertion has pushed to ruler 4..5.
+ expect(findCueWordId(sections(), 4.5, inserted)).toBe(clipWordId("clip_1", "w_c"));
+ // Without the shift this same moment resolved to source 4.5 — past "c" entirely.
+ expect(findCueWordId(sections(), 0.5, inserted)).toBe(clipWordId("clip_1", "w_a"));
+ });
+
+ it("still finds a word at the very end of the clip", () => {
+ // The extent used to stop at the source length, so the last 2s belonged to no
+ // section and the highlight simply went out.
+ expect(findCueWordId(sections(), 11.5, inserted)).not.toBeNull();
+ });
+});
diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.ts b/src/lib/ai-edition/timeline/aggregated-transcript.ts
index 71e55583d..27dcbb5cd 100644
--- a/src/lib/ai-edition/timeline/aggregated-transcript.ts
+++ b/src/lib/ai-edition/timeline/aggregated-transcript.ts
@@ -15,7 +15,15 @@
// kept word; the user or the LLM decides what to mark as skipped.
import { collapseTracksToPills, trackGroupId } from "../document/audioTracks";
-import type { AxcutAsset, AxcutAudioTrack, AxcutClip, AxcutTranscript, AxcutWord } from "../schema";
+import type {
+ AxcutAsset,
+ AxcutAudioTrack,
+ AxcutClip,
+ AxcutInsertRange,
+ AxcutTranscript,
+ AxcutWord,
+} from "../schema";
+import { sourceToTimelineSec, timelineToSourceSec } from "./inserted-time";
import { type RawSpan, type RemovedRawSpan, removalAt } from "./programme-time";
import { type TakeInsert, takeProgramme } from "./take-programme";
@@ -55,16 +63,28 @@ export type TranscriptLane = "recording" | "voiceover";
* whether two things coincide; raw time can, which is why kept-or-removed is asked here
* and not in source time (issue #560).
*/
-export function placementRawSec(placement: TranscriptPlacement, sourceSec: number): number {
- return placement.timelineStartSec + (sourceSec - placement.sourceStartSec);
+export function placementRawSec(
+ placement: TranscriptPlacement,
+ sourceSec: number,
+ insertRanges: readonly AxcutInsertRange[],
+ edge: "opens" | "closes" = "opens",
+): number {
+ return sourceToTimelineSec(placement, sourceSec, insertRanges, edge);
}
/** The placement's own stretch of raw ruler, or null when it runs open-ended. */
-export function placementRawExtent(placement: TranscriptPlacement): RawSpan | null {
+export function placementRawExtent(
+ placement: TranscriptPlacement,
+ insertRanges: readonly AxcutInsertRange[],
+): RawSpan | null {
if (placement.sourceEndSec === undefined) return null;
return {
startSec: placement.timelineStartSec,
- endSec: placementRawSec(placement, placement.sourceEndSec),
+ // `"closes"` on the end: the media inserted inside this placement is part of its
+ // stretch of ruler, so the extent has to reach past the last one. Ending short left
+ // the final seconds of every such clip belonging to no section at all, and the
+ // highlight simply went out there.
+ endSec: placementRawSec(placement, placement.sourceEndSec, insertRanges, "closes"),
};
}
@@ -214,6 +234,7 @@ export function buildClipSection(
transcript: AxcutTranscript | null,
asset: AxcutAsset | null,
removed: RemovedRawSpan[],
+ insertRanges: readonly AxcutInsertRange[],
): ClipSection {
const words = transcript
? withSilenceGaps(
@@ -225,7 +246,10 @@ export function buildClipSection(
const tagged: ClipWord[] = words.map((word) => {
// The word's CENTRE, mirroring the rule the identity filter used, so the recording
// lane's tagging does not shift under this change.
- const covering = removalAt(removed, placementRawSec(clip, (word.startSec + word.endSec) / 2));
+ const covering = removalAt(
+ removed,
+ placementRawSec(clip, (word.startSec + word.endSec) / 2, insertRanges),
+ );
return {
id: clipWordId(clip.id, word.id),
word,
@@ -291,6 +315,7 @@ export function buildAggregatedSections(
transcripts: AxcutTranscript[],
assets: AxcutAsset[],
removed: RemovedRawSpan[],
+ insertRanges: readonly AxcutInsertRange[],
): ClipSection[] {
const transcriptById = new Map(transcripts.map((t) => [t.assetId, t]));
const assetById = new Map(assets.map((a) => [a.id, a]));
@@ -300,6 +325,7 @@ export function buildAggregatedSections(
transcriptById.get(clip.assetId) ?? null,
assetById.get(clip.assetId) ?? null,
removed,
+ insertRanges,
),
);
}
@@ -379,7 +405,11 @@ export function lanePlacements(
* clip whose media has not been probed) has no extent of its own and runs to the next
* section's head, then to the end of time.
*/
-export function findCueWordId(sections: ClipSection[], rawSec: number | null): string | null {
+export function findCueWordId(
+ sections: ClipSection[],
+ rawSec: number | null,
+ insertRanges: readonly AxcutInsertRange[],
+): string | null {
if (rawSec === null || !Number.isFinite(rawSec)) return null;
// No fallback to a neighbouring section: a placement with no transcript simply has no
// cue word, and borrowing another's would point at the wrong text.
@@ -390,7 +420,7 @@ export function findCueWordId(sections: ClipSection[], rawSec: number | null): s
let match: ClipSection | null = null;
for (const [i, section] of withWords.entries()) {
if (rawSec < section.clip.timelineStartSec) break;
- const extent = placementRawExtent(section.clip);
+ const extent = placementRawExtent(section.clip, insertRanges);
const endSec =
extent?.endSec ?? withWords[i + 1]?.clip.timelineStartSec ?? Number.POSITIVE_INFINITY;
if (rawSec < endSec) {
@@ -401,7 +431,14 @@ export function findCueWordId(sections: ClipSection[], rawSec: number | null): s
if (!match) return null;
// Back to the placement's own source clock, which is what the words are stamped in.
- const t = match.clip.sourceStartSec + (rawSec - match.clip.timelineStartSec);
+ const { sourceSec: t, insideInsert } = timelineToSourceSec(match.clip, rawSec, insertRanges);
+ // Inside an insertion, the word being spoken is the one that bought it — those seconds
+ // exist for no other reason. There is no source second in there to find it by, which is
+ // why the added word could never be highlighted before.
+ if (insideInsert) {
+ const own = match.words.find((cw) => cw.word.id === insideInsert.wordId);
+ if (own) return own.id;
+ }
let previous: string | null = null;
for (const cw of match.words) {
if (isSilenceWord(cw.word)) continue;
diff --git a/src/lib/ai-edition/timeline/inserted-time.ts b/src/lib/ai-edition/timeline/inserted-time.ts
index c061b5ff0..ea0cb9489 100644
--- a/src/lib/ai-edition/timeline/inserted-time.ts
+++ b/src/lib/ai-edition/timeline/inserted-time.ts
@@ -139,7 +139,9 @@ export function sourceToTimelineSec(
* driving a decoder needs both: where to park, and the fact that it should stay parked.
*/
export function timelineToSourceSec(
- clip: AxcutClip,
+ /** The same three fields `sourceToTimelineSec` needs, so a voiceover placement maps
+ * through this too. */
+ clip: Pick<AxcutClip, "assetId" | "sourceStartSec" | "timelineStartSec">,
timelineSec: number,
inserts: readonly AxcutInsertRange[],
): { sourceSec: number; insideInsert: AxcutInsertRange | null } {
diff --git a/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts b/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts
index b132308ef..118495949 100644
--- a/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts
+++ b/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts
@@ -75,6 +75,7 @@ describe("repro: trim on clip 2 of two clips sharing one media", () => {
next.transcripts,
next.assets,
removedRawSpans(next.timeline.clips, next.timeline.trimRanges, []),
+ [],
);
expect(sections[0].trimRuns).toHaveLength(0);
expect(sections[1].trimRuns).toHaveLength(1);
diff --git a/src/lib/ai-edition/timeline/voiceoverCut.test.ts b/src/lib/ai-edition/timeline/voiceoverCut.test.ts
index 7e121be61..00892553c 100644
--- a/src/lib/ai-edition/timeline/voiceoverCut.test.ts
+++ b/src/lib/ai-edition/timeline/voiceoverCut.test.ts
@@ -84,7 +84,7 @@ describe("a cut authored from the voiceover lane", () => {
// wrote `clipId: "vo"` here and removed nothing at all.
// biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
const [placement] = voiceoverPlacements([VOICE as any]);
- const rows = cut(placementRawSec(placement, 2), placementRawSec(placement, 3));
+ const rows = cut(placementRawSec(placement, 2, []), placementRawSec(placement, 3, []));
expect(rows).toHaveLength(1);
expect(CLIPS.map((c) => c.id)).toContain(rows[0].clipId);
expect(filmSec([])).toBeCloseTo(12, 6);
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index c51c4988d..cda53e559 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -2016,7 +2016,6 @@ describe("buildSceneDescription.holdSec", () => {
}),
],
timeline: {
- // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
insertRanges: [
{
id: "i1",
@@ -2027,6 +2026,7 @@ describe("buildSceneDescription.holdSec", () => {
reason: "",
origin: "user",
},
+ // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise
] as any,
},
});