// NARRATED POST ITEMS (report-to-video/post-narration.mjs): a posts cut whose // first item reads a take over its video (post-narration.spec.ts). // // post-narration-fixture p-vid a 4 s video with a 440 Hz tone, narrated // by a 2 s take (a 262 Hz tone): the muffle // from 0 to lead + 2 + tail = 2.7 s, the ramp // to 3.5 s, clean after; a long script of two // paragraphs (two parts to record) // p-pics four pictures, un-narrated: one card, the // pictures cycling beside it // p-txt words only, a script and no take // the deck on. WRITES its manifest: the spec puts // it back before each test. // // Synthetic, like every fixture. import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import { spawnSync } from "node:child_process"; import path from "node:path"; const ff = (args) => { const r = spawnSync("ffmpeg", ["-v", "error", "-y", ...args]); if (r.status !== 0) throw new Error(`ffmpeg ${args.join(" ")}: ${String(r.stderr)}`); }; /** * Every file the fixture writes under its narration/, relative to it. Nothing * else under narration/ is the fixture's: it is a take, a part, a cache or a * trash a spec made. */ export const POST_NARRATION_OWN_FILES = ["posts/11/take-1.orpheus-zac.wav", "posts/11/take-1.orpheus-zac.wav.heard.json"]; /** * Put the fixture's narration/ back to what it built, removing what any spec * left there. Several specs share this project (long-reads writes a take-7 of * p-11 and re-reads it into more), and a new take is numbered past every * take-N on disk (report-to-video/post-narration.mjs nextTakeNumber) -- so * without this, which spec ran first decided post-narration's take numbers. * @param {string} dir the project's directory */ export function resetPostNarrationFiles(dir) { const root = path.join(dir, "narration"); const keep = new Set(POST_NARRATION_OWN_FILES.map((f) => path.join(root, f))); const prune = (d) => { let entries = []; try { entries = readdirSync(d, { withFileTypes: true }); } catch { return false; } let kept = false; for (const e of entries) { const p = path.join(d, e.name); if (e.isDirectory() && !e.isSymbolicLink()) { if (prune(p)) kept = true; else rmSync(p, { recursive: true, force: true }); } else if (keep.has(p)) kept = true; else rmSync(p, { force: true }); } return kept; }; prune(root); } /** @param {{ reports: string, deckManifest: Function }} o */ export function makePostNarrationFixture({ reports, deckManifest }) { const name = "post-narration-fixture"; const dir = path.join(reports, name); const media = path.join(dir, "posts-media", "narrchan-x"); for (const id of ["11", "12"]) mkdirSync(path.join(media, id), { recursive: true }); ff([ "-f", "lavfi", "-i", "testsrc=size=320x180:rate=30:duration=4", "-f", "lavfi", "-i", "sine=frequency=440:duration=4", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-ar", "48000", "-ac", "2", "-shortest", path.join(media, "11", "11_1.mp4"), ]); for (const [k, c] of ["red", "green", "blue", "yellow"].entries()) { ff(["-f", "lavfi", "-i", `color=c=${c}:size=320x180`, "-frames:v", "1", path.join(media, "12", `12_${k + 1}.png`)]); } const takes = path.join(dir, "narration", "posts", "11"); mkdirSync(takes, { recursive: true }); ff(["-f", "lavfi", "-i", "sine=frequency=262:sample_rate=48000:duration=2", "-ac", "1", "-c:a", "pcm_s16le", path.join(takes, "take-1.orpheus-zac.wav")]); // What the editor's stubbed transcription "hears" in that take (a word zoom's word timings; editor-stub-case-stages.mjs). writeFileSync(path.join(takes, "take-1.orpheus-zac.wav.heard.json"), JSON.stringify([["The", 0.1, 0.3], ["video", 0.35, 0.7], ["speaks", 0.75, 1.1], ["for", 1.15, 1.3], ["itself.", 1.35, 1.8]].map(([w, start, end]) => ({ w, start, end })))); const base = (id, text, o = {}) => ({ type: "post", id, post: `narrchan-x/${id.slice(2)}`, platform: "x", author: "Narr Subject", handle: "narrsubject", date: "2026-10-30T10:00:00.000Z", text, url: `https://x.com/narrsubject/status/${id}`, engagement: { likes: 4 }, subjects: ["narrsubject"], ...o, }); const timeline = [ base("p-11", "The video speaks for itself.", { post: "narrchan-x/11", media: [{ src: "posts-media/narrchan-x/11/11_1.mp4", kind: "video", seconds: 4, width: 320, height: 180, audio: true }], narration: { script: "The video speaks for itself.\n\nAnd a second paragraph, read as its own part.", takes: [{ file: "narration/posts/11/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 2, script: "The video speaks for itself.", at: "2026-11-02T00:00:00.000Z" }], pick: 0, }, }), base("p-12", "Four pictures of the thing, one after another, while this is read.", { post: "narrchan-x/12", media: [1, 2, 3, 4].map((k) => ({ src: `posts-media/narrchan-x/12/12_${k}.png`, kind: "image", width: 320, height: 180 })), }), base("p-13", "Words only, waiting for a voice.", { post: "narrchan-x/13", narration: { script: "Words only, waiting for a voice." } }), ]; const m = deckManifest(name, "The Post Narration Fixture", timeline); m.provenance = { ...m.provenance, channelSlug: "narrchan-x" }; writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); return { dir }; }