Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat(audio): the export and the transcript read the take's walk
EtienneLescot1f9801c6ac92
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 93ea198ce..f1a3a91de 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -78,6 +78,7 @@ import {} from "@/lib/ai-edition/timeline/aggregated-transcript";import { hasAnyClipWithCamera } from "@/lib/ai-edition/timeline/camera";import { formatMs } from "@/lib/ai-edition/timeline/format";+import { takeInserts } from "@/lib/ai-edition/timeline/insert-mapping";import { removedRawSpans } from "@/lib/ai-edition/timeline/programme-time";import type {AssetTranscriptionView,@@ -879,8 +880,21 @@ export function TranscriptPane({// deleting the last voiceover pill while reading it must not leave the pane, the// preview and the exporter disagreeing about which lane that project has.const { settings: captionSettings, set: setCaptionSettings } = useCaptions();- const voiceover = useMemo(() => voiceoverPlacements(audioTracks), [audioTracks]);const document = useProjectStore((s) => s.document);+ // From the RECORDING clips and the whole trim set, never from `placements`: the+ // programme is one thing, and the voiceover lane is asking whether the film still+ // contains a moment — not whether some trim happens to name an audio fragment.+ const removed = useMemo(() => removedRawSpans(clips, trimRanges), [clips, trimRanges]);+ // The take's placements are fed the cuts AND its own insertions, so a word after a pause+ // is struck through — and highlighted — at the moment it is actually heard (issue #560).+ const insertsFor = useCallback(+ (groupId: string) => (document ? takeInserts(document, groupId) : []),+ [document],+ );+ const voiceover = useMemo(+ () => voiceoverPlacements(audioTracks, removed, insertsFor),+ [audioTracks, removed, insertsFor],+ );const activeLane = resolveCaptionLane(document, captionSettings);const setLane = useCallback((captionLane: TranscriptLane) => {@@ -890,10 +904,6 @@ export function TranscriptPane({);const placements = activeLane === "voiceover" ? voiceover : clips;- // From the RECORDING clips and the whole trim set, never from `placements`: the- // programme is one thing, and the voiceover lane is asking whether the film still- // contains a moment — not whether some trim happens to name an audio fragment.- const removed = useMemo(() => removedRawSpans(clips, trimRanges), [clips, trimRanges]);const sections = useMemo(() => buildAggregatedSections(placements, transcripts, assets, removed),[placements, transcripts, assets, removed],diff --git a/src/lib/ai-edition/captions/cues.ts b/src/lib/ai-edition/captions/cues.tsindex d812f141c..78fd9250f 100644--- a/src/lib/ai-edition/captions/cues.ts+++ b/src/lib/ai-edition/captions/cues.ts@@ -24,7 +24,9 @@ import {import type { CaptionSegment } from "@/lib/captioning/transcribe";import type { AxcutDocument, AxcutTranscript } from "../schema";import { lanePlacements, type TranscriptPlacement } from "../timeline/aggregated-transcript";+import { takeInserts } from "../timeline/insert-mapping";import { expandRawSec, type RulerInsert, rulerInserts } from "../timeline/inserted-time";+import { removedRawSpans } from "../timeline/programme-time";import {type CaptionAnchorV,type CaptionSettings,@@ -208,6 +210,8 @@ export function deriveCaptionCues(// `?? []` for the same reason `insertRanges` has one: the key is additive, so a// document written before it — or hand-built, never through the schema — has none.document.audioTracks ?? [],+ removedRawSpans(document.timeline.clips, document.timeline.trimRanges),+ (groupId) => takeInserts(document, groupId),);if (placements.length === 0) return [];diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.tsindex 0a458c36a..012d45947 100644--- a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts+++ b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts@@ -64,16 +64,42 @@ describe("voiceoverPlacements", () => {expect(placements.map((p) => p.id)).toEqual(["early", "late"]);});- it("keeps every fragment of a ventilated track", () => {- // A bed spanning a cut is one pill and two fragments; collapsing them here- // would re-read the file from its head on the far side of the cut.+ it("folds a ventilated take back into one placement", () => {+ // The fragments exist because the take spans a cut in the FILM, not because the+ // narration is in two pieces. The walk recomputes the source advance, so collapsing+ // them is safe now — and necessary, because a fragment's own source window knows+ // nothing about an insertion before it.const placements = voiceoverPlacements([track({ id: "f1", trackId: "T", startMs: 0, endMs: 3000, offsetMs: 0 }),track({ id: "f2", trackId: "T", startMs: 3000, endMs: 5000, offsetMs: 3000 }),]);- expect(placements.map((p) => [p.sourceStartSec, p.sourceEndSec])).toEqual([- [0, 3],- [3, 5],+ expect(placements.map((p) => [p.sourceStartSec, p.sourceEndSec])).toEqual([[0, 5]]);+ });++ it("splits at the CUTS, not at the fragment boundaries", () => {+ const placements = voiceoverPlacements(+ [track({ id: "f1", trackId: "T", startMs: 0, endMs: 6000, offsetMs: 0 })],+ [{ startSec: 2, endSec: 4, trimIds: ["t1"] }],+ );+ // The take is heard 0..2 and 4..6 of the ruler, reading source 0..2 and 4..6 — its+ // own clock ran through the cut, so the words after it stay on their picture.+ expect(placements.map((p) => [p.timelineStartSec, p.sourceStartSec, p.sourceEndSec])).toEqual([+ [0, 0, 2],+ [4, 4, 6],+ ]);+ });++ it("maps the words after an insertion to the moment they actually occupy", () => {+ // The reason this stopped being per-fragment. Source 4 is heard at ruler 5, because+ // the pause before it took a second of the take's span.+ const placements = voiceoverPlacements(+ [track({ id: "f1", trackId: "T", startMs: 0, endMs: 6000, offsetMs: 0 })],+ [],+ () => [{ id: "i1", wordId: "w1", atSourceSec: 4, durationSec: 1 }],+ );+ expect(placements.map((p) => [p.timelineStartSec, p.sourceStartSec, p.sourceEndSec])).toEqual([+ [0, 0, 4],+ [5, 4, 5],]);});});@@ -281,3 +307,56 @@ describe("one programme, two lanes", () => {expect(voiceoverPlacements([VO])).toHaveLength(1);});});++// ─── The cue, after an insertion ─────────────────────────────────────────────+// `findCueWordId` carries its own inverse of the affine map — the fourth copy in the tree.+// It needs no insertion term of its own PROVIDED each placement is affine, which is exactly+// what walking the take by play pieces buys. Asserted rather than assumed.++describe("the karaoke highlight after a pause", () => {+ const TAKE = track({ id: "vo", startMs: 0, endMs: 6000, offsetMs: 0, durationSec: 6 });+ const WORDS = {+ assetId: "asset_vo",+ language: "en",+ segments: [],+ words: [0, 1, 2, 3, 4, 5].map((i) => ({+ id: `w${i}`,+ segmentId: "s",+ text: `w${i}`,+ startSec: i + 0.1,+ endSec: i + 0.9,+ })),+ };++ const sectionsWith = (+ inserts: Array<{ id: string; wordId: string; atSourceSec: number; durationSec: number }>,+ ) =>+ buildAggregatedSections(+ // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise+ voiceoverPlacements([TAKE as any], [], () => inserts),+ // biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise+ [WORDS as any],+ [],+ [],+ );++ it("tracks the voice with no insertion", () => {+ 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");+ // And it is NOT still answering with the pre-pause mapping.+ 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();+ });+});diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.ts b/src/lib/ai-edition/timeline/aggregated-transcript.tsindex 9ecc0d5b5..71e55583d 100644--- a/src/lib/ai-edition/timeline/aggregated-transcript.ts+++ b/src/lib/ai-edition/timeline/aggregated-transcript.ts@@ -14,8 +14,10 @@// names a word a filler. The transcript view shows plain text for every// 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 RawSpan, type RemovedRawSpan, removalAt } from "./programme-time";+import { type TakeInsert, takeProgramme } from "./take-programme";/*** The unit the aggregation actually runs over: one stretch of ONE asset's source@@ -309,32 +311,39 @@ export function buildAggregatedSections(* all (STT on a bed is noise we pay for), so a music placement could only ever* produce an empty section that reads as a failed transcription.*- * One placement PER FRAGMENT, not per user-visible track. A track that spans a cut- * is ventilated into a fragment per clip, each with its own `offsetMs` advanced by- * what its predecessors consumed (`anchorAudioTrackFragments`) — so the fragments- * already carry exactly the source windows this needs, and collapsing them back- * into one pill here would re-read the file from its head at every cut.+ * One placement per PLAY PIECE of the take's own walk, which is what makes the words after+ * an insertion map to the raw moment they actually occupy. It used to be one per stored+ * FRAGMENT — equivalent while a take could only lose time, wrong the moment it can gain+ * some, because a fragment's source window knows nothing about the pause before it.** A LOOPING take contributes nothing at all. `anchorAudioTrackFragments` deliberately* does not advance `offsetMs` across the fragments of a looping track, so their words map* to raw moments the words do not occupy — a placement built from them would read* kept-or-removed on false evidence, and would author a cut in the wrong place.*/-export function voiceoverPlacements(audioTracks: AxcutAudioTrack[]): TranscriptPlacement[] {- return audioTracks- .filter((track) => track.kind === "voiceover" && !track.loop)- .slice()+export function voiceoverPlacements(+ audioTracks: AxcutAudioTrack[],+ /** What the film no longer contains. Empty is the honest default: with no cuts and no+ * insertions the walk yields one piece per take, which is what this always produced. */+ removed: readonly RemovedRawSpan[] = [],+ /** This take's own insertions, by group id. */+ insertsFor: (groupId: string) => readonly TakeInsert[] = () => [],+): TranscriptPlacement[] {+ return collapseTracksToPills(audioTracks)+ .filter((pill) => pill.kind === "voiceover" && !pill.loop).sort((a, b) => a.startMs - b.startMs || a.id.localeCompare(b.id))- .map((track) => {- const offsetSec = track.offsetMs / 1000;- return {- id: track.id,- assetId: track.assetId,- sourceStartSec: offsetSec,- sourceEndSec: offsetSec + Math.max(0, track.endMs - track.startMs) / 1000,- timelineStartSec: track.startMs / 1000,- };- });+ .flatMap((pill) =>+ takeProgramme(pill, removed, insertsFor(trackGroupId(pill)))+ .filter((piece) => piece.kind === "play")+ .map((piece, i) => ({+ // Namespaced by piece so two stretches of one take never collide on a word id.+ id: i === 0 ? pill.id : `${pill.id}#${i}`,+ assetId: pill.assetId,+ sourceStartSec: piece.sourceStartSec,+ sourceEndSec: piece.sourceEndSec,+ timelineStartSec: piece.rawStartSec,+ })),+ );}/** The placements a lane contributes, in timeline order. */@@ -342,8 +351,10 @@ export function lanePlacements(lane: TranscriptLane,clips: AxcutClip[],audioTracks: AxcutAudioTrack[],+ removed: readonly RemovedRawSpan[] = [],+ insertsFor: (groupId: string) => readonly TakeInsert[] = () => [],): TranscriptPlacement[] {- return lane === "voiceover" ? voiceoverPlacements(audioTracks) : clips;+ return lane === "voiceover" ? voiceoverPlacements(audioTracks, removed, insertsFor) : clips;}/**diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 3c45f3249..887b63d79 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -28,6 +28,7 @@ import {getCaptionSettings,getCaptionTranslations,} from "@/lib/ai-edition/captions";+import { collapseTracksToPills, trackGroupId } from "@/lib/ai-edition/document/audioTracks";import { createId } from "@/lib/ai-edition/document/ids";import { pickOutputDims } from "@/lib/ai-edition/document/outputFormat";import {@@ -40,8 +41,10 @@ import type { AxcutClip, AxcutDocument } from "@/lib/ai-edition/schema";import { getEditorSettings } from "@/lib/ai-edition/store/editorSettings";import { assetCameraSource } from "@/lib/ai-edition/timeline/camera";import { resolveClipSourceEndSec } from "@/lib/ai-edition/timeline/clipDuration";+import { takeInserts } from "@/lib/ai-edition/timeline/insert-mapping";import { rulerInserts } from "@/lib/ai-edition/timeline/inserted-time";-import { removedRawSpans, subtractRemoved } from "@/lib/ai-edition/timeline/programme-time";+import { removedRawSpans } from "@/lib/ai-edition/timeline/programme-time";+import { takeProgramme } from "@/lib/ai-edition/timeline/take-programme";import { projectRegionsToSource } from "@/lib/ai-edition/timeline/timelineMap";import {computeCompositeLayout,@@ -574,6 +577,15 @@ export function buildSceneDescription(// the ruler says rather than D seconds early.const filmInserts = rulerInserts(document.timeline.insertRanges ?? [], projectedClips);const removed = removedRawSpans(projectedClips, document.timeline.trimRanges);+ // The take's pills, keyed by group. A voiceover is walked ONCE per pill and never per+ // stored fragment: the document keeps one fragment per clip a take covers, so walking+ // them separately would emit overlapping entries and `overlay_track_pcm` sums with `+=`+ // at an absolute offset — the export would contain the take playing on top of itself.+ const voiceoverPills = new Map(+ collapseTracksToPills(document.audioTracks)+ .filter((pill) => pill.kind === "voiceover" && !pill.loop)+ .map((pill) => [trackGroupId(pill), pill]),+ );const audioTracks = document.audioTracks.flatMap((track) => {if (track.muted) return [];const asset = assetById.get(track.assetId);@@ -633,25 +645,32 @@ export function buildSceneDescription(// #560 refuses that combination outright, and inventing semantics for something// about to be banned would be the worse answer.if (track.kind === "voiceover" && !track.loop) {- const trackRawStart = track.startMs / 1000;- const rawSpanSec = Math.max(0, track.endMs / 1000 - trackRawStart);+ const groupId = trackGroupId(track);+ const pill = voiceoverPills.get(groupId);+ // Emitted from the group's HEAD fragment only — every other fragment of the same+ // take is already covered by the pill's own walk.+ if (!pill || pill.id !== track.id) return [];+ const rawSpanSec = Math.max(0, pill.endMs / 1000 - pill.startMs / 1000);// Unprobed assets have no real duration to cap with; the RAW span is how much// file the take covers, which is the honest fallback once the cuts are taken out.const voWindowSec =sourceDurationSec > 0 ? Math.max(0, sourceDurationSec - offsetSec) : rawSpanSec;- const pieces = subtractRemoved(trackRawStart, track.endMs / 1000, removed);- const kept = pieces+ // One walk: the cuts take time away, the take's own insertions add it, and the+ // walk resolves them together so a second insertion lands after the first one's+ // hold rather than inside it.+ const kept = takeProgramme(pill, removed, takeInserts(document, groupId), rawSpeedRegions)+ .filter((piece) => piece.kind === "play").map((piece) => ({...base,startSec: projectRawTimelineSecToPlayback(projectedClips,document.timeline.trimRanges,- piece.startSec,+ piece.rawStartSec,filmInserts,rawSpeedRegions,),- trimStartSec: offsetSec + (piece.startSec - trackRawStart),- trimEndSec: Math.min(offsetSec + voWindowSec, offsetSec + (piece.endSec - trackRawStart)),+ trimStartSec: piece.sourceStartSec,+ trimEndSec: Math.min(offsetSec + voWindowSec, piece.sourceEndSec),})).filter((entry) => entry.trimEndSec > entry.trimStartSec);// The fades belong to the TAKE's edges, not to every piece a cut left behind.