Archilyzer · Source

archilyzer

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

commit 64ae1b6831703d90d0241226b337248f8b7d7d1a
parent 7d99aa4f3ff34772512f0222bf79fffc17d76154
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 15:28:58 -0500

postTakeAsk.mjs: the bench's take op and `posts narrate --take` build one ask (reads-find ruling 3)

The voice, speed, tuning (and whose it is), the line's own values, and what is said -- one module,
called by the bench's take op and by makeTake. makeTake gains `benchSlurs` (the re-read queue's):
the bench's slur rule (a cut that beeps has the slur left out, as the bench cannot word-time a read
as it is made), so the queue's read of a post asks the editor exactly what a bench press asks.
benchQueueParity.test.mjs pins it, the slur case included. The S2 no-tuning pin is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mumtool/app/api/report/post-narration/route.ts | 48+++++++++++++++++++-----------------------------
Aumtool/lib/report/benchQueueParity.test.mjs | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postNarrationCli.mjs | 48+++++++++++++++++++-----------------------------
Aumtool/lib/report/postTakeAsk.mjs | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 161 insertions(+), 58 deletions(-)

diff --git a/umtool/app/api/report/post-narration/route.ts b/umtool/app/api/report/post-narration/route.ts @@ -1,7 +1,7 @@ import { mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { - POST_DERIVE_OPS, POST_DERIVE_ROUTES, derivedFileOf, isNarrated, nextReadingOf, nextTakeNumber, pickedTake, postIdOf, postNarrationKnobs, takeFileOf, takeIdOf, takesDirOf, + POST_DERIVE_OPS, POST_DERIVE_ROUTES, derivedFileOf, isNarrated, nextReadingOf, nextTakeNumber, pickedTake, postIdOf, takeFileOf, takeIdOf, takesDirOf, } from "umtool-report-to-video/post-narration"; import { postItemPlan } from "umtool-report-to-video/post-item"; import { jobState, resultLine, startJob } from "@/lib/research/case-editor"; @@ -19,10 +19,9 @@ import { withTakeScope } from "@/lib/report/takeScope.mjs"; import { isTakeId } from "@/lib/report/takes.mjs"; import { keepRecording, RECORD_LABEL_RE } from "@/lib/report/postRecord.mjs"; import { fitPostItem } from "@/lib/report/postFit.mjs"; -import { itemReadVoice } from "@/lib/report/readVoice.mjs"; +import { askBody, benchSlurVoice, postTakeAskOf } from "@/lib/report/postTakeAsk.mjs"; import { projectRedaction } from "@/lib/report/postRedaction.mjs"; import { spokenRead } from "umtool-report-to-video/post-redact"; -import { tuningAskOf } from "umtool-report-to-video/post-say"; import { characterById, recordedPresetOf, shownNameOf } from "umtool-report-to-video/cast"; import { readLayers, recordedTrimFor } from "@/lib/report/characterLayers.mjs"; import { convertAskOf, derivePitchOf, deriveRefusalOf, stepPitchOf } from "@/lib/report/derivePitch.mjs"; @@ -32,8 +31,8 @@ import { renderWaitSentence } from "@/lib/report/renderMode.mjs"; export const dynamic = "force-dynamic"; -/** The slur filter's voice for a take synthesized on the bench: beep falls back to skip (no word timings yet to beep by). */ -const benchVoice = (red: { slurs?: { voice?: string } | null } | null) => (red?.slurs?.voice === "beep" ? "skip" : undefined) as "skip" | undefined; +/** The slur filter's voice for a take synthesized on the bench: beep falls back to skip (lib/report/postTakeAsk.mjs, one rule). */ +const benchVoice = (red: { slurs?: { voice?: string } | null } | null) => benchSlurVoice(red) as "skip" | undefined; // A NARRATED POST ITEM's bench (report-to-video/post-narration.mjs; knobs.md, // "A narrated post item"): the recording session, the takes, the mix's knobs. @@ -397,7 +396,6 @@ async function postHere(request: Request) { } if (body.op === "take") { // The EDITOR synthesizes (its tts op, a job on its queue); the take is kept when the job is done (GET ?job). - const k = postNarrationKnobs(e, (m.render ?? {}) as Record<string, unknown>); const script = String(body.script ?? e.narration?.script ?? "").trim(); if (!script) return Response.json({ error: `${id} has no script to read` }, { status: 400 }); // Its tuning and reading (another reading of the same words): refused here in the editor's words, sent as asked. @@ -425,41 +423,33 @@ async function postHere(request: Request) { // .ask.json) away, so a failed press never answers 409 for two minutes. let askFile: string | null = null; try { - // The voice: the one asked for, the item's own character, the project's characters and voice map, the CAST, the - // narrator's -- a single read's rule (readVoice.mjs). - const said = await itemReadVoice(r.project, e, { - render: (m.render ?? {}) as Record<string, unknown>, + // THE ASK (lib/report/postTakeAsk.mjs, the one `posts narrate --take` and the re-read queue build too; lane + // reads-find): the voice (the one asked for, the item's own character, the project's characters and voice map, + // the CAST, the narrator's), its speed (the one asked for, else the item's own, else its character's; none for + // Orpheus), its tuning (the line's own -- the Tune -- over its character's, field by field; a character with no + // tuning asks as it always did) and what the voice SAYS (the redaction, the slurs, the lexicon; the script kept + // as written). The bench cannot word-time a take as it is made, so a beep falls back to skip (benchSlurVoice). + const red = await projectRedaction(r.project.dir, m); + const A = await postTakeAskOf(r.project, e, { + render: (m.render ?? {}) as Record<string, unknown>, script, engine: typeof body.engine === "string" && body.engine ? body.engine : null, voice: typeof body.voice === "string" && body.voice ? body.voice : null, + speed: body.speed === undefined || body.speed === null ? null : Number(body.speed), + tuning: tuned?.ok ? tuned.value : null, reading, red, slurVoice: benchSlurVoice(red), }); - const engine = String(said.engine ?? k.engine); - const voice = String(said.voice ?? k.voice); + const { engine, voice, tuning, tuningAsked } = A; const pid = postIdOf(e); const dir = path.join(r.project.dir, ...takesDirOf(pid).split("/")); await mkdir(dir, { recursive: true }); const rel = takeFileOf(pid, nextTakeNumber(e, await readdir(dir).catch(() => [])), engine, voice); - // Its speed: the one asked for, else the item's own (`narration.speed`), else its character's (the synthetic - // preset's that answered for the voice) -- makeTake's order. - const askedSpeed = body.speed === undefined || body.speed === null ? (e.narration as { speed?: number } | undefined)?.speed ?? (said as { speed?: number }).speed : Number(body.speed); - const speed = askedSpeed === undefined || askedSpeed === null || engine === "orpheus" ? undefined : Number(askedSpeed); - // What the voice SAYS: the script with every redacted term left out (post-redact.mjs), each slur as the cut's - // filter has it (post-slurs.mjs) and the project's pronunciation lexicon applied (post-say.mjs); the script is kept as written. The bench cannot word-time a take as it is made, - // so a beep falls back to skip here (the CLI's --take times it and beeps). - const red = await projectRedaction(r.project.dir, m); - const spoken = spokenRead(script, e, red, { voice: benchVoice(red) }).text; const out = path.join(r.project.dir, ...rel.split("/")); // Its speed and where it came from, for the take the GET makes when the job is done (a sidecar, removed then). // A re-read (`keepPick`, the bench's Read again) joins the list unpicked: said here too. const keepPick = body.keepPick === true; - // Its tuning: the line's own (the Tune), else -- Orpheus only -- its character's (the synthetic preset's that - // answered for the voice: lane character-tuning); a character with no tuning asks as it always did. - // Field by field, as makeTake and every thread piece: the line's own values over the character's (tuningAskOf). - const ta = tuningAskOf({ own: tuned?.ok ? tuned.value : null, preset: (said as { tuning?: Record<string, number> }).tuning ?? null, engine }); - const tuning = ta.tuning; - const tuningAsked = ta.asked; + const speed = A.speed ?? undefined; askFile = `${out}.ask.json`; - if (speed || keepPick || tuningAsked || ta.own) await writeFile(`${out}.ask.json`, JSON.stringify({ ...(speed ? { speed, speedAsked: body.speed !== undefined && body.speed !== null ? true : (e.narration as { speed?: number } | undefined)?.speed != null ? "item" : "preset" } : {}), ...(keepPick ? { keepPick: true } : {}), ...(tuningAsked ? { tuningAsked } : {}), ...(ta.own ? { tuningOwn: ta.own } : {}) })); - const jobId = await startJob("/api/ops/tts", { text: spoken, engine, voice, out, ...(speed ? { speed } : {}), ...(tuning ? { tuning } : {}), ...(reading !== null ? { reading } : {}) }); + if (speed || keepPick || tuningAsked || A.tuningOwn) await writeFile(`${out}.ask.json`, JSON.stringify({ ...(speed ? { speed, speedAsked: A.speedAsked } : {}), ...(keepPick ? { keepPick: true } : {}), ...(tuningAsked ? { tuningAsked } : {}), ...(A.tuningOwn ? { tuningOwn: A.tuningOwn } : {}) })); + const jobId = await startJob("/api/ops/tts", askBody(A, out)); // The marker names its job, its file and what the take keeps (its words, its note): a bench that lost the job // finds it again here and lands its take (GET ?pending). await writeFile(pendingFile, JSON.stringify({ jobId, file: rel, script, ...(typeof body.note === "string" && body.note ? { note: body.note } : {}), at: new Date().toISOString() })); diff --git a/umtool/lib/report/benchQueueParity.test.mjs b/umtool/lib/report/benchQueueParity.test.mjs @@ -0,0 +1,72 @@ +// THE QUEUE's READ IS THE BENCH's (lane reads-find, the orchestrator's ruling 3): a post's read made by the re-read +// queue (makeTake with the bench's slur rule) asks the editor EXACTLY what the bench's take op asks +// (postTakeAsk.mjs: the one module both build from) -- the slur case included: a cut that beeps a slur has it left +// out of a bench read, and out of the queue's. Temp dirs, a stub tts, invented people. +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +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 { 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 { makeTake } from "./postNarrationCli.mjs"; +import { askBody, benchSlurVoice, postTakeAskOf } from "./postTakeAsk.mjs"; +import { projectRedaction } from "./postRedaction.mjs"; + +const LIST = JSON.parse(readFileSync(new URL("../../report-to-video/slurs.json", import.meta.url), "utf8")); +const F = LIST.entries.find((e) => e.id === "f-slur").word; +const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-bench-parity-")); +after(() => rm(ROOT, { recursive: true, force: true })); +delete process.env.UMTOOL_CAST_FILE; + +const item = (o = {}) => ({ 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: "post one", ...o }); +async function project(name, timeline, render = {}) { + const dir = path.join(ROOT, name, "p"); + await mkdir(dir, { recursive: true }); + await mkdir(path.join(ROOT, name, ".umtool"), { recursive: true }); + await writeFile(path.join(ROOT, name, ".umtool", "cast.json"), JSON.stringify({ format: "umtool-cast", version: 2, characters: [{ id: "ferry", name: "Ferry Teller", handles: ["invented_ferry"], synthetic: { voice: "orpheus:tara", tuning: { temperature: 0.75 } } }] })); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, render: { width: 1920, height: 1080, fps: 30, postNarration: { engine: "orpheus", voice: "zac" }, ...render }, timeline }, null, 2)); + return { id: name, dir }; +} +const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); +const asker = (asked) => async (body) => { + asked.push(body); + await mkdir(path.dirname(body.out), { recursive: true }); + await writeFile(body.out, encodeWav16(withSilence(syntheticVoice({ ...VOICE_B, seconds: 0.6 }), { before: 0.1, after: 0.1 }))); + return { jobId: `job-${asked.length}`, result: { wav: body.out, engine: body.engine, voice: body.voice } }; +}; +/** The bench's take op's body for one press (the route builds it with these very calls). */ +async function benchBody(p, press) { + const m = await manifest(p); + const e = m.timeline[0]; + const red = await projectRedaction(p.dir, m); + const a = await postTakeAskOf(p, e, { render: m.render, script: String(press.script ?? e.narration.script), speed: press.speed ?? null, tuning: press.tuning ?? null, reading: press.reading ?? null, red, slurVoice: benchSlurVoice(red) }); + return askBody(a, "OUT"); +} +async function queueBody(p, press) { + const asked = []; + const r = await makeTake(p, (await manifest(p)).timeline[0], { ask: asker(asked), benchSlurs: true, keepPick: true, ...press, askOp: async () => { throw new Error("the queue's read is never word-timed"); } }); + assert.equal(asked.length, 1, "one ask, never a second for a beep"); + return { body: { ...asked[0], out: "OUT" }, take: r.take }; +} + +test("the same press, the same ask: the character's tuning, the line's own over it, a reading", async () => { + for (const [name, press] of [["plain", {}], ["own", { tuning: { temperature: 0.9, takes: 5 } }], ["reading", { reading: 2 }]]) { + const p = await project(`same-${name}`, [item({ narration: { script: "The ferry runs at noon." } })]); + const want = await benchBody(p, press); + const got = await queueBody(p, press); + assert.deepEqual(got.body, want, name); + } +}); + +test("THE SLUR CASE: a cut that beeps -- the bench leaves the slur out, and so does the queue's read (no word timing)", async () => { + const script = `Hello, you ${F}. Welcome.`; + const p = await project("beep", [item({ narration: { script } })], { posts: { slurs: { voice: "beep" } } }); + const want = await benchBody(p, {}); + assert.equal(want.text, "Hello, you. Welcome."); + const got = await queueBody(p, {}); + assert.deepEqual(got.body, want); + assert.equal(got.take.slurs, "skip"); + assert.equal(got.take.words, undefined); +}); diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -376,19 +376,23 @@ export async function transcriptionLaneHeld() { } } -export async function makeTake(project, e, { script = null, note = null, engine = null, voice = null, speed = null, tuning = null, reading = null, keepPick = false, render = {}, emit = () => {}, editor = null, ask = null, askOp = null, redaction = undefined, laneHeld = null, timingDeadlineMs = BEEP_TIMING_DEADLINE_MS } = {}) { - const k = postNarrationKnobs(e, render); +export async function makeTake(project, e, { script = null, note = null, engine = null, voice = null, speed = null, tuning = null, reading = null, keepPick = false, render = {}, emit = () => {}, editor = null, ask = null, askOp = null, redaction = undefined, laneHeld = null, timingDeadlineMs = BEEP_TIMING_DEADLINE_MS, benchSlurs = false } = {}) { const words = String(script ?? e.narration?.script ?? "").trim(); if (!words) throw new NarrateError(`${e.id} has no script to read (--script "…", or --all --draft-scripts)`); - // The voice his own read is said in: the one asked for, the item's own character, the project's characters and voice - // map, the CAST, the narrator's (readVoice.mjs). - const { itemReadVoice } = await import("./readVoice.mjs"); - const said0 = await itemReadVoice(project, e, { render, engine, voice }); - const eng = said0.engine; - const vox = said0.voice; - // Its speed: the one asked for (--speed), else the item's own (`narration.speed`: set on this one item), else its - // character's (the synthetic preset's that answered for the voice). - const spd = speed ?? e.narration?.speed ?? said0.speed ?? null; + // What the voice SAYS: the script with every redacted term left out (post-redact.mjs), each slur as the cut's + // filter has it (post-slurs.mjs: skipped, its stand-in, or said for a beep), and each word of the project's + // pronunciation lexicon said its way (post-say.mjs) -- the script itself is kept as written. + const red = redaction !== undefined ? redaction : await projectRedaction(project.dir, (await readManifest(project.dir)) ?? {}); + // THE ASK (postTakeAsk.mjs, the one the bench's take op builds too; lane reads-find): the voice his own read is said + // in (the one asked for, the item's own character, the project's characters and voice map, the CAST, the + // narrator's), its speed (the one asked for, else the item's own, else its character's), its tuning (the line's own + // values over its character's, field by field; a character with no tuning: the ask as it always was) and what is + // said. `benchSlurs` (the re-read queue): the bench's slur rule -- a beep left out, as a bench press leaves it. + const { askBody, benchSlurVoice, postTakeAskOf } = await import("./postTakeAsk.mjs"); + const A = await postTakeAskOf(project, e, { render, script: words, engine, voice, speed, tuning, reading, red, slurVoice: benchSlurs ? benchSlurVoice(red) : undefined }); + const eng = A.engine; + const vox = A.voice; + const spd = A.speed; const pid = postIdOf(e); const dir = path.join(project.dir, ...takesDirOf(pid).split("/")); await mkdir(dir, { recursive: true }); @@ -397,24 +401,10 @@ export async function makeTake(project, e, { script = null, note = null, engine const rel = takeFileOf(pid, n, eng, vox); const out = path.join(project.dir, ...rel.split("/")); const askTts = ask ?? (await import("umtool-report-to-video/narrate-via-editor")).askEditorTts; - // What the voice SAYS: the script with every redacted term left out (post-redact.mjs), each slur as the cut's - // filter has it (post-slurs.mjs: skipped, its stand-in, or said for a beep), and each word of the project's - // pronunciation lexicon said its way (post-say.mjs) -- the script itself is kept as written. - const red = redaction !== undefined ? redaction : await projectRedaction(project.dir, (await readManifest(project.dir)) ?? {}); - const said = spokenRead(words, e, red); - // Its tuning and reading (--reading, --temperature, …): sent only when asked -- an ask without them is the one it always was. - // ITS CHARACTER's TUNING (lane character-tuning): the synthetic preset's that answered for the voice, asked when the - // line asks none of its own (the line's beats it; an engine with no sampler is asked none of the character's). A - // character with no tuning: the ask, and the take, as they always were. - // Field by field: the line's own values over the character's (post-say.mjs tuningAskOf, the thread read's rule too). - const { tuningAskOf } = await import("umtool-report-to-video/post-say"); - const ta = tuningAskOf({ own: tuning, preset: said0.tuning ?? null, engine: eng }); - const asked = ta.tuning; - const tuningAsked = ta.asked; - const ttsBody = (text) => ({ - text, engine: eng, voice: vox, out, ...(spd !== null && eng !== "orpheus" ? { speed: spd } : {}), - ...(asked ? { tuning: asked } : {}), ...(reading !== null ? { reading } : {}), - }); + const said = A.said; + const tuningAsked = A.tuningAsked; + const ta = { own: A.tuningOwn }; + const ttsBody = (text) => askBody(A, out, text); let { jobId, result } = await askTts(ttsBody(said.text), { ...(editor ? { editor } : {}), emit }); if (result?.note) emit("note", { message: `${e.id}: ${result.note}` }); if (!(await stat(out).catch(() => null))?.isFile()) throw new NarrateError(`the editor's job ${jobId} finished but ${rel} is not there (its result names ${result?.wav ?? "no file"})`); diff --git a/umtool/lib/report/postTakeAsk.mjs b/umtool/lib/report/postTakeAsk.mjs @@ -0,0 +1,51 @@ +// ONE POST's TAKE, AS ASKED OF THE EDITOR (lane reads-find, the orchestrator's ruling 3: the queue's read of a post is +// the same ask a bench press makes): the voice (readVoice.mjs: the one asked for, the item's own character, the +// project's characters and voice map, the cast, the narrator), the speed (the one asked for, the item's own, the +// character's; none for Orpheus), the tuning (post-say.mjs tuningAskOf: the line's own values over the character's, +// field by field, and whose it is) and what the voice SAYS (post-redact.mjs spokenRead: the redaction, the slurs, the +// lexicon, an anonymous handle as its shown name). The bench's take op (app/api/report/post-narration) and +// `umtool posts narrate <p> <item> --take` (makeTake) both build their ask here; the re-read queue asks through +// makeTake with the bench's slur rule, so the two can never drift apart. +// +// THE SLURS: the bench cannot word-time a take as it is made, so a cut that BEEPS a slur has it left out of a bench +// read (`benchSlurVoice`); the CLI's own --take says it and times its words for the beep (makeTake). +// +// Plain ESM: the CLI runs it under bare node. +import { postNarrationKnobs } from "umtool-report-to-video/post-narration"; +import { spokenRead } from "umtool-report-to-video/post-redact"; +import { tuningAskOf } from "umtool-report-to-video/post-say"; + +/** The slur filter's voice for a read made on the bench (and by the re-read queue): a beep falls back to skip. */ +export const benchSlurVoice = (red) => (red?.slurs?.voice === "beep" ? "skip" : undefined); + +/** + * THE ASK: `{ engine, voice, speed, speedAsked, tuning, tuningAsked, tuningOwn, reading, said }` -- `said` spokenRead's + * result; askBody makes the editor's tts op body of it. `speed`/`tuning`/`reading` are the press's own (null: none); + * `slurVoice` the slur rule (benchSlurVoice for a bench read; undefined: the cut's own). + * + * @param {{ id: string, dir: string }} project + * @param {Record<string, any>} e + * @param {{ render?: Record<string, any>, script: string, engine?: string | null, voice?: string | null, speed?: number | null, + * tuning?: Record<string, number> | null, reading?: number | null, red: any, slurVoice?: string }} o + */ +export async function postTakeAskOf(project, e, { render = {}, script, engine = null, voice = null, speed = null, tuning = null, reading = null, red, slurVoice = undefined }) { + const k = postNarrationKnobs(e, render); + const { itemReadVoice } = await import("./readVoice.mjs"); + const v = await itemReadVoice(project, e, { render, engine, voice }); + const eng = String(v.engine ?? k.engine); + const vox = String(v.voice ?? k.voice); + // Its speed: the press's, else the item's own (`narration.speed`), else its character's -- none for Orpheus. + const asked = speed ?? e.narration?.speed ?? v.speed ?? null; + const spd = asked === null || asked === undefined || eng === "orpheus" ? null : Number(asked); + const speedAsked = spd === null ? undefined : speed !== null && speed !== undefined ? true : e.narration?.speed != null ? "item" : "preset"; + // Its tuning: the line's own values over its character's, field by field; whose it is; the line's own as asked. + const ta = tuningAskOf({ own: tuning, preset: v.tuning ?? null, engine: eng }); + const said = spokenRead(script, e, red, slurVoice ? { voice: slurVoice } : {}); + return { engine: eng, voice: vox, speed: spd, speedAsked, tuning: ta.tuning, tuningAsked: ta.asked, tuningOwn: ta.own, reading: reading ?? null, said }; +} + +/** The editor's tts op body of an ask, writing `out` (`text`: other words than the ask's, e.g. a slur left out). */ +export const askBody = (a, out, text = a.said.text) => ({ + text, engine: a.engine, voice: a.voice, out, ...(a.speed !== null ? { speed: a.speed } : {}), + ...(a.tuning ? { tuning: a.tuning } : {}), ...(a.reading !== null ? { reading: a.reading } : {}), +});