// THE READS FIXTURE (lane reads-find): one project in a temp dir with every kind of read -- a post's script read alone, // a thread read with a screen (its parent, the quoted post, his words, two screen lines), a recorded read, and a // narrated card with a reading kept beside the build -- and a cast whose character reads the single post. Invented // people and places; the thread item is the reading pin's (post-reading-pin.fixtures.mjs), so the drawn hashes apply. import { mkdir, readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { draftScript } from "umtool-report-to-video/post-narration"; import { narrationsOf } from "umtool-report-to-video/narration"; import { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"; import { VOICE_B, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"; import { threadItem } from "../../report-to-video/post-reading-pin.fixtures.mjs"; import { PROJECT_KINDS } from "../projects/kinds.mjs"; export const FERRY_TEXT = "The ferry runs at noon from the north pier.\n\nBring a coat for the crossing to the north shore."; export const CARD_TEXT = "Six months later, the north pier reopened."; export const LIVELY = { temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 }; export const wavOf = async (file, seconds = 0.6) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...VOICE_B, seconds }), { before: 0.1, after: 0.1 }))); }; /** The cast: the single post's author reads as Ferry Teller (orpheus:tara), with `tuning` when given. */ export const castDoc = (tuning = null) => ({ format: "umtool-cast", version: 2, characters: [{ id: "ferry", name: "Ferry Teller", handles: ["invented_ferry"], synthetic: { voice: "orpheus:tara", ...(tuning ? { tuning } : {}) } }], }); export function singlePost() { const script = draftScript(FERRY_TEXT).script; return { type: "post", id: "p-1", post: "ferry-x/1", platform: "x", author: "Ferry Teller", handle: "invented_ferry", date: "2026-10-30T10:00:00.000Z", text: FERRY_TEXT, narration: { script, pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-tara.wav", engine: "orpheus", voice: "tara", seconds: 6.2, script, tuning: { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3 }, reading: 0 }] }, }; } /** The reading pin's thread item as p-2, its parent one paragraph long (so its read says it whole, as a press would). */ export function threadPost() { const e = threadItem(); // Each part its own file in the parts cache, as a thread read keeps them (made on disk by readsProject). const takes = e.narration.takes.map((t) => ({ ...t, parts: t.parts.map((x) => ({ ...x, file: `narration/parts-cache/fixture-${x.n}.wav` })) })); return { ...e, id: "p-2", parents: e.parents.map((x) => ({ ...x, text: x.text.split("\n\n")[0] })), narration: { ...e.narration, takes } }; } export function recordedPost() { return { type: "post", id: "p-3", post: "ferry-x/3", platform: "x", author: "Pier Watch", handle: "invented_pier", date: "2026-10-30T11:00:00.000Z", text: "The north pier is closed today.", narration: { script: "The north pier is closed today.", pick: 0, takes: [{ file: "narration/posts/3/take-1.recorded-operator.wav", engine: "recorded", voice: "operator", seconds: 2.4, script: "The north pier is closed today.", source: { kind: "recorded", voice: "operator" } }] }, }; } export const card = () => ({ type: "card", id: "c-1", seconds: "auto", heading: "Later", narration: { text: CARD_TEXT, engine: "orpheus", voice: "leo" } }); /** * The project: `p` under the reports root `/`, the cast in `//.umtool/cast.json`, the takes' * files on disk and the card's reading kept in out/narration/. Returns `{ id: "p", dir, root }` (`root` the reports root). */ export async function readsProject(root, name, { cast = castDoc(), timeline = null } = {}) { const top = path.join(root, name); const dir = path.join(top, "p"); await mkdir(path.join(dir, "narration"), { recursive: true }); await mkdir(path.join(top, ".umtool"), { recursive: true }); await writeFile(path.join(top, ".umtool", "cast.json"), JSON.stringify(cast, null, 1)); const tl = timeline ?? [singlePost(), threadPost(), recordedPost(), card()]; const manifest = { schemaVersion: 1, slug: name, title: name, render: { width: 1920, height: 1080, fps: 30, postNarration: { engine: "orpheus", voice: "zac" } }, timeline: tl }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest, null, 2)); // A project of the reports root `top` (projects/core.mjs walks it): `umtool … p` finds it there. await writeFile(path.join(dir, "project.json"), `${JSON.stringify({ kind: PROJECT_KINDS.find((k) => k.makesTakes).id, title: name })}\n`); for (const e of tl) for (const t of e?.narration?.takes ?? []) { await wavOf(path.join(dir, ...t.file.split("/"))); for (const x of t.parts ?? []) if (typeof x.file === "string") await wavOf(path.join(dir, ...x.file.split("/"))); } for (const n of narrationsOf(manifest)) await keepCardReading(dir, n); return { id: "p", dir, root: top }; } /** A card's reading kept beside the build (narration-store.mjs's shape): its record and its sound. */ export async function keepCardReading(dir, n, { createdAt = "2026-11-01T10:00:00.000Z" } = {}) { const store = path.join(dir, "out", "narration"); await wavOf(path.join(store, `${n.key}.wav`), 1.2); await writeFile(path.join(store, `${n.key}.json`), JSON.stringify({ id: n.id, key: n.key, text: n.text, engine: n.engine, voice: n.voice, speed: 1, seconds: 1.4, createdAt, ...(n.tuning ? { askedTuning: n.tuning } : {}), ...(n.reading ? { askedReading: n.reading } : {}) })); } export const readManifestOf = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"));