Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 95ac33ab49d8528812c5643581e875b22cd0151b
parent 82239866fabe9405714c5b3efa0b0b7cd958352d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue,  3 Nov 2026 11:25:14 -0500

umtool: a narrated post's read RATE (0.8-1.5, default 1) -- the voice atempo'd, its pitch kept, the attachment untouched; every second taken from a take (the read span, the item's length, the parts' starts, the muffle's schedule) is the take's divided by it (operator: "read everything the slightest bit faster")

render.postNarration.rate (the cut's) and narration.rate (a post's), validated
in the build's words; `umtool posts narrate <p> --cut rate=1.08`, `… <item>
rate=1.1` and `posts set-item <p> <item> narration.rate=1.1` (any mix knob as
narration.<k>=); the post bench's mix gets **read rate**, its read lane the
read's real length. PostItemPlayer plays the take at the rate times a `speed`
it is given (playbackRate with preservesPitch, the attachment at `speed`, the
drift allowance scaled by it). Docs: knobs.md and report-video.md rows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/components/projects/PostNarrationPanel.tsx | 7++++---
Mumtool/components/projects/review/PostItemPlayer.tsx | 51+++++++++++++++++++++++++++++++++++++++------------
Mumtool/docs/knobs.md | 7++++---
Mumtool/docs/report-video.md | 13+++++++++----
Mumtool/lib/report/manifest.mjs | 2+-
Mumtool/lib/report/postNarration.test.mjs | 12++++++++++++
Mumtool/lib/report/postNarrationCli.mjs | 14++++++++------
Mumtool/lib/report/postsCli.mjs | 27++++++++++++++++++++++++++-
Mumtool/report-to-video/post-narration.mjs | 52++++++++++++++++++++++++++++++++++++++++------------
Mumtool/report-to-video/post-narration.test.mjs | 43++++++++++++++++++++++++++++++++++++++++++-
10 files changed, 185 insertions(+), 43 deletions(-)

diff --git a/umtool/components/projects/PostNarrationPanel.tsx b/umtool/components/projects/PostNarrationPanel.tsx @@ -27,7 +27,7 @@ import type { PostPlan } from "./review/PostItemPlayer"; // part), play back, Keep -- saved as a recorded take and picked // takes each take (play it, its parts, Pick, its note), Approve, the // script, Re-take with direction (the EDITOR's tts op, a job) -// the mix wet, lead, tail, ramp, linger, short, attach, clip, duck +// the mix wet, lead, tail, ramp, linger, rate, short, attach, clip, duck // // Every change is one write (POST /api/report/post-narration), the writer // `umtool posts narrate` runs; the bench takes the entry it returns. @@ -420,7 +420,7 @@ export default function PostNarrationPanel({ {sch && picked && ( <div data-post-lane="read"> <div className="micro mb-1"> - the read · {picked.file.split("/").pop()} · {picked.seconds.toFixed(1)} s from {lead.toFixed(2)} s · muffled to {sch.voiceEnd.toFixed(1)} s, clean from {sch.rampEnd.toFixed(1)} s · {mixPhaseAt(sch, s)} + the read · {picked.file.split("/").pop()} · {picked.seconds.toFixed(1)} s{(sch.rate ?? 1) !== 1 ? ` read in ${sch.seconds.toFixed(1)} s at ${sch.rate}×` : ""} from {lead.toFixed(2)} s · muffled to {sch.voiceEnd.toFixed(1)} s, clean from {sch.rampEnd.toFixed(1)} s · {mixPhaseAt(sch, s)} </div> <div className="relative h-16 w-full overflow-hidden rounded bg-black/30" @@ -448,7 +448,7 @@ export default function PostNarrationPanel({ ))} <div className="absolute inset-y-1 cursor-grab rounded bg-amber-400/20 ring-1 ring-amber-400/60" - style={{ left: pct(lead), width: pct(picked.seconds) }} + style={{ left: pct(lead), width: pct(sch.seconds) }} onPointerDown={(e) => { e.stopPropagation(); (e.currentTarget.parentElement as HTMLElement).setPointerCapture(e.pointerId); @@ -691,6 +691,7 @@ export default function PostNarrationPanel({ {mixKnob("tail", "tail", { step: 0.05, min: 0, max: 5 })} {mixKnob("ramp", "ramp", { step: 0.1, min: 0, max: 5 })} {mixKnob("linger", "linger", { step: 0.1, min: 0, max: 30 })} + {mixKnob("rate", "read rate", { step: 0.01, min: 0.8, max: 1.5 })} {mixKnob("short", "short clip", { options: ["hold", "loop"] })} {mixKnob("attach", "attachment", { options: ["under", "after"] })} {mixKnob("clip", "clip", { options: ["read", "full"] })} diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -13,11 +13,14 @@ import { dryGainAt, mixPhaseAt, pickedTake, wetGainAt } from "umtool-report-to-v // first frame while the words are read, then each in turn -- a video playing // with its sound, a GIF looped, an image held (pushed in on when it asks). // The cut's clock is Play's own; each element follows it, re-seeked when it -// drifts. A video's words (its transcript) show at the slot's foot. +// drifts -- and plays at its speed (`speed`, Play's 0.75-3x: playbackRate, +// the pitch kept), so a fast-forward SPEEDS the item up rather than seeking +// it forward every few frames. The voice plays at that times the read's own +// `rate` (post-narration.mjs). A video's words show at the slot's foot. // --------------------------------------------------------------------------- /** A narrated item's mix on its clock (post-narration.mjs narrationSchedule). */ -export type NarrationSchedule = { at: number; seconds: number; voiceEnd: number; rampEnd: number; wet: number; lowpassHz: number; duck: boolean; attach?: string; lufs?: number }; +export type NarrationSchedule = { at: number; seconds: number; takeSeconds?: number; rate?: number; voiceEnd: number; rampEnd: number; wet: number; lowpassHz: number; duck: boolean; attach?: string; lufs?: number }; export type PostPlan = { reading: number; @@ -40,9 +43,23 @@ type Box = { width: number; height: number }; type Cue = { start: number; end: number; text: string }; const pct = (n: number, of: number) => `${(n / of) * 100}%`; -/** How far a playing element may drift from the cut's clock before it is re-seeked. */ +/** How far a playing element may drift from the cut's clock before it is re-seeked (times the speed, above 1x). */ const DRIFT = 0.3; +/** An element played at `rate`, its pitch kept (the bench's and Play's clips do the same). */ +function setRate(el: HTMLMediaElement, rate: number) { + const want = Number.isFinite(rate) && rate > 0 ? rate : 1; + const m = el as HTMLMediaElement & { preservesPitch?: boolean; mozPreservesPitch?: boolean; webkitPreservesPitch?: boolean }; + if (m.preservesPitch !== true) { + m.preservesPitch = true; + m.mozPreservesPitch = true; + m.webkitPreservesPitch = true; + } + // The load algorithm resets playbackRate to defaultPlaybackRate: set both (ClipBench's lesson). + if (Math.abs(el.defaultPlaybackRate - want) > 1e-3) el.defaultPlaybackRate = want; + if (Math.abs(el.playbackRate - want) > 1e-3) el.playbackRate = want; +} + export function postFileUrl(project: string, rel: string) { return `/api/report/post-item?project=${encodeURIComponent(project)}&file=${encodeURIComponent(rel)}`; } @@ -93,7 +110,7 @@ function mixGraph(el: HTMLMediaElement, lowpassHz: number) { } function MediaEl({ - project, m, box, b, step, s, playing, inStep, mix = null, + project, m, box, b, step, s, playing, inStep, mix = null, speed = 1, }: { project: string; m: PostPlan["steps"][number]["items"][number]; @@ -105,6 +122,8 @@ function MediaEl({ inStep: boolean; /** Narrated: its sound muffled under the read, on this schedule. */ mix?: NarrationSchedule | null; + /** The clock's speed (Play's rate): the element plays at it. */ + speed?: number; }) { const ref = useRef<HTMLVideoElement | null>(null); // The muffle follows the clock: the gains set from the item's second, as the render's expressions are. @@ -130,7 +149,8 @@ function MediaEl({ useEffect(() => { const v = ref.current; if (!v || target === null) return; - if (Math.abs(v.currentTime - target) > DRIFT || !run) { + setRate(v, speed); + if (Math.abs(v.currentTime - target) > DRIFT * Math.max(1, speed) || !run) { try { v.currentTime = target; } catch { @@ -139,7 +159,7 @@ function MediaEl({ } if (run && v.paused) void v.play().catch(() => {}); if (!run && !v.paused) v.pause(); - }, [target, run]); + }, [target, run, speed]); const progress = inStep ? Math.min(1, Math.max(0, (s - step.at) / Math.max(0.1, step.seconds))) : 0; return ( <div @@ -154,6 +174,7 @@ function MediaEl({ src={postFileUrl(project, String(m.src))} data-post-video={m.i} data-post-video-playing={run ? "1" : "0"} + data-post-video-rate={String(speed)} preload="auto" playsInline loop={step.loop} @@ -174,7 +195,7 @@ function MediaEl({ } export default function PostItemPlayer({ - project, take = null, entry, plan, box, s, playing, cardKey = null, + project, take = null, entry, plan, box, s, playing, cardKey = null, speed = 1, }: { project: string; take?: string | null; @@ -186,6 +207,8 @@ export default function PostItemPlayer({ playing: boolean; /** Changes when the saved item does (the bench: its manifest token), so the card page is drawn again. */ cardKey?: string | null; + /** The clock's speed (Play's 0.75-3x): the attachments and the voice play at it, not seeked along. */ + speed?: number; }) { const wrap = useRef<HTMLDivElement | null>(null); const [scale, setScale] = useState(0); @@ -195,12 +218,16 @@ export default function PostItemPlayer({ const voice = useRef<HTMLAudioElement | null>(null); const local = mix ? s - mix.at : -1; const speaking = !!mix && local >= 0 && local < mix.seconds; + // The read's own rate (post-narration.mjs `rate`): a second of the item's clock is `readRate` of the take's. + const readRate = mix?.rate && mix.rate > 0 ? mix.rate : 1; useEffect(() => { const a = voice.current; if (!a || !mix) return; - const target = Math.min(Math.max(0, local), Math.max(0, mix.seconds - 0.01)); + const takeSeconds = mix.takeSeconds ?? mix.seconds * readRate; + const target = Math.min(Math.max(0, local * readRate), Math.max(0, takeSeconds - 0.01)); const run = playing && speaking; - if (Math.abs(a.currentTime - target) > DRIFT || !run) { + setRate(a, speed * readRate); + if (Math.abs(a.currentTime - target) > DRIFT * Math.max(1, speed * readRate) || !run) { try { a.currentTime = target; } catch { @@ -209,7 +236,7 @@ export default function PostItemPlayer({ } if (run && a.paused) void a.play().catch(() => {}); if (!run && !a.paused) a.pause(); - }, [mix, local, playing, speaking]); + }, [mix, local, playing, speaking, speed, readRate]); useEffect(() => { const node = wrap.current; if (!node) return; @@ -262,7 +289,7 @@ export default function PostItemPlayer({ > {mix && voiceTake && ( // eslint-disable-next-line jsx-a11y/media-has-caption - <audio ref={voice} src={takeFileUrl(project, voiceTake.file)} preload="auto" data-post-narration-audio={voiceTake.file} /> + <audio ref={voice} src={takeFileUrl(project, voiceTake.file)} preload="auto" data-post-narration-audio={voiceTake.file} data-post-narration-rate={String(speed * readRate)} /> )} {scale > 0 && ( <div className="absolute left-0 top-0" style={{ width: box.width, height: box.height, transform: `scale(${scale})`, transformOrigin: "0 0" }}> @@ -287,7 +314,7 @@ export default function PostItemPlayer({ {shown && layout.slot && (layout.mode === "side" || mediaPhase) && ( <> {stepBoxes(shown, layout.slot).map((b: { x: number; y: number; width: number; height: number }, j: number) => ( - <MediaEl key={`${plan.steps.indexOf(shown)}:${j}`} project={project} m={shown.items[j]} box={box} b={b} step={shown} s={s} playing={playing} inStep={inStep} mix={mix} /> + <MediaEl key={`${plan.steps.indexOf(shown)}:${j}`} project={project} m={shown.items[j]} box={box} b={b} step={shown} s={s} playing={playing} inStep={inStep} mix={mix} speed={speed} /> ))} {cue && ( <div diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -542,7 +542,7 @@ puts the walked take over the project's manifest with one undo | | In umtool | Keys | |---|---|---| -| play / pause, back (tap again: further), pause, play (tap again: 1.5×, 2×, …; the voice keeps its pitch), ±5 s, previous / next clip | the transport under the picture, the speed menu | Space, J K L, ← →, P N | +| play / pause, back (tap again: further), pause, play (tap again: 1.5×, 2×, …; the voice keeps its pitch), ±5 s, previous / next clip — a post item plays FASTER at the speed too (its attachment and its narration at that `playbackRate`, the card's clock with them), never skipped through | the transport under the picture, the speed menu | Space, J K L, ← →, P N | | the whole cut at a glance: a cell per entry as wide as it plays, tinted by its recording's date (older is darker), hatched when its media is not fetched; the sections' seams with their first date and their name, in the section's colour; the counter (the deck's tally) as a staircase with its total at the end and at the playhead; the notes as pins | the **reel strip** under the picture: click or drag a cell's body to scrub, a cell's Enter jumps to its start, hover names it | — | | closer: zoom at the pointer, in, out, fit, the clip on screen, its section; pan; the whole cut under it | the strip's **zoom** row (− + Fit, **Zoom to clip**, **Zoom to section**), Ctrl/⌘ + wheel, the wheel while zoomed, the overview | z Z f F | | move a clip: drag it to another place, into another section | drag a cell by its top band (⠿, or with Alt held); **Move <clip> to…** (a section's start or end); an **Undo** after | Alt+← → on a focused cell | @@ -681,9 +681,10 @@ the shape, the mix, recordings, parts, the best part). One writer for a post's n | `narration.pick` — the take that plays | post bench, the take's **Pick** | `--pick <n>` (1 = the first, as `--list` shows) | `patch: {pick}` (an index) | | `narration.approved` — the picked take on this script, approved (a new script or pick takes it away) | post bench, **approved** | `--approve` · `--unapprove` | `patch: {approved: true \| null}` | | `narration.off` — keep it all, play un-narrated | post bench, **narrated** | `--off` · `--on` | `patch: {off: true \| null}` | -| `lead`, `tail`, `ramp`, `linger`, `wet`, `lowpassHz`, `duck`, `short` (`hold`\|`loop`), `clip` (`read`\|`full`), `attach` (`under`\|`after`), `lufs` — this post's mix | post bench, **the mix**; the read lane's voice block dragged sets `lead` | `umtool posts narrate <p> <item> lead=0.6 wet=0.25 short=loop …` (`k=` back to the cut's) | `patch: {…}` | +| `lead`, `tail`, `ramp`, `linger`, `wet`, `lowpassHz`, `duck`, `short` (`hold`\|`loop`), `clip` (`read`\|`full`), `attach` (`under`\|`after`), `lufs`, `rate` — this post's mix | post bench, **the mix** (`rate`: **read rate**); the read lane's voice block dragged sets `lead` | `umtool posts narrate <p> <item> lead=0.6 wet=0.25 short=loop rate=1.1 …` (`k=` back to the cut's) · `umtool posts set-item <p> <item> narration.rate=1.1` (any mix knob as `narration.<k>=`) | `patch: {…}` | +| `rate` — the READ's speed, 0.8–1.5 (default 1): the voice sped up, its pitch kept (the build's `atempo`; Play's `playbackRate` with `preservesPitch`), the attachment untouched; the item's length, the muffle and the parts follow the faster read (take ÷ rate) | post bench, **the mix**, **read rate**; the read lane says `read in <s> at <r>×` | the cut's: `umtool posts narrate <p> --cut rate=1.08` · a post's: `… <item> rate=1.1` or `posts set-item <p> <item> narration.rate=1.1` | `patch: {rate}` | | the attachment's window — its in and out for the read; why it was chosen (`narration.window`) | post bench, the attachment lane's handles; **Re-pick best**; **Play whole attachment** | `umtool posts fit <p> --all \| <item>… [--linger s]` · `posts set-item <p> <item> fit=read[:<linger>]` | `op: "fit", linger?` · the handles: `POST /api/report/post-item {op: "set", patch: {media}}` | -| `render.postNarration` — the cut's mix (every key above but `attach`, and `engine`, `voice`) | — | `umtool posts narrate <p> --cut wet=0.25 clip=full …` | — | +| `render.postNarration` — the cut's mix (every key above but `attach`, and `engine`, `voice`) | — | `umtool posts narrate <p> --cut wet=0.25 clip=full rate=1.08 …` | — | | undo the last write | post bench, **Undo last change** | `umtool timeline <p> undo` | `op: "undo"` | | the hand-made batch | — | `umtool posts narrate <p> --import` (`narration/posts/index.json`, a take's `take-<n>.parts.json`) | — | | the authors' pictures (`postAvatars`) | drawn on every card | `umtool posts avatar <p> <handle> <image>` (`off`) · `umtool posts avatars <p>` | — | diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -469,7 +469,7 @@ attachments play beside the words within it. | | seconds | |---|---| | the read, un-narrated | the reading time: `clamp(1 + words / 3, 3, 15)` — 3 words a second (about 180 a minute), a second to find the text first — + each post it answers, and the post it quotes, `clamp(words / 3, 1, 4)` (context, not the post) | -| the read, narrated | lead + the take + tail + linger (0.4 + take + 0.3 + 1.8: the item ends `linger` after the words; [Narrated post items](#narrated-post-items)) | +| the read, narrated | lead + the take ÷ `rate` + tail + linger (0.4 + take + 0.3 + 1.8 at rate 1: the item ends `linger` after the words; [Narrated post items](#narrated-post-items)) | | a video | from the item's first frame, from its in point (or the best part `posts fit` chose) for the read — cut to it; an out point set is kept as the choice; `clip: "full"` plays it whole. Shorter than the read: its last frame held (`short: "loop"` loops it) | | pictures | the read's time left after the videos, shared out: each image (or a GIF, looped; or a grid, one picture) at least 1.5 s (`POST_PICTURE_MIN`) | | the item | max(the read, the attachments) | @@ -556,13 +556,17 @@ manifest in one undoable write. umtool never synthesizes: `posts narrate <p> <it **The mix, inside the build's audio graph** (`postNarrationFilters`, frame-accurate, the item's true length — so the deck's rail and date run on with it, never frozen): the item's own sound split wet / dry; the wet low-passed at `lowpassHz` twice at `wet` -until `lead + take + tail`, then ramped to silence over `ramp` while the dry ramps up -from silence; the voice levelled to `lufs` (its measured loudness), the narrator's +until `lead + take ÷ rate + tail`, then ramped to silence over `ramp` while the dry ramps up +from silence; the voice sped up by `rate` (`atempo`, its pitch kept; the attachment +never sped), levelled to `lufs` (its measured loudness), the narrator's compressor (threshold 0.1, ratio 3) and ×1.5 make-up, delayed by `lead`; all three mixed without normalising under a 0.95 limiter. Measured against the demo: the same segment lengths to the millisecond, its levels within 0.2 dB in the read and after it. Play the cut plays the take and muffles the attachment live (WebAudio: two low-pass -BiquadFilters and two gains on the same schedule). +BiquadFilters and two gains on the same schedule), the take at `rate` (`playbackRate`, +`preservesPitch`). Play's speed menu (1.5×, 2×, …) plays a post item FASTER — the +attachment and the voice at that playbackRate, the card's clock with them — rather than +seeking them forward every few frames (before 3 Nov a fast-forward skipped through a post). | `render.postNarration` / a post's `narration` | default | what it does | |---|---|---| @@ -577,6 +581,7 @@ BiquadFilters and two gains on the same schedule). | `short` | `hold` | a video shorter than the read: its last frame held, or `loop` | | `attach` | `under` | one post's: `after` reads over the card first, then plays the attachments whole | | `lufs` | −21 | the voice levelled to this before the compressor (where Orpheus `zac` reads) | +| `rate` | 1 | the READ's speed, 0.8–1.5 (operator, 3 Nov: "read everything the slightest bit faster"): the voice time-stretched, its pitch kept; the attachment untouched. Every second taken from the take — the read, its parts' starts, the muffle's schedule, the item's length — is the take's ÷ `rate` (a 13.5 s take at 1.08 reads in 12.5 s) | | `engine`, `voice` | `orpheus`, `zac` | what a new synthesized take asks for (the cut's, or one post's) | **Scripts are the post, VERBATIM** (operator: "stick to the script! Only adjust diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -2504,7 +2504,7 @@ export function handlesWithoutAvatar(m, handles) { // ---- a post item's narration (report-to-video/post-narration.mjs) ---------- /** The narration keys a write may set on one post item (post-narration.mjs; knobs.md, "A narrated post item"). */ -export const POST_NARRATION_KNOBS = Object.freeze(["script", "excerpt", "engine", "voice", "speed", "pick", "approved", "off", "lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs", "window"]); +export const POST_NARRATION_KNOBS = Object.freeze(["script", "excerpt", "engine", "voice", "speed", "pick", "approved", "off", "lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs", "rate", "window"]); /** * One post item's narration, changed in place (`m` the manifest inside a diff --git a/umtool/lib/report/postNarration.test.mjs b/umtool/lib/report/postNarration.test.mjs @@ -119,6 +119,18 @@ test("the writers: the script, a take (picked), the pick and the approval -- a n // The cut's mix. assert.equal((await cli(["narrate", "w", "--cut", "wet=0.25", "clip=full"])).code, 0); assert.deepEqual((await manifest(p)).render.postNarration, { wet: 0.25, clip: "full" }); + // The read's rate: the cut's, a post's own (posts narrate, and set-item's narration.rate=), refused out of 0.8-1.5. + assert.equal((await cli(["narrate", "w", "--cut", "rate=1.08"])).code, 0); + assert.equal((await manifest(p)).render.postNarration.rate, 1.08); + assert.equal((await cli(["narrate", "w", "p-1", "rate=1.2"])).code, 0); + assert.equal((await manifest(p)).timeline[0].narration.rate, 1.2); + assert.equal((await cli(["set-item", "w", "p-1", "narration.rate=1.15"])).code, 0); + assert.equal((await manifest(p)).timeline[0].narration.rate, 1.15); + assert.equal((await cli(["set-item", "w", "p-1", "narration.rate="])).code, 0); + assert.equal((await manifest(p)).timeline[0].narration.rate, undefined); + const fast = await cli(["narrate", "w", "--cut", "rate=3"]); + assert.equal(fast.code, 1); + assert.match(fast.err, /rate must be 0\.8–1\.5/); }); test("--all --draft-scripts: every post's words verbatim (cleaned to be spoken), in one write", async () => { diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -11,7 +11,7 @@ // umtool posts narrate <p> <item> --take [--note "…"] [--voice v] [--engine e] [--speed s] [--script "…"] // a new take, asked of the editor (a job; waits) // umtool posts narrate <p> <item> --pick <n> | --approve | --unapprove | --off | --on -// umtool posts narrate <p> <item> k=v … this post's mix: lead tail ramp linger clip wet lowpass duck short attach lufs +// umtool posts narrate <p> <item> k=v … this post's mix: lead tail ramp linger clip wet lowpass duck short attach lufs rate // umtool posts narrate <p> --all --draft-scripts [--force] scripts from the posts' words (verbatim) // umtool posts narrate <p> --all --take [--limit N] every missing take, one at a time (resumable) // umtool posts narrate <p> --cut k=v … the cut's mix (render.postNarration) @@ -38,9 +38,9 @@ export const NARRATE_USAGE = [ " umtool posts narrate <project> --list [--json]", " umtool posts narrate <project> <item> [--script \"…\"] [--take [--note \"…\"] [--voice v] [--engine e] [--speed s]]", " [--pick <n>] [--approve|--unapprove] [--off|--on] [lead=… tail=… ramp=… linger=… clip=read|full", - " wet=… lowpass=… duck=on|off short=hold|loop attach=under|after lufs=…] [--json]", + " wet=… lowpass=… duck=on|off short=hold|loop attach=under|after lufs=… rate=…] [--json]", " umtool posts narrate <project> --all --draft-scripts [--force] | --all --take [--limit N]", - " umtool posts narrate <project> --cut lead=… tail=… ramp=… linger=… clip=read|full wet=… lowpass=… duck=on|off short=hold|loop lufs=… engine=… voice=…", + " umtool posts narrate <project> --cut lead=… tail=… ramp=… linger=… clip=read|full wet=… lowpass=… duck=on|off short=hold|loop lufs=… rate=… engine=… voice=…", " A NARRATED POST ITEM: its script read by a stock synthetic voice, its attachment playing under the read (muffled,", " then clean). Takes are files of the project (narration/posts/<postId>/take-<n>.<engine>-<voice>.wav) the EDITOR", " writes (`pnpm ops tts`, a job on its tts queue; ARCHILYZER_EDITOR_URL + WORKER_TOKEN) -- umtool never synthesizes.", @@ -53,6 +53,8 @@ export const NARRATE_USAGE = [ " (enhance: denoise, level; convert: the performance kept, the timbre a STOCK synthetic voice) -- the original kept.", " A narrated post lasts lead + its read + tail + linger (1.8 s); a longer video is cut to that -- its best part,", " once `umtool posts fit` has scanned it (else from its in point). clip=full plays the attachments whole.", + " rate=0.8–1.5 (default 1): the READ sped up (its pitch kept), the attachment untouched; the post's length, its", + " muffle and its parts follow the faster read (a 10 s take at rate=1.25 reads in 8 s).", ].join("\n"); export class NarrateError extends Error {} @@ -190,7 +192,7 @@ export function narrationLines(e, render) { }); if (plan.narration) { const k = postNarrationKnobs(e, render); - lines.push(` mix: ${["lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs"].map((x) => fmtKnob(x, k[x])).join(" ")}`); + lines.push(` mix: ${["lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs", "rate"].map((x) => fmtKnob(x, k[x])).join(" ")}`); if (n.window) lines.push(` window: attachment ${n.window.media + 1} ${n.window.start}–${n.window.end} s (score ${n.window.score}): ${n.window.reason}`); lines.push(` plays: voice ${plan.narration.at}–${(plan.narration.at + plan.narration.seconds).toFixed(2)} s, muffled to ${plan.narration.voiceEnd} s, clean from ${plan.narration.rampEnd} s; attachments ${plan.steps.map((s) => `${s.kind} ${s.at}+${s.seconds}`).join(", ") || "none"}${plan.held ? `, held ${plan.held} s` : ""}`); } @@ -212,7 +214,7 @@ export function mixPatchOf(pairs, { cut = false } = {}) { if (!Number.isFinite(x)) throw new NarrateError(`${k}= takes a number`); return x; }; - if (["lead", "tail", "ramp", "linger", "wet", "lufs"].includes(k)) out[k] = clear ? null : num(); + if (["lead", "tail", "ramp", "linger", "wet", "lufs", "rate"].includes(k)) out[k] = clear ? null : num(); else if (k === "clip") out.clip = clear ? null : v; else if (k === "lowpass" || k === "lowpassHz") out.lowpassHz = clear ? null : num(); else if (k === "duck") out.duck = clear ? null : ON.has(v) ? true : OFF.has(v) ? false : (() => { throw new NarrateError("duck= takes on or off"); })(); @@ -225,7 +227,7 @@ export function mixPatchOf(pairs, { cut = false } = {}) { if (!m) throw new NarrateError("fit= takes read or read:<linger seconds>"); out.linger = m[1] !== undefined ? Number(m[1]) : null; out.clip = null; - } else throw new NarrateError(`${pair}: not a narration knob (lead, tail, ramp, end, wet, lowpass, duck, short, ${cut ? "linger, clip, lufs, engine, voice" : "linger, clip, attach, lufs, fit"})`); + } else throw new NarrateError(`${pair}: not a narration knob (lead, tail, ramp, end, wet, lowpass, duck, short, ${cut ? "linger, clip, lufs, rate, engine, voice" : "linger, clip, attach, lufs, rate, fit"})`); } if (!Object.keys(out).length) throw new NarrateError("nothing to set"); return out; diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -59,7 +59,7 @@ export const POSTS_USAGE = [ " umtool posts set-item <project> <item> [hold=<s>|off] [layout=sequence|grid] [redact=on|off|auto]", " [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.mute=on|off] [media.<i>.crop=x,y,w,h|off]", " [media.<i>.push=on|off] [media.<i>.trim=off] [quoted.paraphrase=\"…\"|off]", - " [parent.<i>.paraphrase=\"…\"|off] [--json]", + " [parent.<i>.paraphrase=\"…\"|off] [narration.rate=0.8–1.5|narration.<mix knob>=…] [--json]", " a post item's knobs (the post bench's writer, updatePostItem): its hold, its images' grid, the blur of other authors,", " an attachment's trim, sound, crop (fractions of its picture) and push-in; fit=read[:linger] (a narrated post: its", " video cut to its best part for the read, `posts fit`). quoted.paraphrase / parent.<i>.paraphrase (nearest first):", @@ -609,6 +609,31 @@ async function setItemCommand(projectArg, ref, pairs, { root, json, out }) { const { fitCommand } = await import("./postNarrationCli.mjs"); return fitCommand(await projectOf(projectArg, root), [ref], { linger: m[1] !== undefined ? Number(m[1]) : null, json, out }); } + // narration.<knob>=…: this post's narration mix (rate, lead, wet …), through the narration's own writer. + const narr = pairs.filter((p) => p.startsWith("narration.")); + if (narr.length) { + if (narr.length !== pairs.length) throw new CliError("narration.<knob>= goes with other narration knobs only (it is posts narrate's mix on this item)"); + const { mixPatchOf, NarrateError } = await import("./postNarrationCli.mjs"); + let npatch; + try { + npatch = mixPatchOf(narr.map((p) => p.slice("narration.".length))); + } catch (err) { + throw err instanceof NarrateError ? new CliError(err.message) : err; + } + const project = await projectOf(projectArg, root); + const manifest = await readManifest(project.dir); + const hit = (Array.isArray(manifest?.timeline) ? manifest.timeline : []).find((e) => e?.type === "post" && (e.id === ref || String(e.post ?? "").split("/")[1] === ref)); + if (!hit) throw new CliError(`no post item ${ref} in ${project.id} (its id, or the post's id)`); + const { updatePostNarration } = await import("./manifest.mjs"); + const { result, editNotes } = await withEditNotes(project, async () => updatePostNarration(project.dir, hit.id, npatch, { token: await manifestToken(project.dir) })); + if (json) { + out(JSON.stringify({ ok: true, id: hit.id, entry: result.entry, token: result.token, editNotes }, null, 2)); + return 0; + } + const { postItemSeconds } = await import("umtool-report-to-video/post-item"); + out(`set ${hit.id}: ${Object.entries(npatch).map(([k, v]) => `narration.${k}=${v ?? "(the cut's)"}`).join(" ")} -- ${postItemSeconds(result.entry, manifest.render).toFixed(1)} s`); + return 0; + } const patch = postItemPatchOf(pairs); const project = await projectOf(projectArg, root); const manifest = await readManifest(project.dir); diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs @@ -15,7 +15,7 @@ // approved?: true, // the picked take on this script, approved // off?: true, // kept, but the item plays un-narrated // // the mix, per post (absent: render.postNarration's, else the defaults): -// lead?, tail?, ramp?, linger?, clip?, wet?, lowpassHz?, duck?, short?, attach?, lufs? +// lead?, tail?, ramp?, linger?, clip?, wet?, lowpassHz?, duck?, short?, attach?, lufs?, rate? // window?: { media, start, end, score, reason, at } // why `posts fit` chose the attachment's span // } // @@ -104,6 +104,13 @@ export const derivedFileOf = (postId, n, op, engine) => `${takesDirOf(postId)}/t * lufs -21 the voice is levelled to this before the narrator's * compressor (-21 LUFS is where Orpheus `zac` reads: the * demo's chain was tuned there) + * rate 1 the READ's speed (operator, 3 Nov: "read everything the + * slightest bit faster"): the voice time-stretched by this, + * its pitch kept (ffmpeg atempo; Play: playbackRate with + * preservesPitch) -- the attachment untouched. Every second + * the item takes from a take (its read, its parts, the + * muffle's schedule, the item's length) is the take's + * divided by it (readSecondsOf) * engine orpheus, voice zac what a new take is synthesized with */ export const POST_NARRATION_DEFAULTS = Object.freeze({ @@ -118,6 +125,7 @@ export const POST_NARRATION_DEFAULTS = Object.freeze({ short: "hold", attach: "under", lufs: -21, + rate: 1, engine: "orpheus", voice: "zac", }); @@ -131,6 +139,7 @@ export const POST_NARRATION_LIMITS = Object.freeze({ lowpassHz: [100, 8000], lufs: [-40, -10], speed: [0.5, 2], + rate: [0.8, 1.5], /** A script is the whole post read aloud (operator, 2 Nov: never excerpted); the editor's tts op takes 20,000. */ scriptChars: 20000, takes: 50, @@ -149,7 +158,7 @@ export const POST_NARRATION_LIMIT = 0.95; export const POST_NARRATION_CLIP = Object.freeze(["read", "full"]); -const MIX_KEYS = ["lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs"]; +const MIX_KEYS = ["lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz", "duck", "short", "attach", "lufs", "rate"]; // `attach` is one post's (it decides the card's layout, which is drawn from the entry alone). const RENDER_KEYS = new Set([...MIX_KEYS.filter((k) => k !== "attach"), "engine", "voice"]); const ITEM_KEYS = new Set([...MIX_KEYS, "script", "excerpt", "engine", "voice", "speed", "takes", "pick", "approved", "off", "window"]); @@ -189,6 +198,15 @@ export function pickedTake(entry) { return isObj(t) && typeof t.file === "string" && fin(t.seconds) && t.seconds > 0 ? { ...t, index: i } : null; } +/** The read's speed for a post (its `rate`, else the cut's, else 1), held to its limits. */ +export function narrationRateOf(entry, render) { + const r = Number(postNarrationKnobs(entry, render).rate); + return numIn(r, POST_NARRATION_LIMITS.rate) ? r : 1; +} + +/** A take's seconds AS THE ITEM PLAYS THEM: its length divided by the read's rate. */ +export const readSecondsOf = (seconds, rate = 1) => round3(Number(seconds) / (fin(rate) && rate > 0 ? rate : 1)); + /** Is the item narrated -- a take picked, and not switched off? */ export const isNarrated = (entry) => entry?.type === "post" && entry?.narration?.off !== true && !!pickedTake(entry); @@ -203,7 +221,7 @@ export function readSpanSeconds(entry, render) { const t = pickedTake(entry); if (!t) return null; const k = postNarrationKnobs(entry, render); - return round3(k.lead + t.seconds + k.tail + k.linger); + return round3(k.lead + readSecondsOf(t.seconds, narrationRateOf(entry, render)) + k.tail + k.linger); } /** The postId a post item names (`<channel>/<postId>`). */ @@ -230,18 +248,22 @@ export function nextTakeNumber(entry, files = []) { /** * THE MIX's SCHEDULE on the item's clock, for a narrated item: when the * voice starts and ends, when the muffle ends and the clean sound is back. - * `seconds` the take's length. The render and Play both read this. + * `seconds` the read's length on the item's clock (the take's, divided by + * `rate`); `takeSeconds` the take's own. The render and Play both read this. * - * @returns {{ at: number, seconds: number, voiceEnd: number, rampEnd: number, wet: number, lowpassHz: number, duck: boolean, attach: string, lufs: number }} + * @returns {{ at: number, seconds: number, takeSeconds: number, rate: number, voiceEnd: number, rampEnd: number, wet: number, lowpassHz: number, duck: boolean, attach: string, lufs: number }} */ export function narrationSchedule(entry, render) { const t = pickedTake(entry); const k = postNarrationKnobs(entry, render); - const seconds = t ? t.seconds : 0; + const rate = narrationRateOf(entry, render); + const seconds = t ? readSecondsOf(t.seconds, rate) : 0; const voiceEnd = round3(k.lead + seconds + k.tail); return { at: round3(k.lead), seconds: round3(seconds), + takeSeconds: round3(t ? t.seconds : 0), + rate, voiceEnd, rampEnd: round3(voiceEnd + k.ramp), wet: k.wet, @@ -299,10 +321,12 @@ export function narrationLevelDb(measured, target) { * * media -> asplit -> wet: lowpass F twice, gain W until voiceEnd, ramping to 0 over the ramp * -> dry: 0 until voiceEnd, ramping to 1 over the ramp - * voice -> resampled, stereo, levelled, the narrator's compressor and make-up gain, delayed by lead + * voice -> resampled, sped up by the read's rate (atempo: its pitch kept), stereo, levelled, the narrator's + * compressor and make-up gain, delayed by lead * wet + dry + voice -> amix (no normalising, the item's length) -> limiter * - * Without `duck`, the media's sound plays as it is under the voice. + * Without `duck`, the media's sound plays as it is under the voice. The + * attachment's sound is never sped: only the voice is (`sch.rate`). */ export function postNarrationFilters({ media, voice, out, sch, gainDb = 0, audioRate = 48000 }) { const E = f6(sch.voiceEnd); @@ -310,8 +334,10 @@ export function postNarrationFilters({ media, voice, out, sch, gainDb = 0, audio const W = f6(sch.wet); const F = Math.round(sch.lowpassHz); const ms = Math.round(sch.at * 1000); + const rate = fin(sch.rate) && sch.rate > 0 ? sch.rate : 1; + const tempo = Math.abs(rate - 1) > 1e-6 ? `atempo=${f6(rate)},` : ""; const parts = [ - `[${voice}]aresample=${audioRate},aformat=sample_fmts=fltp:channel_layouts=stereo,volume=${f6(gainDb)}dB,${POST_NARRATOR_COMPRESSOR},volume=${f6(POST_NARRATOR_MAKEUP)},adelay=${ms}:all=1[pnv]`, + `[${voice}]aresample=${audioRate},${tempo}aformat=sample_fmts=fltp:channel_layouts=stereo,volume=${f6(gainDb)}dB,${POST_NARRATOR_COMPRESSOR},volume=${f6(POST_NARRATOR_MAKEUP)},adelay=${ms}:all=1[pnv]`, ]; if (sch.duck) { parts.push( @@ -428,7 +454,7 @@ function scriptErrors(s, where) { function mixErrors(o, where) { const errors = []; - for (const k of ["lead", "tail", "ramp", "linger", "wet", "lowpassHz", "lufs"]) { + for (const k of ["lead", "tail", "ramp", "linger", "wet", "lowpassHz", "lufs", "rate"]) { if (o[k] !== undefined && !numIn(o[k], POST_NARRATION_LIMITS[k])) errors.push(`${where}.${k} must be ${POST_NARRATION_LIMITS[k][0]}–${POST_NARRATION_LIMITS[k][1]}`); } if (o.duck !== undefined && typeof o.duck !== "boolean") errors.push(`${where}.duck must be true or false`); @@ -599,13 +625,15 @@ export function scriptParts(script, max = POST_PART_WORDS) { /** The pause before part `k` of `parts` (0 before the first). */ export const partGapBefore = (parts, k) => (k === 0 ? 0 : parts[k].para !== parts[k - 1].para ? POST_PART_GAP.para : POST_PART_GAP.inside); +/** Where part `p` of the picked take starts on the item's clock (its start in the take, at the read's rate). */ +export const partStartOnItem = (sch, p) => round3((sch?.at ?? 0) + readSecondsOf(p.start, sch?.rate ?? 1)); + /** The part being read at item second `s` (the picked take's parts, on the item's clock), or null. */ export function partAt(entry, sch, s) { const t = pickedTake(entry); const parts = Array.isArray(t?.parts) ? t.parts : []; if (!parts.length || !sch) return null; - const local = s - sch.at; let cur = null; - for (const p of parts) if (local >= p.start - 0.05) cur = p; + for (const p of parts) if (s >= partStartOnItem(sch, p) - 0.05) cur = p; return cur; } diff --git a/umtool/report-to-video/post-narration.test.mjs b/umtool/report-to-video/post-narration.test.mjs @@ -6,7 +6,7 @@ import { test } from "node:test"; import { POST_NARRATION_DEFAULTS, draftScript, dryGainAt, isNarrated, mixPhaseAt, narrationLevelDb, narrationSchedule, nextTakeNumber, pickedTake, speakShouts, postNarrationDisclosure, postNarrationFilters, postNarrationKnobs, readSpanSeconds, speakableText, takeFileOf, - validatePostNarration, validatePostNarrationRender, wetGainAt, + validatePostNarration, validatePostNarrationRender, wetGainAt, narrationRateOf, partAt, partStartOnItem, readSecondsOf, } from "./post-narration.mjs"; import { POST_PICTURE_MIN, mediaTimeAt, postItemFiles, postItemPlan, postItemSeconds, postLayout, ruleSeconds, validatePostItem } from "./post-item.mjs"; import { postSegmentArgs } from "./post-render.mjs"; @@ -154,6 +154,47 @@ test("THE MIX's FILTERS are mix.sh's chain: lowpass 650 twice at 0.30, the ramp, assert.equal(narrationLevelDb(-50, -21), 12); }); +test("THE READ's RATE (operator, 3 Nov: \"read everything the slightest bit faster\"): the voice atempo'd, every take second divided by it", () => { + assert.equal(POST_NARRATION_DEFAULTS.rate, 1); + const media = [video({ seconds: 30.03 })]; + const slow = post({ media, narration: narr(13.5) }); + const cutFast = { postNarration: { rate: 1.08 } }; + // The cut's rate, a post's own over it, the default 1. + assert.equal(narrationRateOf(slow), 1); + assert.equal(narrationRateOf(slow, cutFast), 1.08); + assert.equal(narrationRateOf(post({ media, narration: narr(13.5, { rate: 1.25 }) }), cutFast), 1.25); + assert.equal(readSecondsOf(13.5, 1.08), 12.5); + // The item's length shrinks by the read's (lead + read/rate + tail + linger), the attachment cut to it. + assert.equal(readSpanSeconds(slow), 16); + assert.equal(readSpanSeconds(slow, cutFast), 15); + const p1 = postItemPlan(slow); + const p2 = postItemPlan(slow, cutFast); + assert.equal(p1.total, 16); + assert.equal(p2.total, 15); + assert.equal(p2.steps[0].seconds, 15); + assert.equal(postItemSeconds(slow, cutFast), 15); + // The muffle's schedule on the item's clock: the read ends sooner, the take's own length kept beside it. + const sch = p2.narration; + assert.deepEqual([sch.at, sch.seconds, sch.takeSeconds, sch.rate, sch.voiceEnd, sch.rampEnd], [0.4, 12.5, 13.5, 1.08, 13.2, 14]); + // A take in parts: each part's start on the item's clock is its start in the take over the rate. + const parts = [{ n: 1, start: 0, seconds: 5 }, { n: 2, start: 5.4, seconds: 8.1 }]; + const e = post({ media, narration: { ...narr(13.5), takes: [{ ...narr(13.5).takes[0], parts }] } }); + const s2 = narrationSchedule(e, cutFast); + assert.equal(partStartOnItem(s2, parts[1]), 5.4); + assert.equal(partAt(e, s2, 5.3).n, 1); + assert.equal(partAt(e, s2, 5.4).n, 2); + assert.equal(partStartOnItem(narrationSchedule(e), parts[1]), 5.8); + // The filter graph: atempo on the VOICE only (the pitch kept); at 1 the chain is as it was. + const f = postNarrationFilters({ media: "pm", voice: "5:a", out: "a", sch }); + assert.match(f[0], /^\[5:a\]aresample=48000,atempo=1\.08,aformat=/); + assert.ok(f.slice(1).every((x) => !x.includes("atempo"))); + assert.doesNotMatch(postNarrationFilters({ media: "pm", voice: "5:a", out: "a", sch: p1.narration })[0], /atempo/); + // Held to 0.8-1.5, by the validator of the cut's and of a post's. + assert.deepEqual(validatePostNarrationRender({ postNarration: { rate: 1.08 } }), []); + assert.match(validatePostNarrationRender({ postNarration: { rate: 2 } }).join(), /rate must be 0\.8–1\.5/); + assert.match(validatePostNarration(post({ narration: narr(5, { rate: 0.5 }) })).join(), /narration\.rate must be 0\.8–1\.5/); +}); + test("the segment's argv carries the take as an input and the mix after the item's own sound", () => { const e = post({ media: [video()], narration: narr(18.42) }); const plan = postItemPlan(e);