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): a cut under a voiceover takes the words, not the take's tail
EtienneLescotc1633cd36ffd
diff --git a/src/components/ai-edition/VirtualPreview.audio.test.ts b/src/components/ai-edition/VirtualPreview.audio.test.tsindex e1d6fec6d..39fea8528 100644--- a/src/components/ai-edition/VirtualPreview.audio.test.ts+++ b/src/components/ai-edition/VirtualPreview.audio.test.ts@@ -1,11 +1,13 @@import { describe, expect, it } from "vitest";import { projectRawTimelineSecToPlayback } from "@/lib/ai-edition/document/timeline";import type { AxcutAudioTrack, AxcutClip, AxcutTrimRange } from "@/lib/ai-edition/schema";+import { removedRawSpans } from "@/lib/ai-edition/timeline/programme-time";import {applyPreviewAudioSettings,type PreviewAudioGraph,resolveAudioTrackPlayback,resolveTimelineAudioPlayback,+ resolveVoiceoverPlayback,timelineAudioFadeAt,} from "./VirtualPreview";@@ -308,3 +310,98 @@ describe("timelineAudioFadeAt", () => {expect(timelineAudioFadeAt(long, 2, 2)).toBe(1);});});++// ─── A cut under a voiceover ──────────────────────────────────────────────────+// Issue #560. The preview and the export have to agree about this, or a word the+// transcript pane shows struck through is still audible in one of them.++describe("resolveVoiceoverPlayback", () => {+ const CLIPS = [+ {+ id: "c1",+ assetId: "scr",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ wordRefs: [],+ origin: "user" as const,+ reason: "",+ },+ ];+ /** Raw 4..6 is out of the film. */+ const TRIMS = [+ {+ id: "t1",+ assetId: "scr",+ clipId: "c1",+ startSec: 4,+ endSec: 6,+ reason: "",+ origin: "user" as const,+ },+ ];+ const removed = removedRawSpans(CLIPS, TRIMS);++ const voice = {+ id: "vo",+ assetId: "aud",+ kind: "voiceover" as const,+ startMs: 0,+ endMs: 10_000,+ durationSec: 30,+ offsetMs: 0,+ gainDb: 0,+ loop: false,+ fadeInMs: 0,+ fadeOutMs: 0,+ muted: false,+ label: "",+ origin: "user" as const,+ } as unknown as AxcutAudioTrack;++ it("goes silent exactly where the film lost its moment", () => {+ expect(resolveVoiceoverPlayback(voice, 3.9, removed).shouldPlay).toBe(true);+ expect(resolveVoiceoverPlayback(voice, 4.5, removed).shouldPlay).toBe(false);+ expect(resolveVoiceoverPlayback(voice, 6.1, removed).shouldPlay).toBe(true);+ });++ it("keeps the take's own clock running through the cut", () => {+ // It does NOT rewind or skip: raw 7 is second 7 of the take either way, which is+ // what makes the words after the cut still line up with the ones on screen.+ expect(resolveVoiceoverPlayback(voice, 7, removed).targetTimeSec).toBeCloseTo(7, 6);+ expect(+ resolveVoiceoverPlayback({ ...voice, offsetMs: 2000 }, 7, removed).targetTimeSec,+ ).toBeCloseTo(9, 6);+ });++ it("stays silent outside its own span, and past the end of its file", () => {+ expect(resolveVoiceoverPlayback({ ...voice, startMs: 2000 }, 1, removed).shouldPlay).toBe(+ false,+ );+ expect(resolveVoiceoverPlayback(voice, 11, removed).shouldPlay).toBe(false);+ // A 3s file under a 10s span: silent after its own end rather than seeking past it.+ const short = { ...voice, durationSec: 3 } as AxcutAudioTrack;+ expect(resolveVoiceoverPlayback(short, 2.5, removed).shouldPlay).toBe(true);+ expect(resolveVoiceoverPlayback(short, 3.5, removed).shouldPlay).toBe(false);+ });++ it("schedules the same source seconds the export writes into the mix", () => {+ // Walk the take frame by frame and collect the contiguous runs of source time the+ // preview would play; they must be the export's entries, piece for piece.+ const runs: Array<{ from: number; to: number }> = [];+ for (let raw = 0; raw < 10; raw += 0.05) {+ const at = resolveVoiceoverPlayback(voice, raw, removed);+ if (!at.shouldPlay) continue;+ const last = runs.at(-1);+ if (last && Math.abs(at.targetTimeSec - last.to) < 0.06) last.to = at.targetTimeSec;+ else runs.push({ from: at.targetTimeSec, to: at.targetTimeSec });+ }+ expect(runs).toHaveLength(2);+ expect(runs[0].from).toBeCloseTo(0, 1);+ expect(runs[0].to).toBeCloseTo(4, 1);+ // The second run resumes at source 6 — the two seconds the cut took are never heard.+ expect(runs[1].from).toBeCloseTo(6, 1);+ expect(runs[1].to).toBeCloseTo(10, 1);+ });+});diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsxindex aed97cc4c..075446e01 100644--- a/src/components/ai-edition/VirtualPreview.tsx+++ b/src/components/ai-edition/VirtualPreview.tsx@@ -19,6 +19,11 @@ import type {import { audioGainScalar } from "@/lib/ai-edition/store/editorSettings";import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";import type { PlaybackClockRef } from "@/lib/ai-edition/timeline/playback-clock";+import {+ type RemovedRawSpan,+ removalAt,+ removedRawSpans,+} from "@/lib/ai-edition/timeline/programme-time";import { findActiveSpeedRegion, type SpeedRegion } from "@/lib/ai-edition/timeline/speed";import {clampVirtualTime,@@ -127,6 +132,42 @@ export function resolveTimelineAudioPlayback(};}+/**+ * Where a VOICEOVER should be, asked in RAW ruler seconds (issue #560).+ *+ * A cut under a voiceover removes the words that were said there, not the tail of the+ * take: the transcript pane has already struck those words through, so a mix that went on+ * playing them — shifted earlier, as a contiguous block does — would make the red a lie.+ *+ * Raw is the simpler question and the exact one. `resolveTimelineAudioPlayback` works in+ * output seconds because a bed is one contiguous block laid on the finished programme, and+ * getting there means projecting the playhead through the trims. A sliced take needs no+ * projection at all: its source position is its own offset plus however far raw time has+ * carried it, and it falls silent wherever the film did. That is the same question+ * `removedRawSpans` answers for the words themselves, so the two cannot drift.+ *+ * Music does NOT come through here. A bed plays through a cut and ends early, on purpose.+ */+export function resolveVoiceoverPlayback(+ track: AxcutAudioTrack,+ rawSec: number,+ removed: RemovedRawSpan[],+) {+ const startSec = track.startMs / 1000;+ const offset = Math.max(0, track.offsetMs / 1000);+ const sourceEnd = track.durationSec > 0 ? track.durationSec : Number.POSITIVE_INFINITY;+ const local = rawSec - startSec;+ const targetTimeSec = Math.min(Math.max(offset, offset + local), sourceEnd);+ return {+ targetTimeSec,+ shouldPlay:+ rawSec >= startSec &&+ rawSec < track.endMs / 1000 &&+ offset + local < sourceEnd &&+ removalAt(removed, rawSec) === null,+ };+}+/** Fraction 0..1 of a track's volume `localSec` into its span, applying the* ramps. Shares `resolveFadeSecs` with the export so a fade too long for its* span is reduced the same way on both sides. */@@ -547,6 +588,10 @@ export function VirtualPreview({// must see the live trims, not the set captured when the loop was created.const trimRangesRef = useRef(trimRanges);trimRangesRef.current = trimRanges;+ // What the film no longer contains, recomputed only when the cuts move — the rAF asks+ // it once per voiceover per frame, and walking every trim there would be wasteful.+ const removedRef = useRef(removedRawSpans(clips, trimRanges));+ removedRef.current = useMemo(() => removedRawSpans(clips, trimRanges), [clips, trimRanges]);// Trim-narrowed (`resolvePlaybackSegments`) — used ONLY to detect "has the <video>'s own// currentTime drifted into a trim" and where to jump it back out to. Everything ELSE in// this component (`clips`/`clipsRef` above, virtualTimeSec, zoom/speed region lookups,@@ -678,12 +723,13 @@ export function VirtualPreview({track.startMs / 1000,),);- const trackTarget = resolveTimelineAudioPlayback(- outputTimeSec,- outputStartSec,- track,- spanSec,- );+ // A voiceover follows the cuts; a bed plays through them. Step 6 of #560+ // refuses `loop` on a voiceover outright, so until then a looping one keeps+ // the bed's treatment rather than getting semantics invented for it.+ const trackTarget =+ track.kind === "voiceover" && !track.loop+ ? resolveVoiceoverPlayback(track, virtualTimeSecRef.current, removedRef.current)+ : resolveTimelineAudioPlayback(outputTimeSec, outputStartSec, track, spanSec);const fade = timelineAudioFadeAt(track, outputTimeSec - outputStartSec, spanSec);// Imported audio plays at its natural 1× rate, NOT the video's. The export// sums it into the programme at 1× — speed regions stretch clip PCM only,diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex 32afda410..32ef84d4a 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -2045,6 +2045,119 @@ describe("buildSceneDescription.audioTracks", () => {expect(buildSceneDescription(doc).audioTracks[0]?.trimEndSec).toBe(30);});+ // ─── A cut under a voiceover ────────────────────────────────────────────────+ // Issue #560. A trim removes the moment it covers; the transcript pane strikes the+ // words said there through. If the mix played them anyway, shifted earlier, the red+ // would be a lie — so a voiceover is SLICED by the cuts. Music is not: a bed plays+ // through and ends early, deliberately, and has no words whose redness must be true.++ /** One 10s clip, cut over raw 4..6. */+ function cutDoc(tracks: Array<Omit<typeof track, "kind"> & { kind: "music" | "voiceover" }>) {+ return makeDoc({+ assets: [+ audioAsset,+ makeAsset({ id: "scr", kind: "video", originalPath: "/screen.mp4", durationSec: 10 }),+ ],+ clips: [+ makeClip({+ id: "c1",+ assetId: "scr",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ }),+ ],+ timeline: {+ trimRanges: [+ {+ id: "t1",+ assetId: "scr",+ clipId: "c1",+ startSec: 4,+ endSec: 6,+ reason: "",+ origin: "user",+ },+ ],+ },+ audioTracks: tracks,+ });+ }++ /** A voiceover over the whole 10s, reading its file from the head. */+ const voice = {+ ...track,+ kind: "voiceover" as const,+ startMs: 0,+ endMs: 10_000,+ offsetMs: 0,+ gainDb: 0,+ };++ it("splits a voiceover at the cut, skipping exactly the seconds the film lost", () => {+ const entries = buildSceneDescription(cutDoc([voice])).audioTracks;+ expect(entries).toHaveLength(2);+ // Before the cut: raw 0..4 of the take, at output 0.+ expect(entries[0]).toMatchObject({ startSec: 0, trimStartSec: 0, trimEndSec: 4 });+ // After it: raw 6..10 of the take, at output 4 — the source jumps the two seconds+ // the cut took. Today's music path would instead play 0..8 and stop early.+ expect(entries[1]).toMatchObject({ startSec: 4, trimStartSec: 6, trimEndSec: 10 });+ });++ it("keeps the fades on the take's outer edges across a split", () => {+ const entries = buildSceneDescription(+ cutDoc([{ ...voice, fadeInMs: 500, fadeOutMs: 500 }]),+ ).audioTracks;+ expect(entries.map((e) => [e.fadeInSec, e.fadeOutSec])).toEqual([+ [0.5, 0],+ [0, 0.5],+ ]);+ });++ it("drops a voiceover buried inside a cut, and keeps one that hangs past the film", () => {+ expect(+ buildSceneDescription(cutDoc([{ ...voice, startMs: 4200, endMs: 5800 }])).audioTracks,+ ).toEqual([]);+ // Raw time past the last clip is unfilmed, not removed: the narration plays on.+ const over = buildSceneDescription(+ cutDoc([{ ...voice, startMs: 10_000, endMs: 14_000 }]),+ ).audioTracks;+ expect(over).toHaveLength(1);+ expect(over[0]).toMatchObject({ trimStartSec: 0, trimEndSec: 4 });+ });++ it("leaves a music bed under the same cut exactly as it was", () => {+ const entries = buildSceneDescription(cutDoc([{ ...voice, kind: "music" }])).audioTracks;+ // One contiguous entry, shortened at the tail by what the cut took — the behaviour+ // `VirtualPreview` and `mix_external_tracks` have always had for a bed.+ expect(entries).toEqual([+ {+ path: "/music.mp3",+ startSec: 0,+ gainDb: 0,+ trimStartSec: 0,+ trimEndSec: 8,+ fadeInSec: 0,+ fadeOutSec: 0,+ },+ ]);+ });++ it("leaves a LOOPING voiceover on the music path, which step 6 will forbid outright", () => {+ // The window comes from the ASSET's duration, so the short file has to be there.+ const doc = cutDoc([{ ...voice, loop: true, endMs: 10_000 }]);+ const short = {+ ...doc,+ assets: doc.assets.map((a) => (a.id === "aud" ? { ...a, durationSec: 3 } : a)),+ };+ const entries = buildSceneDescription(short).audioTracks;+ // Repeats, not slices: inventing semantics for a combination about to be banned+ // would be the worse answer.+ expect(entries.length).toBeGreaterThan(1);+ expect(entries.every((e) => e.trimStartSec === 0)).toBe(true);+ });+it("drops a muted track from the mix list", () => {const doc = makeDoc({ assets: [audioAsset], audioTracks: [{ ...track, muted: true }] });expect(buildSceneDescription(doc).audioTracks).toEqual([]);diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 69bfa1016..8e939480d 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -39,6 +39,7 @@ 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 { removedRawSpans, subtractRemoved } from "@/lib/ai-edition/timeline/programme-time";import { projectRegionsToSource } from "@/lib/ai-edition/timeline/timelineMap";import {computeCompositeLayout,@@ -560,6 +561,9 @@ export function buildSceneDescription(| PlaybackSpeedRegion[]| undefined) ?? []).filter((r) => Number.isFinite(r.speed) && r.speed > 0);+ // The one removed set, hoisted out of the map: every voiceover asks it the same+ // question, and it does not depend on the track.+ const removed = removedRawSpans(projectedClips, document.timeline.trimRanges);const audioTracks = document.audioTracks.flatMap((track) => {if (track.muted) return [];const asset = assetById.get(track.assetId);@@ -605,6 +609,44 @@ export function buildSceneDescription(// span itself is the window — the mixer stops at the real end of the file.const windowSec = sourceDurationSec > 0 ? Math.max(0, sourceDurationSec - offsetSec) : spanSec;if (windowSec <= 0) return [];++ // A cut under a VOICEOVER removes the words that were said there, not the tail of+ // the take (issue #560). The transcript pane strikes those words through; if the+ // mix went on playing them, shifted earlier, the red would be a lie.+ //+ // Music deliberately keeps the branch below: a bed plays through a cut and ends+ // early, because slicing it at every edit is a musical regression, and a bed has no+ // words whose redness has to be true. A LOOPING voiceover keeps it too — step 6 of+ // #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);+ // 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+ .map((piece) => ({+ ...base,+ startSec: projectRawTimelineSecToPlayback(+ projectedClips,+ document.timeline.trimRanges,+ piece.startSec,+ rawSpeedRegions,+ ),+ trimStartSec: offsetSec + (piece.startSec - trackRawStart),+ trimEndSec: Math.min(offsetSec + voWindowSec, offsetSec + (piece.endSec - trackRawStart)),+ }))+ .filter((entry) => entry.trimEndSec > entry.trimStartSec);+ // The fades belong to the TAKE's edges, not to every piece a cut left behind.+ return kept.map((entry, i) => ({+ ...entry,+ fadeInSec: i === 0 ? base.fadeInSec : 0,+ fadeOutSec: i === kept.length - 1 ? base.fadeOutSec : 0,+ }));+ }if (!track.loop) {return [{