Archilyzer · Source

archilyzer

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

commit 1ba7c6bd915f94ae55f37625979f73ae5e99bdcf
parent 080d8ffd1321dacbc07b29038cf98a551fd182f3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 12:08:21 -0500

umtool reads: a character's Orpheus tuning reaches its reads, and says it did

- makeTake and the bench's take op ask the character's tuning (the synthetic
  preset's that answered for the voice) when the line asks none of its own,
  field by field under the line's own; the take records tuningAsked
  "preset" (the character's) or true (the line's own).
- A thread read and its screen lines: each piece its character's, the read's
  own over it; parts record tuningAsked; read.tuned keeps only the read's own
  (a later read asks the character's as it is then).
- post-narration.mjs: tuningAsked is a take key and a part key, true or
  "preset".
- The stale list judges a part's own tuningAsked and a thread read's screen
  lines; rereadPlan re-reads a character-tuned take with its reading only.
- GET /api/report/post-narration?reads=<role>: the character a piece's
  preset reads it with, and where it is kept.
- The pin: a character with no tuning asks, keys and records as main did
  (hashes taken on main's code).

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

Diffstat:
Mumtool/app/api/report/post-narration/route.ts | 40++++++++++++++++++++++++++++++++++++----
Mumtool/lib/report/castProject.mjs | 8+++++++-
Mumtool/lib/report/characterTuningWiring.test.mjs | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postNarrationCli.mjs | 14+++++++++++++-
Mumtool/lib/report/postThreadRead.mjs | 34+++++++++++++++++++++++++++-------
Mumtool/report-to-video/cast.mjs | 25++++++++++++++++++++++---
Mumtool/report-to-video/post-narration.mjs | 12+++++++++---
7 files changed, 199 insertions(+), 19 deletions(-)

diff --git a/umtool/app/api/report/post-narration/route.ts b/umtool/app/api/report/post-narration/route.ts @@ -22,7 +22,7 @@ import { fitPostItem } from "@/lib/report/postFit.mjs"; import { itemReadVoice } from "@/lib/report/readVoice.mjs"; import { projectRedaction } from "@/lib/report/postRedaction.mjs"; import { spokenRead } from "umtool-report-to-video/post-redact"; -import { recordedPresetOf, shownNameOf } from "umtool-report-to-video/cast"; +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"; import { getJob, runningJob, startJob as startUmtoolJob, type Job } from "@/lib/jobs"; @@ -93,6 +93,10 @@ const benchVoice = (red: { slurs?: { voice?: string } | null } | null) => (red?. // screens, else `posts narrate <p> <item> --take --thread` asked as the // playing read was -- every synthesized piece's next reading, unpicked // GET ?project&id&screenJob=<job> either job: its state, its result, and -- ended -- the entry as it is +// GET ?project&id&reads=<role> the CHARACTER whose synthetic preset reads that piece of the item +// (post, parent:<i>, quoted, linked:<i>, screen:<id>:<n>) now: +// {character: {id, name, layer: "cast" | "project"} | null} -- the one a +// Tune's "Keep for <character>" keeps a tuning for (lane character-tuning) // GET ?project&id&pending=1 the post's read being made or made and not kept: {jobId, file, // script, note} -- the bench follows `?job` with them to land its take @@ -138,6 +142,24 @@ export async function GET(request: Request) { } return Response.json({ ok: true, prompts }, { headers: noStore }); } + if (id && q.get("reads") !== null) { + // The character whose synthetic preset answers for one piece of this item's read now (the chain every read asks: + // readVoice.mjs for his own words, the thread read's pieces for the rest) -- and where it is kept. + const e = postsOf(m).find((x) => x.id === id); + if (!e) return Response.json({ error: `no post item ${id}` }, { status: 404 }); + const role = String(q.get("reads") || "post"); + if (!/^(post|quoted|parent:\d|linked:\d|screen:[a-z0-9][a-z0-9-]{0,23}:\d{1,2})$/.test(role)) return Response.json({ error: "reads names one piece of a read (post, quoted, parent:<i>, linked:<i>, screen:<id>:<n>)" }, { status: 400 }); + const L = await readLayers(r.project.dir).catch(() => null); + let charId: string | null = null; + if (role === "post") charId = ((await itemReadVoice(r.project, e, { render: (m.render ?? {}) as Record<string, unknown> }).catch(() => null)) as { character?: string } | null)?.character ?? null; + else { + const { threadTake } = await import("@/lib/report/postThreadRead.mjs"); + const plan = await threadTake(r.project, e, { manifest: m, dryRun: true, parents: "all" }).then((x: { plan?: { pieces?: Array<{ role: string; character?: string }> } }) => x.plan ?? null, () => null); + charId = plan?.pieces?.find((pc) => pc.role === role)?.character ?? null; + } + const hit = charId && L ? characterById(charId, { project: L.project, cast: L.cast }) : null; + return Response.json({ character: hit ? { id: hit.character.id, name: shownNameOf(hit.character), layer: hit.layer } : null }, { headers: noStore }); + } if (id && q.get("pending") !== null) { // THE READ OF THIS POST BEING MADE, or made and not yet kept (review 2, finding 2): its marker's job, file and // words -- a bench that lost it follows the same `?job` GET to land its take. `{ pending: null }` when there is none. @@ -232,10 +254,12 @@ export async function GET(request: Request) { const { slurs, lexicon } = spoken; // What the POST asked (its speed and where it came from), kept beside the file until the take is made. const askFile = `${abs}.ask.json`; - const ask = (await readFile(askFile, "utf8").then(JSON.parse, () => null)) as { speed?: number; speedAsked?: true | "item" | "preset"; keepPick?: boolean } | null; + const ask = (await readFile(askFile, "utf8").then(JSON.parse, () => null)) as { speed?: number; speedAsked?: true | "item" | "preset"; keepPick?: boolean; tuningAsked?: true | "preset" } | null; await rm(askFile, { force: true }); const take = { ...(typeof ask?.speed === "number" ? { speed: ask.speed } : {}), ...(ask?.speedAsked !== undefined ? { speedAsked: ask.speedAsked } : {}), + // Where its tuning came from (lane character-tuning): its line's own, or its character's. + ...(ask?.tuningAsked === true || ask?.tuningAsked === "preset" ? { tuningAsked: ask.tuningAsked } : {}), // What it said, when an anonymous handle made that differ from the script (post-anon.mjs; the lint reads it). ...(spoken.anonymised ? { said: spoken.text } : {}), ...(slurs ? { slurs } : {}), @@ -417,9 +441,17 @@ async function postHere(request: Request) { // 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: the line's own values over the character's. + const own = tuned?.ok && Object.keys(tuned.value).length ? tuned.value : null; + const presetT = (said as { tuning?: Record<string, number> }).tuning; + const preset = engine === "orpheus" && presetT && Object.keys(presetT).length ? presetT : null; + const tuning = preset ? { ...preset, ...(own ?? {}) } : own; + const ownSampler = !!own && Object.keys(own).some((k) => k !== "takes"); + const tuningAsked = engine === "orpheus" && tuning ? (ownSampler || !preset ? true : "preset") : null; askFile = `${out}.ask.json`; - if (speed || keepPick) 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 } : {}) })); - const tuning = tuned?.ok && Object.keys(tuned.value).length ? tuned.value : null; + if (speed || keepPick || tuningAsked) 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 } : {}) })); const jobId = await startJob("/api/ops/tts", { text: spoken, engine, voice, out, ...(speed ? { speed } : {}), ...(tuning ? { tuning } : {}), ...(reading !== null ? { reading } : {}) }); // 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). diff --git a/umtool/lib/report/castProject.mjs b/umtool/lib/report/castProject.mjs @@ -15,6 +15,12 @@ import { import { characterLines } from "./castAudition.mjs"; import { tuningArgvOf } from "./readTuning.mjs"; +/** + * A take's reading asked again, and none of its tuning: a take whose tuning was its CHARACTER's (`tuningAsked` + * "preset", lane character-tuning) is re-read with the character's tuning as it is then, never pinned to the old one. + */ +const readingArgvOf = (t) => (Number.isInteger(t?.reading) && t.reading > 0 ? ["--reading", String(t.reading)] : []); + const str = (v) => (typeof v === "string" ? v : ""); /** @@ -235,7 +241,7 @@ export function rereadPlan(projectId, manifest, drift, handles) { // from the character's preset or the item (that is what a re-read takes anew). Its own tuning and reading too // (readTuning.mjs: what is not Orpheus's default) -- a reading picked by ear is read again the same way. const keepSpeed = !r.thread && typeof t?.speed === "number" && t.speed !== 1 && t.speedAsked !== "preset" && t.speedAsked !== "item"; - const argv = ["posts", "narrate", projectId, r.id, "--take", ...(r.thread ? ["--thread", ...threadArgvOf(t?.read, { handles: [...want], author: e?.handle, takes })] : [...(keepSpeed ? ["--speed", String(t.speed)] : []), ...tuningArgvOf(t)])]; + const argv = ["posts", "narrate", projectId, r.id, "--take", ...(r.thread ? ["--thread", ...threadArgvOf(t?.read, { handles: [...want], author: e?.handle, takes })] : [...(keepSpeed ? ["--speed", String(t.speed)] : []), ...(t?.tuningAsked === "preset" ? readingArgvOf(t) : tuningArgvOf(t))])]; return { ...r, take: t?.file ?? null, argv }; }); return { items, skipped }; diff --git a/umtool/lib/report/characterTuningWiring.test.mjs b/umtool/lib/report/characterTuningWiring.test.mjs @@ -100,3 +100,88 @@ test("THE PIN: a character with no tuning -- the post's take, the thread read an if (process.env.PIN_PRINT) console.log(JSON.stringify(got, null, 2)); assert.deepEqual(got, MAIN); }); + +const STEADY = { temperature: 0.4, top_p: 0.8 }; + +test("a post's take: the character's tuning asked and recorded as \"preset\"; the line's own beats it, field by field", async () => { + const r = await readsOf("single", castDoc(LIVELY)); + assert.deepEqual(r.single[0].tuning, LIVELY); + assert.equal(r.take.tuningAsked, "preset"); + assert.deepEqual(r.take.tuning, { temperature: 0.75, top_p: 0.92, top_k: 50, min_p: 0, repeat_penalty: 1.25, takes: 3 }); + // The line's own sampler value: asked over the character's, recorded as its own. + const p = await project("single-own", castDoc(LIVELY)); + const asked = []; + let t = (await makeTake(p, (await read(p)).timeline[0], { ask: stubAsk(asked), redaction: NO_RED, tuning: { temperature: 0.9 } })).take; + assert.deepEqual(asked[0].tuning, { ...LIVELY, temperature: 0.9 }); + assert.equal(t.tuningAsked, true); + // Only its takes: the character's sampler kept, still the character's. + t = (await makeTake(p, (await read(p)).timeline[0], { ask: stubAsk(asked), redaction: NO_RED, tuning: { takes: 5 } })).take; + assert.deepEqual(asked[1].tuning, { ...LIVELY, takes: 5 }); + assert.equal(t.tuningAsked, "preset"); + // A Kokoro voice is asked none of the character's (no sampler); the take records none. + const k = await project("single-kokoro", { ...castDoc(LIVELY), characters: [{ ...castDoc(LIVELY).characters[0], synthetic: { voice: "kokoro:af_heart", tuning: LIVELY } }, castDoc().characters[1]] }); + const ka = []; + t = (await makeTake(k, (await read(k)).timeline[0], { ask: stubAsk(ka), redaction: NO_RED })).take; + assert.equal("tuning" in ka[0], false); + assert.equal(t.tuningAsked, undefined); + // The take validates (the writer refused nothing): it is the item's now. + assert.equal((await read(p)).timeline[0].narration.takes.at(-1).tuningAsked, "preset"); +}); + +test("a thread read and its screen lines: each piece asked its own character's tuning; the read's own beats it; read.tuned keeps only the read's", async () => { + const r = await readsOf("thread", castDoc(LIVELY, STEADY)); + // Post piece and the author's own line: Lively; the other speaker's line: Steady (repeat penalty the default's: not asked). + const byText = Object.fromEntries(r.threadAsks.map((b) => [b.text, b.tuning])); + assert.deepEqual(byText["Here is what they sent."], LIVELY); + assert.deepEqual(byText["Not this year."], LIVELY); + assert.deepEqual(byText["Are the tolls going up?"], STEADY); + const parts = r.thread.take.parts; + assert.ok(parts.every((x) => x.tuningAsked === "preset"), JSON.stringify(parts.map((x) => [x.role, x.tuningAsked]))); + assert.equal(r.thread.take.read.tuned, undefined, "a character's tuning is not the read's: a later read asks the character's as it is then"); + // The keys: a tuned part is another file than the untuned one. + const pin = await readsOf("thread-pin", castDoc()); + assert.notDeepEqual(r.thread.parts.map((x) => x.key), pin.thread.parts.map((x) => x.key)); + // One line's own tuning (the Tune, --for): that piece's, asked over the character's and recorded as the read's. + const p = await project("thread-own", castDoc(LIVELY, STEADY)); + const asked = []; + const own = await threadTake(p, (await read(p)).timeline[0], { red: NO_RED, ask: stubAsk(asked), lanes: null, ...layersOf(castDoc(LIVELY, STEADY)), tuned: { "screen:s1:0": { tuning: { temperature: 0.9 } } } }); + const line = own.take.parts.find((x) => x.role === "screen:s1:0"); + assert.deepEqual([line.tuning, line.tuningAsked], [{ ...STEADY, temperature: 0.9 }, true]); + assert.deepEqual(own.take.read.tuned["screen:s1:0"].tuning, { ...STEADY, temperature: 0.9 }); + assert.equal(own.take.parts.find((x) => x.role === "post").tuningAsked, "preset"); +}); + +test("stale over real takes: the character's tuning changed -- its post take, its thread pieces and its screen line; the line's own never", async () => { + const { tuningStale } = await import("umtool-report-to-video/cast"); + const { resolverFor } = await import("./castProject.mjs"); + const r = await readsOf("stale", castDoc(LIVELY, STEADY)); + const m = await read(r.p); + // The thread read is the playing take (picked last). The character as it was: nothing stale. + assert.deepEqual(tuningStale(m, resolverFor({ cast: castDoc(LIVELY, STEADY) }), { settingTakes: 3 }), []); + // Ferry is Steady now: his post piece and his own screen line are stale; the other speaker's line is not. + const rows = tuningStale(m, resolverFor({ cast: castDoc(STEADY, STEADY) }), { settingTakes: 3 }); + assert.deepEqual(rows.map((x) => [x.role, x.character]).sort(), [["post", "ferry"], ["screen:s1:1", "ferry"]]); + // The single post take (not playing) is not counted: only what plays is. + const m2 = { ...m, timeline: m.timeline.map((e) => ({ ...e, narration: { ...e.narration, pick: 0 } })) }; + assert.deepEqual(tuningStale(m2, resolverFor({ cast: castDoc(STEADY, STEADY) }), { settingTakes: 3 }).map((x) => x.role), ["post"]); + // A line asked its own tuning: never stale, whatever the character does. + const p = await project("stale-own", castDoc(LIVELY, STEADY)); + await threadTake(p, (await read(p)).timeline[0], { red: NO_RED, ask: stubAsk([]), lanes: null, ...layersOf(castDoc(LIVELY, STEADY)), tuned: { "screen:s1:1": { tuning: { temperature: 0.9 } } } }); + const m3 = await read(p); + assert.deepEqual(tuningStale(m3, resolverFor({ cast: castDoc(STEADY, STEADY) }), { settingTakes: 3 }).map((x) => x.role), ["post"]); +}); + +test("rereadPlan: a take whose tuning was its character's is re-read with the character's as it is then (its reading kept, no tuning flags)", async () => { + const { rereadPlan } = await import("./castProject.mjs"); + const made = (o) => ({ temperature: 0.75, top_p: 0.92, top_k: 50, min_p: 0, repeat_penalty: 1.25, takes: 3, ...o }); + const m = { timeline: [ + { type: "post", id: "p-1", handle: "x", narration: { takes: [{ file: "a.wav", engine: "orpheus", voice: "zac", tuning: made(), tuningAsked: "preset", reading: 2 }], pick: 0 } }, + { type: "post", id: "p-2", handle: "x", narration: { takes: [{ file: "b.wav", engine: "orpheus", voice: "zac", tuning: made({ temperature: 0.9 }), tuningAsked: true }], pick: 0 } }, + ] }; + const drift = (id) => ({ id, handle: "x", role: "post", reads: "orpheus:zac", want: "orpheus:leah", kind: "tts", thread: false }); + const plan = rereadPlan("p", m, [drift("p-1"), drift("p-2")], ["x"]); + assert.deepEqual(plan.items.map((x) => x.argv.slice(4)), [ + ["--take", "--reading", "2"], + ["--take", "--temperature", "0.9", "--top-p", "0.92", "--repeat-penalty", "1.25", "--chunk-takes", "3"], + ]); +}); diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -403,9 +403,19 @@ export async function makeTake(project, e, { script = null, note = null, engine 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 (a line that asks only its takes keeps the + // character's sampler); `tuningAsked` true when the line names a sampler value of its own. + const own = tuning && Object.keys(tuning).length ? tuning : null; + const preset = eng === "orpheus" && said0.tuning && Object.keys(said0.tuning).length ? said0.tuning : null; + const asked = preset ? { ...preset, ...(own ?? {}) } : own; + const ownSampler = !!own && Object.keys(own).some((k) => k !== "takes"); + const tuningAsked = eng === "orpheus" && asked ? (ownSampler || !preset ? true : "preset") : null; const ttsBody = (text) => ({ text, engine: eng, voice: vox, out, ...(spd !== null && eng !== "orpheus" ? { speed: spd } : {}), - ...(tuning && Object.keys(tuning).length ? { tuning } : {}), ...(reading !== null ? { reading } : {}), + ...(asked ? { tuning: asked } : {}), ...(reading !== null ? { reading } : {}), }); let { jobId, result } = await askTts(ttsBody(said.text), { ...(editor ? { editor } : {}), emit }); if (result?.note) emit("note", { message: `${e.id}: ${result.note}` }); @@ -454,6 +464,8 @@ export async function makeTake(project, e, { script = null, note = null, engine // What it was made with, as the editor's result says it (Orpheus: every tuning value and the reading), so it can be // made again exactly; an engine without a sampler reports neither. ...tunedOfResult(result), + // Where that tuning came from: its line's own (true) or its character's ("preset": stale when that changes). + ...(tuningAsked ? { tuningAsked } : {}), // What its audio does with the slurs the script holds (post-slurs.mjs), and its words when timed for a beep. ...(slurs ? { slurs } : {}), ...(timed ? { words: timed } : {}), // The pronunciation entries it said (post-say.mjs; `umtool posts say <p> stale` reads them). diff --git a/umtool/lib/report/postThreadRead.mjs b/umtool/lib/report/postThreadRead.mjs @@ -75,6 +75,10 @@ const r3 = (v) => Math.round(v * 1000) / 1000; const str = (v) => (typeof v === "string" ? v : ""); const norm = (t) => str(t).replace(/\s+/g, " ").trim(); const isTuneObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); +/** Does a tuning name a sampler value (anything but `takes`)? */ +const samplerNamed = (t) => Object.keys(t ?? {}).some((k) => k !== "takes"); +/** A piece's character's Orpheus tuning (resolvePieceVoice's `tuning`), held for the tuning pass below: `{}` for none. */ +const presetTuningOf = (v) => (v?.engine === "orpheus" && isTuneObj(v.tuning) && Object.keys(v.tuning).length ? { presetTuning: v.tuning } : {}); /** The project's parts cache (relative to its folder). */ export const PARTS_CACHE = "narration/parts-cache"; @@ -301,7 +305,7 @@ export function threadReadPlan(manifest, e, { red = null, map = {}, cast = {}, i } const v = resolvePieceVoice({ handle, role: sw.self ? "post" : p.role }, { map, cast, item, overrides, self: str(e.handle), voice: null, narrator, engine: eng }); const spd = readSpeedOf({ flag: speed, preset: v.speed ?? null, own: sw.self ? e.narration?.speed ?? null : null, engine: v.engine }); - pieces.push({ role: p.role, handle, who: p.who, speaker: str(p.who), date: null, line: written, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) }); + pieces.push({ role: p.role, handle, who: p.who, speaker: str(p.who), date: null, line: written, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), ...presetTuningOf(v), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) }); continue; } const written = p.role === "post" ? own || script || "" : draftScript(p.text).script; @@ -316,7 +320,7 @@ export function threadReadPlan(manifest, e, { red = null, map = {}, cast = {}, i } const v = resolvePieceVoice({ handle: p.handle, role: p.role }, { map, cast, item, overrides, self: str(e.handle), voice, narrator, engine: eng }); const spd = readSpeedOf({ flag: speed, preset: v.speed ?? null, own: p.role === "post" ? e.narration?.speed ?? null : null, engine: v.engine }); - pieces.push({ role: p.role, handle: p.handle, date: p.date, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) }); + pieces.push({ role: p.role, handle: p.handle, date: p.date, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), ...presetTuningOf(v), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) }); } if (!fromRead && !pieces.some((p) => p.role === "post")) throw new ThreadReadError(`${e.id} has no words of his own to read (--script "…" first)`); if (!pieces.length) throw new ThreadReadError(`${e.id} has nothing to read (its screen ${fromRead?.id ?? ""} reads no line)`); @@ -334,15 +338,26 @@ export function threadReadPlan(manifest, e, { red = null, map = {}, cast = {}, i // EACH SYNTHESIZED PIECE's READING AND TUNING (lane line-rerun): the one asked for its role (`tuned[role]`), else // the whole read's (`tuned["*"]`), else the one the playing read gave it while it says the same words (`inherit`, // posts screen read's) -- a reading "next" one past the highest its words were read at. + // ITS CHARACTER's TUNING (lane character-tuning): a piece whose read asks no tuning of its own is asked its + // character's (the synthetic preset's that answered for its voice: `presetTuning`), and says so (`tuningAsked`: + // "preset"; its own: true). A character with no tuning: the piece as it always was. for (const pc of pieces) { + const preset = pc.presetTuning ?? null; + delete pc.presetTuning; if (pc.take) continue; const kept = isTuneObj(inherit?.[pc.role]) && norm(inherit[pc.role].said) === norm(pc.text) ? inherit[pc.role] : null; const ask = tuned?.[pc.role] ?? tuned?.["*"] ?? kept; + const own = isTuneObj(ask) ? tuningOf(ask.tuning) : null; + // Field by field: the read's own values over the character's (a read that asks only its takes keeps the + // character's sampler); asked by the read when it names a sampler value of its own. + const t = preset && pc.engine === "orpheus" ? tuningOf({ ...preset, ...(isTuneObj(ask?.tuning) ? ask.tuning : {}) }) : own; + if (t) { + pc.tuning = t; + pc.tuningAsked = own && samplerNamed(own) ? true : preset && pc.engine === "orpheus" ? "preset" : true; + } if (!isTuneObj(ask)) continue; const reading = ask.reading === "next" ? nextPartReading(e, pc.role, pc.text) : Number.isInteger(ask.reading) ? ask.reading : 0; - const tuning = tuningOf(ask.tuning); if (reading > 0) pc.reading = reading; - if (tuning) pc.tuning = tuning; } const lexicon = [...new Map(pieces.flatMap((p) => p.lexicon).map((x) => [`${x.word.toLowerCase()}|${x.item ?? ""}`, x])).values()]; const states = pieces.map((p) => p.slurs).filter(Boolean); @@ -453,7 +468,9 @@ export function readParts(plan) { if (pc.take) return [{ piece, para: 0, role: pc.role, voice: pc.voice, text: pc.text, file: pc.take.file, take: pc.take.id, key: null, ...line }]; const eng = pc.engine ?? plan.engine; const tune = { ...(pc.reading ? { reading: pc.reading } : {}), ...(pc.tuning ? { tuning: pc.tuning } : {}) }; - return scriptParts(pc.text).map((q) => ({ piece, para: q.para, role: pc.role, voice: pc.voice, engine: eng, ...(pc.speed !== undefined ? { speed: pc.speed } : {}), ...tune, text: q.text, key: partKey(eng, pc.voice, q.text, pc.speed ?? null, tune), ...line })); + // Where its tuning came from (not in its key: the same tuning is the same audio, whoever asked it). + const from = pc.tuning && pc.tuningAsked ? { tuningAsked: pc.tuningAsked } : {}; + return scriptParts(pc.text).map((q) => ({ piece, para: q.para, role: pc.role, voice: pc.voice, engine: eng, ...(pc.speed !== undefined ? { speed: pc.speed } : {}), ...tune, ...from, text: q.text, key: partKey(eng, pc.voice, q.text, pc.speed ?? null, tune), ...line })); }); } @@ -475,7 +492,7 @@ export function joinTimes(parts, seconds, { fileOf = (p) => (p.take ? p.file : ` t += gap; const s = Number(seconds[i]); // A part from a take (--post-take) says which (`take`: its id); a synthesized one its parts-cache file and voice. - const row = { n: i + 1, para: p.piece * 100 + p.para, text: p.text, ...(typeof p.line === "string" ? { line: p.line, speaker: str(p.speaker) } : {}), voice: p.voice, ...(p.engine ? { engine: p.engine } : {}), ...(typeof p.speed === "number" ? { speed: p.speed } : {}), ...(p.reading ? { reading: p.reading } : {}), ...(p.tuning ? { tuning: p.tuning } : {}), role: p.role, piece: p.piece, file: fileOf(p), ...(p.take ? { take: p.take } : {}), start: r3(t), seconds: r3(s), gapBefore: gap }; + const row = { n: i + 1, para: p.piece * 100 + p.para, text: p.text, ...(typeof p.line === "string" ? { line: p.line, speaker: str(p.speaker) } : {}), voice: p.voice, ...(p.engine ? { engine: p.engine } : {}), ...(typeof p.speed === "number" ? { speed: p.speed } : {}), ...(p.reading ? { reading: p.reading } : {}), ...(p.tuning ? { tuning: p.tuning } : {}), ...(p.tuning && p.tuningAsked ? { tuningAsked: p.tuningAsked } : {}), role: p.role, piece: p.piece, file: fileOf(p), ...(p.take ? { take: p.take } : {}), start: r3(t), seconds: r3(s), gapBefore: gap }; t += s; return row; }); @@ -486,7 +503,10 @@ export function joinTimes(parts, seconds, { fileOf = (p) => (p.take ? p.file : ` export function readRecordOf({ parents = "0", skip = [], quoted = true, linked = true, readSeen = false, overrides = {}, voice = null, speed = null, postTake = null, screens = true, lineTakes = {}, pieces = [] }) { // Each piece's reading and tuning, as made (lane line-rerun), with the words it said: a later read of the same words // keeps it (posts screen read), and `--tuned` asks it again exactly (castProject.mjs threadArgvOf). - const tuned = Object.fromEntries((pieces ?? []).filter((pc) => !pc.take && (pc.reading || pc.tuning)).map((pc) => [pc.role, { ...(pc.reading ? { reading: pc.reading } : {}), ...(pc.tuning ? { tuning: pc.tuning } : {}), said: pc.text }])); + // A tuning that came from the piece's character (`tuningAsked` "preset") is NOT the read's: it is left out, so a later + // read asks the character's as it is then (lane character-tuning). + const ownTuning = (pc) => (pc.tuning && pc.tuningAsked !== "preset" ? pc.tuning : null); + const tuned = Object.fromEntries((pieces ?? []).filter((pc) => !pc.take && (pc.reading || ownTuning(pc))).map((pc) => [pc.role, { ...(pc.reading ? { reading: pc.reading } : {}), ...(ownTuning(pc) ? { tuning: ownTuning(pc) } : {}), said: pc.text }])); return { kind: "thread", parents: parentsSelector(parents), ...(skip?.length ? { skip: [...skip] } : {}), ...(quoted ? {} : { quoted: false }), ...(linked ? {} : { linked: false }), diff --git a/umtool/report-to-video/cast.mjs b/umtool/report-to-video/cast.mjs @@ -838,16 +838,35 @@ export function madeOf(e, take, role = "post", seen = new Set()) { const part = parts.find((p) => p?.role === role && typeof p?.take !== "string" && isObj(p?.tuning)); return { tuning: part ? part.tuning : isObj(take?.tuning) ? take.tuning : null, - asked: take?.tuningAsked, + // A thread read's part says where its own tuning came from; else the take does. + asked: part?.tuningAsked ?? take?.tuningAsked, reading: Number.isInteger(take?.reading) ? take.reading : 0, }; } /** + * A thread read's SCREEN LINES as reads (`[{ handle, role, engine, voice, kind: "tts" }]`, one per line): each line + * synthesized in its speaker's voice, its handle the speaker as written (a line whose speaker is a handle answers to + * that handle's character; one named otherwise answers to none here). takeReads leaves them out (drift does not judge + * them); the stale list does. + */ +function screenReadsOf(take) { + const seen = new Map(); + for (const p of Array.isArray(take?.parts) ? take.parts : []) { + if (typeof p?.role !== "string" || !p.role.startsWith("screen:") || typeof p.take === "string" || typeof p.voice !== "string" || seen.has(p.role)) continue; + const h = handleKey(str(p.speaker)); + if (!h) continue; + seen.set(p.role, { handle: h, role: p.role, engine: str(p.engine) || str(take.engine) || null, voice: p.voice, kind: "tts" }); + } + return [...seen.values()]; +} + +/** * EVERY PICKED ORPHEUS READ OF A CHARACTER MADE WITH OTHER SETTINGS THAN ITS TUNING NOW, pure -- `[{ id, handle, role, * character, made, want, reading, thread }]`. `resolve(e, role, handle, take, read)` says the voice now as castProject.mjs * resolverFor does (`{ engine, voice, character?, tuning? }`). A read is STALE when all of these hold: - * - it is synthesized, by Orpheus (a recorded, converted or derived read never is); + * - it is synthesized, by Orpheus (a recorded, converted or derived read never is) -- a post's take, a thread read's + * pieces, and its screen lines (screenReadsOf); * - a character's preset answers for it now (the item's own, this video's, the cast's), in the voice it was made * in (another voice is drift: cast.mjs voiceDrift); * - its tuning was not ASKED BY THE LINE: the take's `tuningAsked` is not true -- and a take that says nothing of @@ -865,7 +884,7 @@ export function tuningStale(manifest, resolve, { settingTakes = ORPHEUS_DEFAULT_ if (e?.type !== "post") continue; const take = playing(e); if (!take) continue; - for (const r of takeReads(e, take)) { + for (const r of [...takeReads(e, take), ...screenReadsOf(take)]) { if (r.kind !== "tts" || !r.handle || r.engine !== "orpheus") continue; const want = resolve(e, r.role, r.handle, take, r); if (!want?.character || want.engine !== "orpheus" || !sameVoice({ engine: r.engine, voice: r.voice }, want)) continue; diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs @@ -202,7 +202,10 @@ const ITEM_KEYS = new Set([...MIX_KEYS, "script", "excerpt", "engine", "voice", // every tuning value (the defaults included) and the reading (0 = the first) -- so it can be made again exactly. // `forReading` (lane line-rerun): the take was made from words that are not the post's as drafted -- stamped by the // writer when it is made; while it plays the card follows the shown text (post-item.mjs readEditOf). -const TAKE_KEYS = new Set(["file", "engine", "voice", "seconds", "script", "at", "note", "speed", "lufs", "jobId", "parts", "label", "source", "steps", "words", "slurs", "lexicon", "read", "said", "speedAsked", "screenLine", "tuning", "reading", "forReading"]); +// `tuningAsked` (lane character-tuning): where an Orpheus take's tuning came from -- true (its line's own: the +// command's flags, the bench's Tune), "preset" (its character's: stale when that changes, cast.mjs tuningStale). +// Absent: none was asked (the defaults), or unknown (made before it was recorded). +const TAKE_KEYS = new Set(["file", "engine", "voice", "seconds", "script", "at", "note", "speed", "lufs", "jobId", "parts", "label", "source", "steps", "words", "slurs", "lexicon", "read", "said", "speedAsked", "screenLine", "tuning", "reading", "forReading", "tuningAsked"]); const STEP_KEYS = new Set(["op", "engine", "voice", "pitch", "semitones", "params", "ranAt", "job", "drop", "tempo", "spans", "pauses", "revoice"]); // `role` (post-thread.mjs): the text a part reads -- "post", "quoted", "parent:<i>", "media:<i>"; `voice`, `piece`: the batch's; // `engine`: the part's own when it is not the take's (a cast voice that names its engine: postThreadRead.mjs). @@ -210,8 +213,9 @@ const STEP_KEYS = new Set(["op", "engine", "voice", "pitch", "semitones", "param // `speed`: the speed the part was synthesized at (its character's preset's, or the read's --speed; absent: 1). // `take`: a thread read's part that IS one of the item's takes (postThreadRead.mjs --post-take): that take's id. // `reading`, `tuning` (lane line-rerun): the reading and the tuning a thread read's part was asked at (absent: the -// first reading, the defaults), as postThreadRead.mjs keys and asks it. -const PART_KEYS = new Set(["n", "para", "text", "file", "start", "seconds", "gapBefore", "note", "at", "jobId", "role", "voice", "engine", "piece", "tempo", "speed", "take", "line", "speaker", "reading", "tuning"]); +// first reading, the defaults), as postThreadRead.mjs keys and asks it; `tuningAsked` where that tuning came from +// (true: the read's own, "preset": the piece's character's -- a take's `tuningAsked`, per piece). +const PART_KEYS = new Set(["n", "para", "text", "file", "start", "seconds", "gapBefore", "note", "at", "jobId", "role", "voice", "engine", "piece", "tempo", "speed", "take", "line", "speaker", "reading", "tuning", "tuningAsked"]); const VOICE_RE = /^[A-Za-z0-9][A-Za-z0-9_.+-]{0,63}$/; /** Orpheus's expressive tags (narration.mjs NARRATION_TAGS, the editor's list). */ const TAGS = ["laugh", "chuckle", "sigh", "cough", "sniffle", "groan", "yawn", "gasp"]; @@ -685,6 +689,7 @@ export function validatePostNarration(e) { errors.push(...takeLexiconErrors(t.lexicon, `${tw}.lexicon`)); if (t.said !== undefined && (typeof t.said !== "string" || t.said.length > 50000)) errors.push(`${tw}.said must be the words its read said`); if (t.speedAsked !== undefined && t.speedAsked !== true && t.speedAsked !== "item" && t.speedAsked !== "preset") errors.push(`${tw}.speedAsked must be true, "item" or "preset"`); + if (t.tuningAsked !== undefined && t.tuningAsked !== true && t.tuningAsked !== "preset") errors.push(`${tw}.tuningAsked must be true (its line's own tuning) or "preset" (its character's)`); errors.push(...tuningProblems(t.tuning, t.reading, tw)); if (t.forReading !== undefined && t.forReading !== true) errors.push(`${tw}.forReading must be true (or absent)`); if (t.read !== undefined && !(isObj(t.read) && t.read.kind === "thread" && JSON.stringify(t.read).length <= 4000)) errors.push(`${tw}.read must be {kind: "thread", …} (how the thread read was asked for)`); @@ -756,6 +761,7 @@ export function validatePostNarration(e) { if (p.speed !== undefined && !numIn(p.speed, POST_NARRATION_LIMITS.speed)) errors.push(`${pw}.speed must be ${POST_NARRATION_LIMITS.speed.join("–")} (the speed it was synthesized at)`); if (p.tempo !== undefined && !numIn(p.tempo, POST_NARRATION_LIMITS.tempo)) errors.push(`${pw}.tempo must be ${POST_NARRATION_LIMITS.tempo.join("–")} (its reading speed in the take)`); if (p.reading !== undefined || p.tuning !== undefined) errors.push(...tuningProblems(p.tuning, p.reading, pw)); + if (p.tuningAsked !== undefined && p.tuningAsked !== true && p.tuningAsked !== "preset") errors.push(`${pw}.tuningAsked must be true (the read's own tuning) or "preset" (its character's)`); if (p.role !== undefined && !(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d|linked:\d|screen:[a-z0-9][a-z0-9-]{0,23}:\d{1,2})$/.test(p.role))) errors.push(`${pw}.role must be post, quoted, parent:<i>, linked:<i>, media:<i> or screen:<id>:<line> (the text it reads)`); if (p.engine !== undefined && !POST_NARRATION_ENGINES.includes(p.engine)) errors.push(`${pw}.engine must be one of ${POST_NARRATION_ENGINES.join(", ")}`); if (p.take !== undefined && !(typeof p.take === "string" && n.takes.some((x) => x !== t && takeIdOf(x) === p.take))) errors.push(`${pw}.take must be the id of another of its takes (the take this part is)`);