// postYell.mjs: THE CAPS YELLED -- which words (his caps found in the read's word timings, acronyms and slurs left // flat, a piece's caps only in the words that read it), the spans (padded, a run merged), the plan's refusals and // chain rules, and the file: its length the source's, the spans louder by the lift (measured), the rest untouched, // its loudness within 1 LU, a derived take picked in one write; chained with the tempo either way. import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { validatePostItem } from "umtool-report-to-video/post-item"; import { acronymWhy, capsOfRead, isCapsWord, spansRms, yellArgs, yellPlan, yellSpans, yellTake } from "./postYell.mjs"; import { rereadTake } from "./postReread.mjs"; import { postsCommand } from "./postsCli.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-yell-")); after(() => rm(ROOT, { recursive: true, force: true })); const REPORTS = path.join(ROOT, "reports"); const TEXT = "The moment THEY have your Dox ITS ALREADY TOO LATE, the FBI will not help.\n\nYou can HIDE all you want."; const SCRIPT = "The moment they have your Dox its already too late, the FBI will not help.\n\nYou can hide all you want."; // One word a 0.4 s slot from 0.2 s; the second paragraph from 6.2 s. const words = () => { const ws = SCRIPT.split(/\s+/); return ws.map((w, i) => { const at = i < 15 ? 0.2 + i * 0.4 : 6.2 + (i - 15) * 0.4; return { w, start: Math.round(at * 1000) / 1000, end: Math.round((at + 0.32) * 1000) / 1000 }; }); }; const item = (o = {}) => ({ type: "post", id: "p-7", post: "subj-x/7", platform: "x", author: "THE SUBJECT", handle: "Subject", date: "2026-10-30T10:00:00.000Z", text: TEXT, narration: { script: SCRIPT, takes: [{ file: "narration/posts/7/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 9, script: SCRIPT, words: words(), parts: [{ n: 1, para: 0, text: SCRIPT.split("\n\n")[0], start: 0.2, seconds: 5.8 }, { n: 2, para: 1, text: SCRIPT.split("\n\n")[1], start: 6.2, seconds: 2.4 }] }], pick: 0 }, ...o, }); test("WHICH WORDS: caps of two letters or more; acronyms and letter-runs left flat; his caps found in the read's words", () => { assert.deepEqual(["ITS", "I'LL", "ISN'T", "I", "10x", "Dox", "FBI's"].map(isCapsWord), [true, true, true, false, false, false, true]); assert.deepEqual(["FBI", "DM", "KF", "TV", "BS", "NEVER", "OMG", "PST"].map(acronymWhy), ["acronym", "acronym", "acronym", "acronym", "acronym", null, "acronym", "acronym"]); assert.equal(acronymWhy("KDR"), "letters"); const c = capsOfRead(item(), item().narration.takes[0]); assert.deepEqual(c.yell.map((x) => [x.k, x.src]), [[2, "THEY"], [6, "ITS"], [7, "ALREADY"], [8, "TOO"], [9, "LATE"], [17, "HIDE"]]); assert.deepEqual(c.skip.map((x) => [x.src, x.why]), [["FBI", "acronym"]]); // Spans: padded, a run of caps one span. assert.deepEqual(yellSpans(words(), c.yell.map((x) => x.k)), [[0.97, 1.36], [2.57, 4.16], [6.97, 7.36]]); // No word timings: refused in the plan's words (the --words pass named). const bare = item(); delete bare.narration.takes[0].words; assert.throws(() => yellPlan(bare), /no word timings to find its caps by \(umtool posts narrate
p-7 --words\)/); assert.throws(() => yellPlan(item({ text: SCRIPT })), /no word of its read is in caps/); }); test("A PIECE's caps are looked for only in the words that read it: a caps word of the post he answers is never his", () => { const e = item({ text: "you can hide all you want.", parents: [{ id: "9", author: "Other", handle: "other", text: "The moment THEY have your Dox ITS ALREADY TOO LATE, the FBI will not help." }] }); const t = e.narration.takes[0]; t.parts[0].role = "parent:0"; t.parts[1].role = "post"; const c = capsOfRead(e, t); assert.deepEqual(c.yell.map((x) => [x.src, x.where]), [["THEY", "parent:0"], ["ITS", "parent:0"], ["ALREADY", "parent:0"], ["TOO", "parent:0"], ["LATE", "parent:0"]]); }); test("the ffmpeg: the voice split, the raised branch shaped and limited, the two crossfaded by the spans' envelope in frames", () => { const p = yellPlan(item()); const fc = yellArgs("/in.wav", "/o.wav", p, { rate: 24000, layout: "mono" })[8]; assert.match(fc, /asetnsamples=n=64:p=0,asplit=2\[yd\]\[yw\]/); assert.match(fc, /equalizer=f=3200:t=o:w=1\.3:g=3,equalizer=f=1100:t=o:w=1:g=1\.5,acompressor=threshold=0\.063:ratio=2\.5/); assert.match(fc, /alimiter=limit=0\.94:attack=2:release=40:level=false:latency=1/); assert.match(fc, /between\(t,0\.920,1\.410\)\*clip\(min\(\(t-0\.920\)\/0\.050,\(1\.410-t\)\/0\.050\),0,1\)/); assert.match(fc, /amix=inputs=2:normalize=0:duration=first,atrim=end_sample=216000\[out\]/); assert.deepEqual(p.steps[0].spans, p.spans); }); async function project(name, timeline) { const dir = path.join(REPORTS, name); await mkdir(path.join(dir, "narration", "posts", "7"), { recursive: true }); // A voice-like read: a 180 Hz buzz with harmonics, syllable-pulsed, at about -21 LUFS. execFileSync("ffmpeg", ["-nostdin", "-loglevel", "error", "-y", "-f", "lavfi", "-i", "aevalsrc='0.12*(sin(2*PI*180*t)+0.5*sin(2*PI*360*t)+0.3*sin(2*PI*2900*t))*(0.55+0.45*sin(2*PI*4*t))':s=24000:d=9", path.join(dir, "narration", "posts", "7", "take-1.orpheus-zac.wav")]); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "" }, render: { width: 1920, height: 1080, fps: 30 }, timeline }, null, 2)); return { id: name, dir }; } const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); test("YELLED: the file as long as its source, its spans louder by the lift (measured), outside them untouched, loudness within 1 LU; picked; re-yelled from the take before; chained with a tempo either way", async () => { const p = await project("yell", [item()]); let e = (await manifest(p)).timeline[0]; const r = await yellTake(p, e, {}); const t = r.take; assert.match(t.file, /take-2\.yell-orpheus\.wav$/); assert.ok(Math.abs(t.seconds - 9) < 0.01, `length ${t.seconds}`); assert.deepEqual([t.source.from, t.steps[0].op, t.steps[0].params.style], ["take-1.orpheus-zac", "yell", "raise"]); assert.deepEqual(t.words, words(), "its timings kept"); const src = path.join(p.dir, "narration/posts/7/take-1.orpheus-zac.wav"); const out = path.join(p.dir, t.file); const lift = (await spansRms(out, r.plan.spans)) - (await spansRms(src, r.plan.spans)); // A third of this read is caps: the loudness rule (≤ 1 LU over its source) lowers the lift asked for, and says so. assert.ok(lift > 1.5 && lift < 7 && (r.plan.gain < 5.5 || lift > 3.5), `the spans' lift ${lift} dB at ${r.plan.gain} dB asked`); assert.equal(t.steps[0].params.gain, r.plan.gain); const flat = (await spansRms(out, [[4.6, 6.6]])) - (await spansRms(src, [[4.6, 6.6]])); assert.ok(Math.abs(flat) < 0.2, `outside the spans: ${flat} dB`); assert.ok(r.plan.lufs.after - r.plan.lufs.base <= 1.05, `loudness ${r.plan.lufs.base} → ${r.plan.lufs.after}`); e = (await manifest(p)).timeline[0]; assert.equal(e.narration.pick, 1); assert.deepEqual(validatePostItem(e), []); // Yelled again: from the take before (never raised twice). assert.equal(yellPlan(e).take.file, "narration/posts/7/take-1.orpheus-zac.wav"); // Then re-timed: the yell's take is cut, the yell kept, the words scaled. const rt = await rereadTake(p, e, { tempo: { 1: 1.3 } }); assert.equal(rt.take.source.from, "take-2.yell-orpheus"); e = (await manifest(p)).timeline[0]; // A yell further up the chain: refused (pick the take before it). assert.throws(() => yellPlan(e), /made from a yelled one/); // The other order: re-timed first, then yelled (posts yell): its spans on the tempo's word timings. const q = await project("yell2", [item()]); let e2 = (await manifest(q)).timeline[0]; await rereadTake(q, e2, { tempo: { 1: 1.3 } }); const lines = []; const code = await postsCommand(["yell", "yell2", "p-7"], { root: REPORTS, out: (s) => lines.push(s), err: (s) => lines.push(s) }); assert.equal(code, 0, lines.join("\n")); assert.match(lines.join("\n"), /p-7: yelled THEY ITS ALREADY TOO LATE HIDE \(3 span\(s\)/); e2 = (await manifest(q)).timeline[0]; const y = e2.narration.takes[e2.narration.pick]; assert.equal(y.steps[0].op, "yell"); assert.ok(y.steps[0].spans[1][1] < 4.16 / 1.0 && y.steps[0].spans[1][0] < 2.57, "the spans are the re-timed words'"); // posts yell --dry-run: the list. const dry = []; await postsCommand(["yell", "yell2", "--dry-run"], { root: REPORTS, out: (s) => dry.push(s), err: (s) => dry.push(s) }); assert.match(dry.join("\n"), /p-7: would yell THEY ITS ALREADY TOO LATE HIDE; flat: FBI \(acronym\)/); });