commit c3ba0fed14d98a8295cf0bc51c2a26fea33ce22b
parent 4e39b056a6f03e78aff842d4b99835950a13f2bf
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 13 Nov 2026 01:13:31 -0500
umtool screens: a screen LINE recorded in the operator's voice, read only once chosen
`umtool posts screen <p> <item> record <id> <n> --recording <file>` (lib/report/screenLineRecord.mjs):
one line of a screen read by a person, through postNarrationCli.mjs importRecording's chain --
kept as a NEW recorded take, cleaned, converted to the line's SPEAKER's character's stock voice
(the author's own lines hers; a speaker with no character, or only the narrator, kept as
recorded with a note) -- each step a new take carrying `screenLine: {screen, n, said, speaker}`,
NONE picked, the item's script untouched. The prompt is the line as the read says it (its shapes
and redaction left out, an anonymous handle as its shown name); the take's script the same with
the lexicon. Refused on an item with no read of its own. --check-words (opt-in, the editor's
transcribe op) refuses a recording heard saying a shape, an @handle, an anonymous handle or a
redacted term before anything is kept, and warns on other words.
A line take is read ONLY when chosen: the screen's `lineTakes` ({"<n>": "<take id>"}, `set <id>
take.<n>=<take>|off`, the bench's select) or --line-take. Refused: a line take picked as the
item's read, used as --post-take, chosen for or named as another line, or read after its line's
words or speaker changed. A chosen take cannot be deleted until unchosen; a removed line takes
its choice with it. `read` names the recordings nobody chose; the lint warns of those, of a
chosen take recorded for the line as it was, and of a read that does not play its chosen take.
The writer now takes a line edited under a read (its words or speaker): the build refuses the
old read until it is made again, as the bench and the docs always said -- the guard's filter let
only a line left out through, not a line changed.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
10 files changed, 639 insertions(+), 28 deletions(-)
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -3114,7 +3114,8 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
const had = new Set(guard(was));
// A SCREEN's line the picked take reads that the screen no longer reads (post-screens.mjs) is the build's to refuse,
// not this write's: the read is re-made FROM the screens (umtool posts screen <p> <item> read), so they change first.
- const now = guard(e).filter((x) => !had.has(x) && !/ reads (?:line \d+ of )?screen [a-z0-9-]+,/.test(x));
+ // So is a line whose words or speaker CHANGED under the read (screenLineChanged): the build refuses the old read.
+ const now = guard(e).filter((x) => !had.has(x) && !/ reads (?:line \d+ of )?screen [a-z0-9-]+,/.test(x) && !/: line \d+ of screen [a-z0-9-]+ changed since the read /.test(x));
if (now.length) throw new StructureRefused(now);
}
return { id, at: i, entry: e };
diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs
@@ -37,6 +37,7 @@ import { withEditNotes } from "./edit-guard.mjs";
import { manifestToken, updatePostNarration, updatePostNarrationRender, updatePostNarrations } from "./manifest.mjs";
const execFileP = promisify(execFile);
+const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
const FFMPEG = () => process.env.FFMPEG_BIN ?? "ffmpeg";
const FFPROBE = () => process.env.FFPROBE_BIN ?? "ffprobe";
@@ -947,8 +948,10 @@ export async function deriveTake(project, e, { from, op, engine = null, voice =
...(Number.isFinite(m.lufs) ? { lufs: m.lufs } : {}), ...(parts ? { parts } : {}),
// Its audio is its source's words at its source's speed: what it said and where that speed came from, copied.
...(typeof t.speed === "number" ? { speed: t.speed } : {}), ...(t.speedAsked !== undefined ? { speedAsked: t.speedAsked } : {}), ...(typeof t.said === "string" ? { said: t.said } : {}),
+ // A recording of a screen line stays that line's (and, as it, never picked).
+ ...(isObj(t.screenLine) ? { screenLine: { ...t.screenLine } } : {}),
};
- const { result } = await withEditNotes(project, async () => updatePostNarration(project.dir, e.id, { addTake: take }, { token: await manifestToken(project.dir) }));
+ const { result } = await withEditNotes(project, async () => updatePostNarration(project.dir, e.id, { addTake: take, ...(isObj(t.screenLine) ? { keepPick: true } : {}) }, { token: await manifestToken(project.dir) }));
return { take, result };
}
@@ -969,7 +972,7 @@ export async function deriveTake(project, e, { from, op, engine = null, voice =
* kept either side), `pitch` / `semitones`. Each step a new take, the last one picked, with the disclosure line the
* cut will carry. Returns `{ takes: [{ step, file }], picked, notes, disclosure, character, direction }`.
*/
-export async function importRecording(project, e0, file, { as = null, label = "operator", clean = undefined, convert = true, trim = undefined, pitch = undefined, semitones = undefined, note = null, emit = () => {}, editor = null, ask = null } = {}) {
+export async function importRecording(project, e0, file, { as = null, label = "operator", clean = undefined, convert = true, trim = undefined, pitch = undefined, semitones = undefined, note = null, emit = () => {}, editor = null, ask = null, screenLine = null, script = null, character: given = undefined } = {}) {
const abs = path.resolve(String(file ?? ""));
if (!(await stat(abs).catch(() => null))?.isFile()) throw new NarrateError(`--recording takes a sound file (no ${file})`);
const { keepRecording } = await import("./postRecord.mjs");
@@ -977,16 +980,20 @@ export async function importRecording(project, e0, file, { as = null, label = "o
const { convertPitchLabel, recordedPresetOf, shownNameOf } = await import("umtool-report-to-video/cast");
const { postNarrationDisclosure } = await import("umtool-report-to-video/post-narration");
const layers = await readLayers(project.dir);
- const who = layers.characterForRead(e0, as);
+ // A SCREEN LINE's recording (screenLineRecord.mjs) is made into its SPEAKER's character, which the caller found
+ // (`character`: null -- none, kept as recorded); a read of the item into the item's (characterForRead).
+ const who = given !== undefined ? (given ? { character: given, layer: "line" } : null) : layers.characterForRead(e0, as);
const character = who?.character ?? null;
- if (as && !character) throw new NarrateError(`--as ${as}: no such character in this video's characters or the cast (umtool cast project ${project.id}, umtool cast ls)`);
+ if (as && !character && given === undefined) throw new NarrateError(`--as ${as}: no such character in this video's characters or the cast (umtool cast project ${project.id}, umtool cast ls)`);
const preset = character ? recordedPresetOf(character) : null;
const doClean = clean ?? preset?.enhance ?? true;
const doTrim = trim ?? (preset ? preset.trim : undefined);
const notes = [];
const takes = [];
const fresh = async () => findPostItem(await readManifest(project.dir), e0.id);
- const kept = await keepRecording(project, e0, [{ file: abs, text: String(e0.narration?.script ?? "") }], { label, manifest: await readManifest(project.dir), note: note ?? `recorded${character ? ` for ${shownNameOf(character)}` : ""}`, ...(doTrim ? { trim: doTrim } : {}) });
+ const kept = screenLine
+ ? await keepRecording(project, e0, [{ file: abs, text: String(script ?? "") }], { label, manifest: await readManifest(project.dir), note: note ?? `line ${screenLine.n} of screen ${screenLine.screen} recorded${character ? ` for ${shownNameOf(character)}` : ""}`, script: String(script ?? ""), screenLine, ...(doTrim ? { trim: doTrim } : {}) })
+ : await keepRecording(project, e0, [{ file: abs, text: String(e0.narration?.script ?? "") }], { label, manifest: await readManifest(project.dir), note: note ?? `recorded${character ? ` for ${shownNameOf(character)}` : ""}`, ...(doTrim ? { trim: doTrim } : {}) });
takes.push({ step: "recorded", file: kept.take.file });
emit("note", { message: `kept as recorded: ${kept.take.file} (levelled ${kept.gain >= 0 ? "+" : ""}${kept.gain} dB${doTrim?.on === false ? ", its edges not trimmed" : ""})` });
let e = await fresh();
@@ -1005,7 +1012,8 @@ export async function importRecording(project, e0, file, { as = null, label = "o
} else if (clean === undefined) notes.push(`not cleaned: ${character.id}'s recorded preset says so (enhance off)`);
if (convert) {
const target = character ? preset.convert : null;
- if (!character) notes.push("not converted: no character to convert to (--as <character>, the item's own, or the post's author or a narrator in the cast: umtool cast add …)");
+ if (!character && screenLine) notes.push(`not converted: line ${screenLine.n}'s speaker has no character to convert to -- kept as recorded (umtool cast add … --handle <the speaker's handle>, or --as <character>)`);
+ else if (!character) notes.push("not converted: no character to convert to (--as <character>, the item's own, or the post's author or a narrator in the cast: umtool cast add …)");
else if (!target.voice) notes.push(`not converted: ${character.id} has no stock voice to convert to (umtool cast ${who.layer === "cast" || who.layer === "narrator" ? "" : `project ${project.id} `}set ${character.id} --convert-voice <engine:voice>)`);
else {
// The pitch asked for this read, else the character's; semitones asked of the target's own pitch are dropped
@@ -1022,8 +1030,11 @@ export async function importRecording(project, e0, file, { as = null, label = "o
}
}
}
+ // A line's: none picked; its disclosure the one its line will carry in the read (a recorded reading, converted or not).
+ const conv = screenLine ? (e?.narration?.takes ?? []).find((t) => t.file === takes.at(-1).file)?.steps?.find((st) => st?.op === "convert") : null;
return {
- takes, picked: takes.at(-1).file, notes, disclosure: e ? postNarrationDisclosure(e) : null,
+ takes, picked: screenLine ? null : takes.at(-1).file, notes,
+ disclosure: screenLine ? (conv ? `a recorded reading converted to a stock voice (${conv.engine ?? "?"} · ${conv.voice ?? "?"})` : "a recorded reading") : e ? postNarrationDisclosure(e) : null,
character: character ? { id: character.id, name: shownNameOf(character), voice: character.voice ?? null, layer: who.layer } : null,
...(preset?.direction ? { direction: preset.direction } : {}),
};
@@ -1043,6 +1054,9 @@ export async function deleteTake(project, e, index) {
const id = takeIdOf(t);
const users = takes.map((x, i) => ({ x, n: i + 1 })).filter(({ x }) => x !== t && ((Array.isArray(x?.parts) && x.parts.some((p) => p?.take === id || (p?.take && p?.file === t.file))) || (x?.source?.kind === "take" && x.source.from === id)));
if (users.length) throw new NarrateError(`take ${index + 1} (${t.file}) is a part of ${users.map(({ x, n }) => `take ${n} (${x.file})`).join(", ")}: delete ${users.length === 1 ? "that take" : "those takes"} first -- nothing moved`);
+ // A take a screen CHOSE for one of its lines (`lineTakes`): unchosen first.
+ const chooser = (Array.isArray(e.screens) ? e.screens : []).flatMap((sc) => Object.entries(isObj(sc?.lineTakes) ? sc.lineTakes : {}).filter(([, v]) => v === id).map(([k]) => ({ sc: sc.id, k })))[0];
+ if (chooser) throw new NarrateError(`take ${index + 1} (${t.file}) is chosen for line ${chooser.k} of screen ${chooser.sc}: unchoose it first (umtool posts screen <p> ${e.id} set ${chooser.sc} take.${chooser.k}=off) -- nothing moved`);
const trash = path.join(project.dir, ...takesDirOf(postIdOf(e)).split("/"), ".trash");
await mkdir(trash, { recursive: true });
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
diff --git a/umtool/lib/report/postRecord.mjs b/umtool/lib/report/postRecord.mjs
@@ -172,7 +172,7 @@ export const partsIn = (parts, relDir) => parts.map((p) => ({ n: p.n, para: p.pa
* @param {Array<{ file: string, text?: string, para?: number }>} parts
* @param {{ label?: string, manifest?: Record<string, any>, note?: string | null, script?: string | null, trim?: { on?: boolean, padMs?: number | null } | null, spans?: Array<{ from: number, to: number } | null> | null }} [o]
*/
-export async function keepRecording(project, entry, parts, { label = "operator", manifest = null, note = null, script = null, trim = null, spans = null } = {}) {
+export async function keepRecording(project, entry, parts, { label = "operator", manifest = null, note = null, script = null, trim = null, spans = null, screenLine = null } = {}) {
// A character's recorded preset (cast.mjs recordedPresetOf): its edges left as recorded (`trim.on` false), or the
// room kept either side of the words (`trim.padMs`); none: trimmed, RECORD_ROOM.
const room = roomOf(trim);
@@ -204,9 +204,11 @@ export async function keepRecording(project, entry, parts, { label = "operator",
file: rel, engine: "recorded", voice: label, label, seconds: j.seconds, source: { kind: "recorded", voice: label }, script: String(script ?? entry.narration?.script ?? ""),
at: new Date().toISOString(), ...(Number.isFinite(j.lufs) ? { lufs: j.lufs } : {}), ...(note ? { note } : {}),
...(partsOut.length > 1 ? { parts: partsOut } : {}),
+ // A RECORDING OF ONE SCREEN LINE (screenLineRecord.mjs): the line it is of; its script the line's words.
+ ...(screenLine ? { screenLine } : {}),
};
- const { result, editNotes } = await withEditNotes(project, async () =>
- updatePostNarration(project.dir, entry.id, { addTake: take, ...(script !== null && script !== entry.narration?.script ? { script } : {}) }, { token: await manifestToken(project.dir) }),
- );
+ // A line's recording is never the item's read: not picked, and the item's script left as it is.
+ const patch = screenLine ? { addTake: take, keepPick: true } : { addTake: take, ...(script !== null && script !== entry.narration?.script ? { script } : {}) };
+ const { result, editNotes } = await withEditNotes(project, async () => updatePostNarration(project.dir, entry.id, patch, { token: await manifestToken(project.dir) }));
return { take, gain: j.gain, target, result, editNotes };
}
diff --git a/umtool/lib/report/postScreensCli.mjs b/umtool/lib/report/postScreensCli.mjs
@@ -11,6 +11,8 @@
// umtool posts screen <p> <item> rm <id> [--json]
// umtool posts screen <p> <item> check <id> [--by <name>] [--undo] [--json]
// umtool posts screen <p> <item> read [--post-take <n>] [--line-take screen:<id>:<n>=<take n>]… [--force] [--dry-run] [--json] …
+// umtool posts screen <p> <item> record <id> <n> --recording <file> [--as <character>] [--no-clean|--clean] [--no-trim|--trim]
+// [--no-convert] [--pitch …] [--semitones n] [--label l] [--check-words [--worker w]] [--events] [--json]
//
// Every write goes through the post item's one writer (manifest.mjs updatePostItem, `screens`: the whole list, under
// the manifest's token), refused in the build's words. `read` is the thread read (postThreadRead.mjs) with the screens:
@@ -23,7 +25,8 @@
// Plain ESM: the CLI runs it under bare node.
import { readFile } from "node:fs/promises";
import path from "node:path";
-import { draftScript } from "umtool-report-to-video/post-narration";
+import { draftScript, takeIdOf } from "umtool-report-to-video/post-narration";
+import { chosenLineTakes, lineTakesOf as lineRecordingsOf } from "umtool-report-to-video/post-thread";
import { voiceOverridesOf } from "umtool-report-to-video/post-say";
import { readManifest } from "../projects/report.mjs";
import { withEditNotes } from "./edit-guard.mjs";
@@ -40,6 +43,8 @@ export const SCREEN_USAGE = [
" umtool posts screen <project> <item> rm <id> [--json]",
" umtool posts screen <project> <item> check <id> [--by <name>] [--undo] [--json]",
" umtool posts screen <project> <item> read [--post-take <n>] [--line-take screen:<id>:<line>=<n>]… [--voice-for h=v]… [--force] [--dry-run] [--json]",
+ " umtool posts screen <project> <item> record <id> <line> --recording <file> [--as <character>] [--no-clean|--clean] [--no-trim|--trim]",
+ " [--no-convert] [--pitch target|source|contour] [--semitones n] [--label l] [--check-words [--worker w]] [--events] [--json]",
" A post's SCREENS: the text screenshots it carries (a DM exchange or an email in its video, a screenshot attached),",
" transcribed once, drawn on its card and read in the voices of the people in them, each line lit while it is said.",
" --media: the attachment it is in (its index); --at: the seconds of a video it is visible in. --read: the lines read",
@@ -49,11 +54,16 @@ export const SCREEN_USAGE = [
" picture (--media: another attachment), kind text (--kind), read whole, NOT checked; no speakers (set them after).",
" set keys: kind= title=|off media= at=<a>,<b>|off unread= ref=|off read=all|none|<n>,… read.<n>=\"excerpt\"|on|off",
" line.add=\"who: words\" line.<n>=off line.<n>.who=|off line.<n>.side=left|right|auto line.<n>.text=",
- " line.<n>.time=|off line.<n>.redact=on|off",
+ " line.<n>.time=|off line.<n>.redact=on|off take.<n>=<take n>|off (the recording read in line n's place)",
" check: the transcription read against the screenshot (by you, now); --undo takes it back. A screen not checked is a",
" lint WARNING. An e-mail address, a phone number, an order or reference number in a line is masked whatever you do.",
" read: the thread read with the screens (posts narrate <p> <item> --take --thread): his words from the take that plays",
- " (--post-take n: another), each read line in its speaker's voice; --line-take: that line from the item's take n.",
+ " (--post-take n: another), each read line in its speaker's voice; --line-take: that line from the item's take n;",
+ " a line's CHOSEN take (take.<n>=, the bench's select) in its place. A recording nobody chose is said, never read in.",
+ " record: ONE LINE in your voice -- the line as the read says it (its shapes and redaction left out) recorded, then",
+ " cleaned and converted to its SPEAKER's character's stock voice (none: kept as recorded), each a new take, none of",
+ " them picked; choose it for the line (set <id> take.<n>=<take>), then read. --check-words (the editor's transcribe",
+ " op): refused when it is heard saying a shape, an @handle, an anonymous handle or a redacted term; nothing kept.",
].join("\n");
export class ScreenUsageError extends Error {
@@ -109,7 +119,7 @@ const readOf = (v) => (v === "all" || v === "none" ? v : numList(v, "read").map(
* A screen with `key=value` pairs laid on (the `set` keys, SCREEN_USAGE), pure; a copy. Throws ScreenUsageError for a
* key it does not know or a value it cannot read; what the build refuses is the writer's to say.
*/
-export function applyPairs(screen, pairs) {
+export function applyPairs(screen, pairs, { takeId = null } = {}) {
const sc = JSON.parse(JSON.stringify(screen));
sc.lines = Array.isArray(sc.lines) ? sc.lines : [];
const lineAt = (n) => {
@@ -173,6 +183,18 @@ export function applyPairs(screen, pairs) {
} else if (f === "text") l.text = v;
else if (off) delete l[f];
else l[f] = v;
+ } else if ((m = /^take\.(\d{1,2})$/.exec(key))) {
+ // The take CHOSEN for a line (a recording of it): its number as --list counts, made its id; off unchooses.
+ const n = Number(m[1]);
+ lineAt(n);
+ const lt = isObj(sc.lineTakes) ? { ...sc.lineTakes } : {};
+ if (off) delete lt[String(n)];
+ else {
+ if (!takeId) fail(`${key}= takes a take's number (posts screen <p> <item> list shows the line's recordings)`);
+ lt[String(n)] = takeId(v, n);
+ }
+ if (Object.keys(lt).length) sc.lineTakes = lt;
+ else delete sc.lineTakes;
} else fail(`${key} is not a screen's knob (posts screen --help)`);
}
// Lines removed: the read's line numbers follow them (a dropped line's read goes too) -- the bench's rule too.
@@ -188,13 +210,16 @@ export function nextScreenId(e) {
/** One screen as listing lines (text). */
export function screenListing(e, sc) {
const reads = new Map(screenReadLines(sc).map((r) => [r.n, r]));
+ const recordings = lineRecordingsOf(e);
const m = (Array.isArray(e.media) ? e.media : [])[sc.media];
const head = `${sc.id} ${sc.kind}${sc.title ? ` "${sc.title}"` : ""} attachment ${sc.media}${m ? ` (${m.kind})` : ""}${Array.isArray(sc.at) ? ` at ${sc.at[0]}–${sc.at[1]} s` : ""} read ${sc.read === "all" ? "all" : sc.read === "none" ? "none (transcribed only)" : `${reads.size} line(s)`}${sc.unread === "dim" ? ", the rest dim" : ""} ${sc.checked ? `checked by ${sc.checked.by} ${String(sc.checked.at).slice(0, 10)}` : "NOT CHECKED"}`;
const rows = sc.lines.map((l, n) => {
const r = reads.get(n);
const mark = l?.redact ? "x" : r ? (r.cutBefore || r.cutAfter ? "~" : "*") : " ";
const ex = r && (r.cutBefore || r.cutAfter) ? ` [reads: "${str(l.text).slice(r.start, r.end)}"]` : "";
- return ` ${mark} ${String(n).padStart(2)} ${(l?.side ? `[${l.side}] ` : "") + (l?.who ? `${l.who}: ` : "- ")}${l?.redact ? "(redacted)" : str(l?.text)}${l?.time ? ` | ${l.time}` : ""}${ex}`;
+ const recs = recordings.find((L) => L.screen === sc.id && L.n === n);
+ const rec = recs ? ` [recorded: ${recs.takes.map((x) => `take ${x.n}${x.chosen ? " (chosen)" : ""}${x.current ? "" : " (line changed since)"}`).join(", ")}]` : "";
+ return ` ${mark} ${String(n).padStart(2)} ${(l?.side ? `[${l.side}] ` : "") + (l?.who ? `${l.who}: ` : "- ")}${l?.redact ? "(redacted)" : str(l?.text)}${l?.time ? ` | ${l.time}` : ""}${ex}${rec}`;
});
return [head, ...rows];
}
@@ -222,7 +247,8 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
const entry = result.entry;
const { pickedTake, isNarrated } = await import("umtool-report-to-video/post-narration");
const { partRoles } = await import("umtool-report-to-video/post-thread");
- const warnings = screenWarnings(entry, { narrated: isNarrated(entry), takeRoles: pickedTake(entry) ? partRoles(entry).map((r) => r.role) : [] });
+ const { lineTakeWarnings } = await import("umtool-report-to-video/post-thread");
+ const warnings = [...screenWarnings(entry, { narrated: isNarrated(entry), takeRoles: pickedTake(entry) ? partRoles(entry).map((r) => r.role) : [] }), ...lineTakeWarnings(entry)];
const { threadReadErrors } = await import("umtool-report-to-video/post-thread");
const { followKnobs } = await import("umtool-report-to-video/read-follow");
const { planContext } = await import("umtool-report-to-video/post-conversation");
@@ -312,7 +338,14 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
}
const pairs = words.slice(1);
if (!pairs.length && !flag("--from")) fail("set <id> <key>=<value>… (posts screen --help)");
- next = applyPairs(next, pairs);
+ next = applyPairs(next, pairs, { takeId: (v, n) => {
+ const takes = Array.isArray(e.narration?.takes) ? e.narration.takes : [];
+ const k = Number(v);
+ if (!/^\d{1,3}$/.test(String(v)) || k < 1 || k > takes.length) fail(`take.${n}= takes a take's number (1–${takes.length}) or off`);
+ const t = takes[k - 1];
+ if (!isObj(t?.screenLine) || t.screenLine.screen !== sc.id || t.screenLine.n !== n) fail(`take ${k} is not a recording of line ${n} of screen ${sc.id}${isObj(t?.screenLine) ? ` (it is of line ${t.screenLine.n} of screen ${t.screenLine.screen})` : ""}: record it (posts screen <p> ${e.id} record ${sc.id} ${n} --recording <file>)`);
+ return takeIdOf(t);
+ } });
// Words changed: what was checked is not what is there now.
if (JSON.stringify(next.lines) !== JSON.stringify(sc.lines)) delete next.checked;
return write(screens.map((s) => (s.id === sc.id ? next : s)), `set screen ${sc.id}`);
@@ -336,10 +369,54 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
const o = screenReadOptions(e, { flags, flag, multi });
return threadCommand(project, e, {
manifest, json, out, ...o, parents: parentsSelector(o.parents), engine: flag("--engine"), note: flag("--note"), force: flags.has("--force"), hold: !flags.has("--no-hold"), dryRun,
- postTake, lineTakes: { ...defaultLineTakes(e), ...lineTakesOf(multi("--line-take")) },
+ // The playing read's (re-attached while their lines say the same), the screens' CHOSEN ones over them, the flags' over all.
+ postTake, lineTakes: { ...defaultLineTakes(e), ...chosenLineTakes(e), ...lineTakesOf(multi("--line-take")) },
});
}
- fail(`posts screen ${verb}: list, add, set, rm, check or read`);
+ if (verb === "record") {
+ // ONE LINE in a person's voice (screenLineRecord.mjs): new takes, none picked; chosen for its line by hand.
+ const sc = byId(words[0]);
+ if (!/^\d{1,2}$/.test(String(words[1] ?? ""))) fail(`record ${sc.id} <line>: which line (0–${sc.lines.length - 1})?`);
+ const file = flag("--recording");
+ if (!file) fail("record takes --recording <file> (a sound file: your read of the line)");
+ const { recordScreenLine, LineRecordError } = await import("./screenLineRecord.mjs");
+ const events = flags.has("--events");
+ const role = `screen:${sc.id}:${Number(words[1])}`;
+ let r;
+ try {
+ r = await recordScreenLine(project, e.id, role, path.resolve(String(file)), {
+ as: flag("--as"), label: flag("--label") ?? "operator",
+ clean: flags.has("--no-clean") ? false : flags.has("--clean") ? true : undefined,
+ ...(flags.has("--no-trim") ? { trim: { on: false, padMs: null } } : flags.has("--trim") ? { trim: { on: true, padMs: null } } : {}),
+ convert: !flags.has("--no-convert"), note: flag("--note"),
+ ...(flag("--pitch") !== null ? { pitch: flag("--pitch") } : {}), ...(flag("--semitones") !== null ? { semitones: Number(flag("--semitones")) } : {}),
+ checkWords: flags.has("--check-words"), worker: flag("--worker"),
+ emit: (ev, f) => (events ? out(JSON.stringify({ ev, ...f })) : !json && f?.message && out(f.message)),
+ });
+ } catch (err) {
+ const { NarrateError } = await import("./postNarrationCli.mjs");
+ if (err instanceof LineRecordError || err instanceof NarrateError) {
+ if (events || json) out(JSON.stringify({ ...(events ? { ev: "result" } : {}), ok: false, id: e.id, role, error: err.message }));
+ else out(`refused: ${err.message}`);
+ return 1;
+ }
+ throw err;
+ }
+ const m2 = await readManifest(project.dir);
+ const after = (m2?.timeline ?? []).find((x) => x?.id === e.id);
+ const numbers = r.takes.map((x) => 1 + (after?.narration?.takes ?? []).findIndex((t) => t.file === x.file));
+ const res = { ok: true, id: e.id, role, takes: r.takes.map((x, i) => ({ ...x, n: numbers[i] })), notes: r.notes, disclosure: r.disclosure, character: r.character, prompt: r.line.prompt };
+ if (events) out(JSON.stringify({ ev: "result", ...res }));
+ else if (json) out(JSON.stringify(res, null, 2));
+ else {
+ out(`${e.id}: line ${words[1]} of screen ${sc.id} recorded -- ${r.takes.map((x, i) => `take ${numbers[i]} ${x.step}`).join(", ")}; none picked`);
+ for (const n of r.notes) out(` ${n}`);
+ out(` disclosure in the read: ${r.disclosure}`);
+ out(` choose it for the line: umtool posts screen ${project.id} ${e.id} set ${sc.id} take.${words[1]}=${numbers.at(-1)} then: umtool posts screen ${project.id} ${e.id} read`);
+ }
+ return 0;
+ }
+ fail(`posts screen ${verb}: list, add, set, rm, check, read or record`);
return 2;
}
@@ -377,6 +454,8 @@ export function defaultLineTakes(e) {
const m = /^screen:([a-z0-9][a-z0-9-]{0,23}):(\d{1,2})$/.exec(role);
const sc = m ? screensOf(e).find((s) => s.id === m[1]) : null;
const now = sc ? lineWritten(screenLineSaid(sc, Number(m[2]))) : "";
+ // A RECORDING OF A LINE (`screenLine`) is read in only while the screen CHOOSES it (chosenLineTakes): never re-attached here.
+ if (at >= 0 && isObj(takes[at]?.screenLine)) continue;
if (at >= 0 && typeof x?.line === "string" && now && norm(x.line) === norm(now)) out[role] = at + 1;
}
return out;
diff --git a/umtool/lib/report/postScreensRound2.test.mjs b/umtool/lib/report/postScreensRound2.test.mjs
@@ -100,3 +100,215 @@ test("the CLI: posts screen … add --from-read writes one screen from narration
assert.equal(r.code, 2);
assert.match(r.text, /not a picture-only post/);
});
+
+// ---------------------------------------------------------------------------
+// ITEM 1: a screen line recorded by the operator
+// ---------------------------------------------------------------------------
+
+const DM = { id: "s1", media: 0, kind: "dm", read: "all", lines: [
+ { who: "TheQuartering", text: "what's your email so I can refund your order" },
+ { who: "MadamSavvy", text: "call me at 555 201 4477 tonight" },
+ { who: "TheQuartering", text: "You can't be this dumb" },
+ { who: "Stranger", text: "who is this" },
+ { who: "TheQuartering", text: "ask @secretkid about it" },
+] };
+const OWN = { file: "narration/posts/2117/take-1.recorded-operator.wav", engine: "recorded", voice: "operator", label: "operator", seconds: 1.4, script: "Hey, you told me. Your turn.", source: { kind: "recorded", voice: "operator" } };
+const SAVVY = {
+ type: "post", id: "p-2117", post: "savvy-x/2117", platform: "x", author: "Savvy", handle: "MadamSavvy", date: "2026-11-02T01:40:36.000Z",
+ text: "Hey, you told me. Your turn.", subjects: ["MadamSavvy"], media: [IMG], screens: [DM],
+ narration: { script: "Hey, you told me. Your turn.", takes: [OWN], pick: 0 },
+};
+// This video's characters: TheQuartering converts to a stock voice; Savvy (the author) to hers; the narrator is never a line's.
+const CHARS = { format: "umtool-project-characters", version: 1, characters: [
+ { id: "tq", name: "Jeremy", handles: ["thequartering"], synthetic: { voice: "kokoro:am_michael" }, recorded: { convert: { engine: "openvoice", voice: "kokoro:am_michael" } } },
+ { id: "savvy", name: "Savvy", handles: ["madamsavvy"], synthetic: { voice: "kokoro:af_bella" }, recorded: { convert: { engine: "openvoice", voice: "kokoro:af_bella" } } },
+ { id: "kid", name: "Secret Kid", handles: ["secretkid"], anonymous: true, shown: "Kid A" },
+] };
+async function savvy(name, item = SAVVY, chars = CHARS) {
+ const p = await project(name, item);
+ await mkdir(path.join(p.dir, "narration"), { recursive: true });
+ if (chars) await writeFile(path.join(p.dir, "narration", "characters.json"), JSON.stringify(chars));
+ return p;
+}
+/** The editor's ops, stubbed: each writes its out file as a tone and answers as the editor does. */
+const stubOps = (asked, heard = null) => async (route, body) => {
+ asked.push({ route, body });
+ if (route === "/api/ops/transcribe") {
+ await writeFile(body.out, JSON.stringify({ words: String(heard ?? "").split(/\s+/).filter(Boolean).map((w, i) => ({ w, start: i * 0.3, end: i * 0.3 + 0.25 })) }));
+ return { jobId: `job-t${asked.length}`, result: {} };
+ }
+ await wavOf(body.out, VOICE_B, 1);
+ return { jobId: `job-${asked.length}`, result: route.endsWith("voice-convert") ? { op: "convert", engine: body.engine ?? "openvoice", voice: String(body.voice ?? "").split(":").pop() } : { op: "enhance", engine: "deepfilternet" } };
+};
+const stubTts = (asked) => async (body) => {
+ asked.push(body);
+ await wavOf(body.out, VOICE_B, 0.6);
+ return { jobId: `tts-${asked.length}`, result: { wav: body.out } };
+};
+const recording = async (p, name = "rec.wav") => {
+ const f = path.join(ROOT, `${p.id}-${name}`);
+ await wavOf(f, VOICE_A, 1.2);
+ return f;
+};
+const NO_RED = { terms: [], markup: {}, slurs: null };
+
+test("lineToRecord: the line as the read says it -- its shapes left out, an anonymous handle as its shown name, the lexicon only in the script; a line not read or redacted refused", async () => {
+ const { lineToRecord } = await import("./screenLineRecord.mjs");
+ const red = { terms: [], markup: {}, slurs: null, say: [{ word: "dumb", say: "dumm" }], anon: new Map([["secretkid", "Kid A"]]) };
+ const a = lineToRecord(SAVVY, "screen:s1:2", { red });
+ assert.equal(a.prompt, "You can't be this dumb");
+ assert.equal(a.script, "You can't be this dumm", "the script says it the lexicon's way: what the read holds the take to");
+ assert.equal(a.written, "You can't be this dumb");
+ assert.deepEqual([a.speaker, a.handle, a.self], ["TheQuartering", "TheQuartering", false]);
+ const b = lineToRecord(SAVVY, "screen:s1:1", { red });
+ assert.ok(!/555|4477/.test(b.prompt + b.script + b.written), "a masked number is never in the prompt nor the script (R2 #2)");
+ assert.equal(b.self, true);
+ const c = lineToRecord(SAVVY, "screen:s1:4", { red });
+ assert.ok(!/secretkid/i.test(c.prompt + c.script) && /Kid A/.test(c.script), "an anonymous handle said as its shown name");
+ const unread = { ...SAVVY, screens: [{ ...DM, read: [{ line: 0 }] }] };
+ assert.throws(() => lineToRecord(unread, "screen:s1:2", { red }), /not read by the screen/);
+ const redacted = { ...SAVVY, screens: [{ ...DM, lines: DM.lines.map((l, n) => (n === 2 ? { ...l, redact: true } : l)) }] };
+ assert.throws(() => lineToRecord(redacted, "screen:s1:2", { red }), /redacted/);
+ assert.throws(() => lineToRecord(SAVVY, "screen:s9:0", { red }), /no screen s9/);
+ assert.throws(() => lineToRecord(SAVVY, "screen:s1:9", { red }), /no line 9/);
+});
+
+test("record: recorded, cleaned, converted to the SPEAKER's character's stock voice -- each a new take, none picked, the item's script untouched; a line take, never the item's read", async () => {
+ const { recordScreenLine } = await import("./screenLineRecord.mjs");
+ const p = await savvy("rec");
+ const asked = [];
+ const r = await recordScreenLine(p, "p-2117", "screen:s1:2", await recording(p), { ask: stubOps(asked) });
+ assert.deepEqual(asked.map((x) => x.route), ["/api/ops/voice-enhance", "/api/ops/voice-convert"]);
+ assert.equal(asked[1].body.voice, "kokoro:am_michael", "TheQuartering's character's stock voice");
+ assert.equal(r.picked, null);
+ assert.equal(r.disclosure, "a recorded reading converted to a stock voice (openvoice · kokoro:am_michael)");
+ assert.equal(r.line.prompt, "You can't be this dumb");
+ const n = (await read(p)).timeline[0].narration;
+ assert.equal(n.pick, 0, "his own read still plays");
+ assert.equal(n.script, SAVVY.narration.script, "the item's script untouched");
+ assert.equal(n.takes.length, 4);
+ for (const t of n.takes.slice(1)) {
+ assert.deepEqual(t.screenLine, { screen: "s1", n: 2, said: "You can't be this dumb", speaker: "TheQuartering" });
+ assert.equal(t.script, "You can't be this dumb");
+ }
+ assert.match(n.takes[1].file, /take-2\.recorded-operator\.wav$/, "a NEW recorded file");
+ assert.equal(n.takes[3].steps[0].op, "convert");
+ // The original recording of his words is untouched (never rewritten).
+ assert.equal(n.takes[0].file, OWN.file);
+ // Picking a line take is refused in the build's words.
+ const { updatePostNarration } = await import("./manifest.mjs");
+ await assert.rejects(() => updatePostNarration(p.dir, "p-2117", { pick: 3 }), /take 4 is a recording of line 2 of screen s1/);
+});
+
+test("record: a speaker with no character is kept as recorded (a note); the author's own line converts to HER character, never the narrator", async () => {
+ const { recordScreenLine } = await import("./screenLineRecord.mjs");
+ const p = await savvy("rec-who");
+ const asked = [];
+ const a = await recordScreenLine(p, "p-2117", "screen:s1:3", await recording(p, "a.wav"), { ask: stubOps(asked) });
+ assert.ok(a.notes.some((x) => /line 3's speaker has no character to convert to -- kept as recorded/.test(x)));
+ assert.ok(!asked.some((x) => x.route.endsWith("voice-convert")));
+ assert.equal(a.disclosure, "a recorded reading");
+ const b = await recordScreenLine(p, "p-2117", "screen:s1:1", await recording(p, "b.wav"), { ask: stubOps(asked) });
+ assert.equal(asked.at(-1).body.voice, "kokoro:af_bella");
+ assert.match(b.disclosure, /af_bella/);
+ // A cast narrator is never a line's character.
+ const p2 = await savvy("rec-narr", SAVVY, null);
+ await mkdir(path.join(p2.dir, ".umtool"), { recursive: true });
+ await writeFile(path.join(p2.dir, ".umtool", "cast.json"), JSON.stringify({ format: "umtool-cast", version: 1, characters: [{ id: "me", name: "Me", handles: ["operator"], voice: "kokoro:bm_george", convert: { engine: "openvoice" }, narrator: true }] }));
+ const asked2 = [];
+ const c = await recordScreenLine(p2, "p-2117", "screen:s1:0", await recording(p2), { ask: stubOps(asked2) });
+ assert.ok(!asked2.some((x) => x.route.endsWith("voice-convert")), "no convert to the narrator");
+ assert.ok(c.notes.some((x) => /no character/.test(x)));
+});
+
+test("record is refused on an item with no read of its own; --check-words refuses a recording heard saying a number or a handle (nothing kept) and warns on other words", async () => {
+ const { recordScreenLine } = await import("./screenLineRecord.mjs");
+ const bare = await savvy("rec-bare", { ...SAVVY, narration: undefined });
+ await assert.rejects(() => recordScreenLine(bare, "p-2117", "screen:s1:2", path.join(ROOT, "nope.wav"), { ask: stubOps([]) }), /no read of its own yet/);
+ const p = await savvy("rec-check");
+ const file = await recording(p);
+ for (const heard of ["call me at 555 201 4477 tonight", "you can't be this dumb @secretkid", "you can't be secretkid this dumb"]) {
+ await assert.rejects(() => recordScreenLine(p, "p-2117", "screen:s1:2", file, { ask: stubOps([], heard), checkWords: true }), /--check-words: .* refused -- it is heard saying/, heard);
+ }
+ assert.equal((await read(p)).timeline[0].narration.takes.length, 1, "a refusal keeps nothing");
+ assert.equal((await readdir(path.join(p.dir, "narration/posts/2117"))).filter((f) => f.startsWith(".line-check")).length, 0, "its scratch is gone");
+ const w = await recordScreenLine(p, "p-2117", "screen:s1:2", file, { ask: stubOps([], "you can this be dumb"), checkWords: true, convert: false, clean: false });
+ assert.ok(w.notes.some((x) => /not the line's in order/.test(x)));
+ const ok = await recordScreenLine(p, "p-2117", "screen:s1:2", file, { ask: stubOps([], "You can't be this dumb"), checkWords: true, convert: false, clean: false });
+ assert.ok(ok.notes.some((x) => /heard saying the line/.test(x)));
+});
+
+test("a line take is read ONLY when chosen: the screen's lineTakes (set <id> take.<n>=) or --line-take; another line's or a stale one refused; the disclosure says what it is", async () => {
+ const { recordScreenLine } = await import("./screenLineRecord.mjs");
+ const { threadTake, postTakeOf } = await import("./postThreadRead.mjs");
+ const { postNarrationDisclosure } = await import("umtool-report-to-video/post-narration");
+ const { lineTakeWarnings, threadReadErrors } = await import("umtool-report-to-video/post-thread");
+ const p = await savvy("choose");
+ await recordScreenLine(p, "p-2117", "screen:s1:2", await recording(p), { ask: stubOps([]) });
+ let e = (await read(p)).timeline[0];
+ // Not chosen: synthesized, and said so.
+ const tts = [];
+ let r = await posts(["screen", "choose", "p-2117", "read", "--dry-run"]);
+ assert.equal(r.code, 0, r.text);
+ assert.match(r.text, /screen:s1:2 is synthesized: its recordings take 2, take 3, take 4 not chosen -- --line-take screen:s1:2=4/);
+ assert.ok(lineTakeWarnings(e).some((x) => /line 2 of screen s1 has a recording no read uses/.test(x)));
+ // Chosen by number; another line's take refused; off unchooses.
+ r = await posts(["screen", "choose", "p-2117", "set", "s1", "take.0=4"]);
+ assert.equal(r.code, 2);
+ assert.match(r.text, /take 4 is not a recording of line 0 of screen s1 \(it is of line 2 of screen s1\)/);
+ r = await posts(["screen", "choose", "p-2117", "set", "s1", "take.2=4"]);
+ assert.equal(r.code, 0, r.text);
+ e = (await read(p)).timeline[0];
+ assert.deepEqual(e.screens[0].lineTakes, { 2: "take-4.convert-openvoice" });
+ r = await posts(["screen", "choose", "p-2117", "list"]);
+ assert.match(r.text, /2 TheQuartering: You can't be this dumb {3}\[recorded: take 2, take 3, take 4 \(chosen\)\]/);
+ const made = await threadTake(p, e, { red: NO_RED, ask: stubTts(tts), lanes: null, postTake: 1 });
+ const parts = made.take.parts;
+ assert.equal(parts.find((x) => x.role === "screen:s1:2").take, "take-4.convert-openvoice");
+ assert.ok(!tts.some((b) => /dumb/.test(b.text)), "the chosen line is not synthesized");
+ const after1 = (await read(p)).timeline[0];
+ assert.deepEqual(threadReadErrors(after1, {}), []);
+ assert.deepEqual(lineTakeWarnings(after1), []);
+ // The disclosure names the converted recording (and the synthetic voices of the rest).
+ assert.match(postNarrationDisclosure(after1), /a recorded reading converted to a stock voice \(openvoice · kokoro:am_michael\)/);
+ // A line take is never his words, and never another line's.
+ assert.throws(() => postTakeOf(after1, 4), /a recording of line 2 of screen s1: it is read in that line's place/);
+ assert.throws(() => postTakeOf(after1, 4, { line: "screen:s1:0" }), /not of screen:s1:0/);
+ await assert.rejects(() => threadTake(p, after1, { red: NO_RED, ask: stubTts([]), lanes: null, postTake: 1, lineTakes: { "screen:s1:0": 4 }, force: true }), /not of screen:s1:0/);
+ // The line edited since it was recorded: the chosen take is refused, never played under new words (R1 #1).
+ r = await posts(["screen", "choose", "p-2117", "set", "s1", "line.2.text=You cannot be this dumb"]);
+ assert.equal(r.code, 0, r.text);
+ const edited = (await read(p)).timeline[0];
+ assert.ok(lineTakeWarnings(edited).some((x) => /its chosen take \(take 4\) was recorded for the line as it was/.test(x)));
+ await assert.rejects(() => threadTake(p, edited, { red: NO_RED, ask: stubTts([]), lanes: null, postTake: 1, force: true }), /recorded for line 2 of screen s1 as it was/);
+ // Given to another speaker since: the same.
+ r = await posts(["screen", "choose", "p-2117", "set", "s1", "line.2.text=You can't be this dumb", "line.2.who=Stranger"]);
+ assert.equal(r.code, 0, r.text);
+ const given = (await read(p)).timeline[0];
+ await assert.rejects(() => threadTake(p, given, { red: NO_RED, ask: stubTts([]), lanes: null, postTake: 1, force: true }), /recorded for line 2 of screen s1 as it was/);
+ r = await posts(["screen", "choose", "p-2117", "set", "s1", "take.2=off"]);
+ assert.equal(r.code, 0, r.text);
+ assert.equal((await read(p)).timeline[0].screens[0].lineTakes, undefined);
+ // A chosen take cannot be deleted until it is unchosen.
+ const q = await savvy("choose-del");
+ await recordScreenLine(q, "p-2117", "screen:s1:0", await recording(q), { ask: stubOps([]), clean: false, convert: false });
+ assert.equal((await posts(["screen", "choose-del", "p-2117", "set", "s1", "take.0=2"])).code, 0);
+ r = await posts(["narrate", "choose-del", "p-2117", "--delete", "2"]);
+ assert.notEqual(r.code, 0);
+ assert.match(r.text, /chosen for line 0 of screen s1: unchoose it first/);
+ assert.equal((await read(q)).timeline[0].narration.takes.length, 2, "nothing moved");
+});
+
+test("the data: lineTakes names a recording of that line; a line removed takes its choice with it, the later ones' keys move down", async () => {
+ const { withoutLines, validateScreens } = await import("umtool-report-to-video/post-screens");
+ const rec = (n, file) => ({ file, engine: "recorded", voice: "operator", seconds: 1, script: "x", screenLine: { screen: "s1", n, said: "x", speaker: "TheQuartering" } });
+ const e = { ...SAVVY, narration: { ...SAVVY.narration, takes: [OWN, rec(2, "narration/posts/2117/take-2.recorded-operator.wav"), rec(4, "narration/posts/2117/take-3.recorded-operator.wav")] } };
+ const sc = { ...DM, lineTakes: { 2: "take-2.recorded-operator", 4: "take-3.recorded-operator" } };
+ assert.deepEqual(validateScreens({ ...e, screens: [sc] }), []);
+ assert.ok(validateScreens({ ...e, screens: [{ ...DM, lineTakes: { 0: "take-2.recorded-operator" } }] }).some((x) => /take 2 is not a recording of line 0 of screen s1 \(it is of line 2/.test(x)));
+ assert.ok(validateScreens({ ...e, screens: [{ ...DM, lineTakes: { 2: "take-9.nope" } }] }).some((x) => /must be the id of one of the item's takes/.test(x)));
+ assert.ok(validateScreens({ ...e, screens: [{ ...DM, lineTakes: { 7: "take-2.recorded-operator" } }] }).some((x) => /has no line 7/.test(x)));
+ assert.deepEqual(withoutLines(sc, [2]).lineTakes, { 3: "take-3.recorded-operator" });
+ assert.deepEqual(withoutLines(sc, [0]).lineTakes, { 1: "take-2.recorded-operator", 3: "take-3.recorded-operator" });
+ assert.equal("lineTakes" in withoutLines({ ...DM, lineTakes: { 2: "x" } }, [2]), false);
+});
diff --git a/umtool/lib/report/postThreadRead.mjs b/umtool/lib/report/postThreadRead.mjs
@@ -58,7 +58,7 @@ import { mkdir, readdir, stat, writeFile } from "node:fs/promises";
import path from "node:path";
import { promisify } from "node:util";
import { POST_PART_GAP, draftScript, nextTakeNumber, pickedTake, postIdOf, postNarrationKnobs, scriptParts, takeFileOf, takeIdOf, takesDirOf } from "umtool-report-to-video/post-narration";
-import { chronoPieces } from "umtool-report-to-video/post-thread";
+import { chosenLineTakes, chronoPieces, lineTakesOf } from "umtool-report-to-video/post-thread";
import { cardText, parentsOf } from "umtool-report-to-video/post-item";
import { planContext } from "umtool-report-to-video/post-conversation";
import { spokenRead, termsFor } from "umtool-report-to-video/post-redact";
@@ -229,6 +229,13 @@ export function threadReadPlan(manifest, e, { red = null, map = {}, cast = {}, i
continue;
}
const lt = lineTakes?.[p.role] ?? null;
+ // A RECORDING OF A LINE (`screenLine`: posts screen … record) is that line's as it was recorded: another line's, or
+ // a line whose words or speaker changed since, is refused -- the old audio never plays under new lit text.
+ const sl = lt?.take?.screenLine;
+ if (sl && typeof sl === "object" && (str(sl.said).replace(/\s+/g, " ").trim() !== norm(written) || str(sl.speaker).trim().toLowerCase() !== str(p.who).trim().toLowerCase())) {
+ const sp = /^screen:([a-z0-9-]+):(\d+)$/.exec(p.role);
+ throw new ThreadReadError(`--line-take ${p.role}=${lt.n}: that take was recorded for line ${sp[2]} of screen ${sp[1]} as it was (its words or its speaker changed since) -- record the line again (umtool posts screen <p> ${e.id} record ${sp[1]} ${sp[2]} --recording <file>), or unchoose it (set ${sp[1]} take.${sp[2]}=off)`);
+ }
if (lt) {
// THE LINE FROM A TAKE (--line-take): that take's file is the line's piece, and its words are what the TAKE says
// (`said`, else its script -- as --post-take's are), so every check that reads a read's words reads the audio's.
@@ -360,7 +367,7 @@ export function takeVoiceOf(t) {
* THE TAKE A THREAD READ's own line may be (--post-take n, as --list numbers them), checked: `{ n, take }`. Refused: no
* such take, a THREAD take (its own context in it), one with no file.
*/
-export function postTakeOf(e, n) {
+export function postTakeOf(e, n, { line = null } = {}) {
const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : [];
const k = Number(n);
if (!Number.isInteger(k) || k < 1) throw new ThreadReadError(`--post-take takes a take's number as --list shows it (1 = the first), not ${n}`);
@@ -368,6 +375,10 @@ export function postTakeOf(e, n) {
const t = takes[k - 1];
if (!t || typeof t.file !== "string" || !t.file) throw new ThreadReadError(`--post-take ${k}: that take has no file`);
if (/-thread\.wav$/.test(t.file) || t.read?.kind === "thread") throw new ThreadReadError(`--post-take ${k} is a thread read itself (${t.file}): name a take of his line alone`);
+ // A RECORDING OF A SCREEN LINE (`screenLine`) is that line's alone: never his words, never another line.
+ const sl = t.screenLine && typeof t.screenLine === "object" ? t.screenLine : null;
+ if (sl && line === null) throw new ThreadReadError(`--post-take ${k} is a recording of line ${sl.n} of screen ${sl.screen}: it is read in that line's place (--line-take screen:${sl.screen}:${sl.n}=${k}), never as his words`);
+ if (sl && line !== null && line !== `screen:${sl.screen}:${sl.n}`) throw new ThreadReadError(`--post-take ${k} is a recording of line ${sl.n} of screen ${sl.screen}, not of ${line}`);
return { n: k, take: t };
}
@@ -474,10 +485,12 @@ export async function threadTake(project, e, opts = {}) {
const item = item0 !== undefined ? item0 : L?.itemOf(e) ?? null;
const postTake = postTakeN === null || postTakeN === undefined ? null : postTakeOf(e, postTakeN);
// A screen line from a take (--line-take): checked as --post-take's is.
- const lineTakes = Object.fromEntries(Object.entries(lineTakesN ?? {}).map(([role, n]) => {
+ // The takes the screens CHOSE for their lines (`lineTakes`, the operator's: the bench's select, `set <id> take.<n>=`),
+ // under the ones the command names -- never one nobody chose.
+ const lineTakes = Object.fromEntries(Object.entries({ ...chosenLineTakes(e), ...(lineTakesN ?? {}) }).map(([role, n]) => {
if (!parseScreenRole(role)) throw new ThreadReadError(`--line-take names a screen's line as screen:<id>:<n> (got ${role})`);
try {
- return [role, postTakeOf(e, n)];
+ return [role, postTakeOf(e, n, { line: role })];
} catch (err) {
throw new ThreadReadError(String(err instanceof Error ? err.message : err).replace(/--post-take/g, `--line-take ${role}=`));
}
@@ -635,9 +648,13 @@ export async function threadCommand(project, e, o) {
}
const pieces = r.plan.pieces.map((p) => ({ role: p.role, handle: p.handle, date: p.date, voice: p.voice, engine: p.engine, from: p.from, ...(p.take ? { take: p.take } : {}), ...(p.speed !== undefined ? { speed: p.speed } : {}), ...(p.character ? { character: p.character } : {}), words: p.text.split(/\s+/).filter(Boolean).length, ...(p.lexicon.length ? { lexicon: p.lexicon } : {}) }));
const guard = r.take ? await guardOf(project, e.id) : null;
+ // RECORDINGS OF ITS LINES NOBODY CHOSE (screenLine takes): said, never read in -- the operator chooses.
+ const used = new Set(r.plan.pieces.filter((p) => p.take && p.role !== "post").map((p) => p.role));
+ const notChosen = lineTakesOf(e).filter((L) => !used.has(L.role) && r.plan.pieces.some((p) => p.role === L.role)).map((L) => ({ role: L.role, takes: L.takes.filter((x) => x.current).map((x) => x.n) })).filter((L) => L.takes.length);
if (json) {
out(JSON.stringify({
ok: true, id: e.id, upToDate: r.upToDate, dryRun: r.dryRun, engine: r.plan.engine, voice: r.plan.voice, pieces, skipped: r.plan.skipped,
+ ...(notChosen.length ? { lineTakesNotChosen: notChosen } : {}),
parts: r.parts.map((p) => ({ role: p.role, voice: p.voice, engine: p.engine, ...(p.speed !== undefined ? { speed: p.speed } : {}), ...(p.take ? { take: p.take, file: p.file } : { key: p.key }), cached: p.cached, text: p.text })),
fresh: r.fresh, cached: r.cached, jobs: r.jobs, lane: r.lane,
...(r.take ? { take: r.take, pick: r.result.narration?.pick ?? null, token: r.result.token, snapshot: r.result.snapshot ?? null, guard } : {}),
@@ -647,6 +664,10 @@ export async function threadCommand(project, e, o) {
out(`${e.id}: a thread read of ${pieces.length} piece(s), ${r.parts.length} part(s) (${r.cached} cached${r.dryRun ? `, ${r.parts.length - r.cached} to synthesize` : ""})`);
for (const p of pieces) out(` ${p.role.padEnd(9)} ${(p.take ? p.voice : p.engine !== r.plan.engine ? `${p.engine}:${p.voice}` : p.voice).padEnd(6)} ${p.take ? `(take ${p.take.n}: ${p.take.file}) ` : ""}${p.from === "cast" ? "(cast) " : p.from === "item" ? `(the item's character: ${p.character}) ` : p.from === "project" && p.character ? `(this video's character: ${p.character}) ` : ""}${p.speed !== undefined ? `×${p.speed} ` : ""}${p.handle ? `@${p.handle}` : ""}${p.date ? ` ${p.date.slice(0, 16)}` : ""} ${p.words} words${p.lexicon ? ` (said: ${p.lexicon.map((x) => `${x.word} -> ${x.say}`).join(", ")})` : ""}`);
for (const s of r.plan.skipped) out(` (not read: ${s.role}${s.id ? ` ${s.id}` : ""} -- ${s.why})`);
+ for (const L of notChosen) {
+ const m = /^screen:([a-z0-9-]+):(\d+)$/.exec(L.role);
+ out(` (${L.role} is synthesized: its recording${L.takes.length > 1 ? "s" : ""} take ${L.takes.join(", take ")} not chosen -- --line-take ${L.role}=${L.takes.at(-1)}, or umtool posts screen ${project.id} ${e.id} set ${m[1]} take.${m[2]}=${L.takes.at(-1)})`);
+ }
if (r.upToDate) {
out(` up to date: the picked take already reads this, in these voices (--force makes it again)`);
return 0;
diff --git a/umtool/lib/report/screenLineRecord.mjs b/umtool/lib/report/screenLineRecord.mjs
@@ -0,0 +1,160 @@
+// A SCREEN LINE RECORDED BY THE OPERATOR (lane/screens-2; docs/report-video.md, "Screens" -- "A line in your own
+// voice"): one line of a post's screen (post-screens.mjs) read by a person, kept as a NEW take of the item -- recorded,
+// cleaned, converted to the line's SPEAKER's character's stock voice -- each step a new take, NONE of them the item's
+// read (never picked): a line take is read in its line's place by the item's thread read only once the operator
+// CHOOSES it (`--line-take`, the screen's `lineTakes`: the bench's per-line select, `posts screen … set <id> take.<n>=`).
+//
+// umtool posts screen <p> <item> record <id> <n> --recording <file> [--as <character>] [--no-clean|--clean]
+// [--no-trim|--trim] [--no-convert] [--pitch …] [--semitones n] [--label l] [--check-words [--worker w]]
+//
+// WHAT IS READ: the line as the read says it (screenLineSaid: its read run, its shapes left out; draftScript; the
+// redaction left out, an anonymous handle said as its shown name: post-redact.mjs spokenRead) -- the PROMPT the person
+// reads is that, without the pronunciation lexicon's spellings, and the take's script is it with them (what the read
+// holds the take to: postThreadRead.mjs lineTakeProblem). The take carries `screenLine: { screen, n, said, speaker }`:
+// the line as a read writes it and its speaker, so a line edited or given to someone else since is refused, never
+// played (postThreadRead.mjs threadReadPlan). The recording itself is postNarrationCli.mjs importRecording's chain.
+//
+// --check-words (opt-in; the editor's transcribe op, a job): the recording TRANSCRIBED before anything is kept --
+// REFUSED when it is heard saying a shape (an e-mail, a number: post-screens.mjs shapeSpans), an @handle, an anonymous
+// handle or a redacted term; a warning when its words are not the line's in order. Without it, the recording is the
+// operator's: what he reads is what he chose.
+//
+// Plain ESM: the CLI runs it under bare node.
+import { mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
+import path from "node:path";
+import { characterOf, projectCharactersOf } from "umtool-report-to-video/cast";
+import { draftScript, isNarrated, pickedTake, postIdOf, takesDirOf } from "umtool-report-to-video/post-narration";
+import { spokenRead, termsFor } from "umtool-report-to-video/post-redact";
+import { handleKey } from "umtool-report-to-video/post-say";
+import { parseScreenRole, screenLineSaid, screenOf, screenReadLines, screenWho, shapeSpans } from "umtool-report-to-video/post-screens";
+import { readManifest } from "../projects/report.mjs";
+
+const str = (v) => (typeof v === "string" ? v : "");
+
+export class LineRecordError extends Error {
+ constructor(message) {
+ super(message);
+ this.name = "LineRecordError";
+ }
+}
+
+/**
+ * THE LINE TO RECORD, pure: `{ role, screen, n, written, script, prompt, speaker, handle, self }` -- `written` the line
+ * as a read writes it (the take's `screenLine.said`), `script` what the read says (the take's script), `prompt` what the
+ * person reads (the same without the lexicon's spellings). Throws LineRecordError: no such screen or line, a line
+ * redacted or not read, nothing left to say.
+ *
+ * @param {Record<string, any>} e the post item
+ * @param {string} role `screen:<id>:<n>`
+ * @param {{ red?: any, names?: Record<string, string> }} [o]
+ */
+export function lineToRecord(e, role, { red = null, names = {} } = {}) {
+ const p = parseScreenRole(role);
+ if (!p) throw new LineRecordError(`a screen line is screen:<id>:<n> (got ${role})`);
+ const sc = screenOf(e, p.id);
+ if (!sc) throw new LineRecordError(`${e?.id} has no screen ${p.id}`);
+ const l = sc.lines[p.n];
+ if (!l) throw new LineRecordError(`screen ${p.id} has no line ${p.n} (lines 0–${sc.lines.length - 1})`);
+ if (l.redact === true) throw new LineRecordError(`line ${p.n} of screen ${p.id} is redacted: it is never read`);
+ if (!screenReadLines(sc).some((r) => r.n === p.n)) throw new LineRecordError(`line ${p.n} of screen ${p.id} is not read by the screen: tick it first (umtool posts screen <p> ${e.id} set ${p.id} read.${p.n}=on)`);
+ const written = draftScript(screenLineSaid(sc, p.n)).script;
+ // A beep needs the slur's time in the read; a joined read is not word-timed as it is made (postThreadRead.mjs): skipped.
+ const voice = red?.slurs?.voice === "beep" ? "skip" : undefined;
+ const script = str(spokenRead(written, e, red, { voice }).text).replace(/\s+/g, " ").trim();
+ const prompt = str(spokenRead(written, e, red ? { ...red, say: [] } : red, { voice }).text).replace(/\s+/g, " ").trim();
+ if (!script) throw new LineRecordError(`line ${p.n} of screen ${p.id} has nothing left to say (all of it masked or redacted)`);
+ const sw = screenWho(l.who, e, names);
+ return { role, screen: p.id, n: p.n, written, script, prompt, speaker: str(l.who), handle: sw.self ? str(e.handle).replace(/^@/, "") || null : sw.handle, self: sw.self };
+}
+
+/**
+ * THE CHARACTER A LINE's RECORDING IS MADE INTO, pure: its SPEAKER's -- the post's author's own lines the item's
+ * chain (characterForRead: the item's own, this video's for her, the cast's; never the narrator), anyone else's the
+ * character holding their handle (this video's characters first, then the cast). Null: none (kept as recorded).
+ */
+export function lineCharacterOf(layers, e, target) {
+ if (target.self) {
+ const r = layers.characterForRead(e);
+ return r && r.layer !== "narrator" ? r.character : null;
+ }
+ const h = handleKey(target.handle);
+ if (!h) return null;
+ return projectCharactersOf(layers.project).find((c) => (c.handles ?? []).map(handleKey).includes(h)) ?? characterOf(layers.cast, h) ?? null;
+}
+
+/**
+ * WHAT A RECORDING IS HEARD SAYING AMISS, pure (--check-words): `{ refused: string | null, warning: string | null }` --
+ * refused when the words heard hold a shape, an @handle, an anonymous handle (`handles`) or a redacted term (`terms`);
+ * a warning when they are not the line's in order (postThreadRead.mjs lineTakeProblem's "other words": ASR slack is
+ * the person's to judge). Names what, never the words.
+ */
+export function heardProblem(heard, script, { handles = [], terms = [], lineTakeProblem }) {
+ const h = str(heard);
+ if (shapeSpans(h).length) return { refused: "it is heard saying an e-mail address or a number the card masks", warning: null };
+ const words = h.toLowerCase().split(/\s+/).map((w) => w.replace(/^[^\p{L}\p{N}@]+|[^\p{L}\p{N}]+$/gu, "")).filter(Boolean);
+ if (words.some((w) => w.startsWith("@"))) return { refused: "it is heard saying an @handle", warning: null };
+ const banned = new Set(handles.map((x) => String(x).replace(/^@+/, "").toLowerCase()));
+ if (words.some((w) => banned.has(w))) return { refused: "it is heard saying an anonymous author's handle", warning: null };
+ const esc = (t) => String(t).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+ if (terms.some((t) => new RegExp(`(?<![\\p{L}\\p{N}])${esc(t)}(?![\\p{L}\\p{N}])`, "iu").test(h))) return { refused: "it is heard saying a redacted term", warning: null };
+ const why = lineTakeProblem(h, script, { handles, terms });
+ return { refused: null, warning: why ? "its words as heard are not the line's in order (the transcription may have misheard: listen to it)" : null };
+}
+
+/**
+ * RECORD ONE SCREEN LINE of post item `id` (see the head): `file` a sound file; the takes made (`{ takes: [{ step, file
+ * }], picked: null, notes, disclosure, character, line: { role, prompt } }`). Refused (LineRecordError) on an item with
+ * no read of its own (a line is read inside one), a line that cannot be read, `as` naming no one, and -- with
+ * `checkWords` -- a recording heard saying what is never said. `ask` / `editor`: the editor's ops (tests stub them).
+ */
+export async function recordScreenLine(project, id, role, file, opts = {}) {
+ const { as = null, label = "operator", clean = undefined, trim = undefined, convert = true, pitch = undefined, semitones = undefined, note = null, checkWords = false, worker = null, emit = () => {}, editor = null, ask = null } = opts;
+ const manifest = await readManifest(project.dir);
+ const e = (manifest?.timeline ?? []).find((x) => x?.type === "post" && x.id === id);
+ if (!e) throw new LineRecordError(`no post item ${id} in ${project.id}`);
+ const t = pickedTake(e);
+ if (!isNarrated(e) || t?.screenLine) throw new LineRecordError(`${id} has no read of its own yet: a screen line is read inside the item's read -- make it first (umtool posts narrate <p> ${id} --take, or record it), then record the line`);
+ const { projectRedaction } = await import("./postRedaction.mjs");
+ const red = await projectRedaction(project.dir, manifest);
+ const { readLayers } = await import("./characterLayers.mjs");
+ const layers = await readLayers(project.dir);
+ const { characterNames, lineTakeProblem } = await import("./postThreadRead.mjs");
+ const target = lineToRecord(e, role, { red, names: characterNames(layers) });
+ let character;
+ if (as) {
+ character = layers.characterForRead(e, as)?.character ?? null;
+ if (!character) throw new LineRecordError(`--as ${as}: no such character in this video's characters or the cast (umtool cast project ${project.id}, umtool cast ls)`);
+ } else character = lineCharacterOf(layers, e, target);
+ const notes = [];
+ if (checkWords) {
+ // Heard BEFORE anything is kept: a refusal keeps nothing.
+ const { decodePart } = await import("./postRecord.mjs");
+ const dir = path.join(project.dir, ...takesDirOf(postIdOf(e)).split("/"));
+ await mkdir(dir, { recursive: true });
+ const tmp = await mkdtemp(path.join(dir, ".line-check-"));
+ try {
+ const wav = path.join(tmp, "heard.wav");
+ await decodePart(path.resolve(file), wav);
+ const out = path.join(tmp, "heard.words.json");
+ const askOp = ask ?? (await import("umtool-report-to-video/narrate-via-editor")).askEditorOp;
+ emit("note", { message: `${id}: the recording of ${role} transcribed on the editor (--check-words)…` });
+ await askOp("/api/ops/transcribe", { path: wav, words: true, out, ...(worker ? { workerId: worker } : {}) }, { ...(editor ? { editor } : {}), emit });
+ const doc = JSON.parse(await readFile(out, "utf8").catch(() => "{}"));
+ const heard = Array.isArray(doc?.words) && doc.words.length ? doc.words.map((w) => str(w?.w)).join(" ") : str(doc?.text);
+ if (!heard.trim()) throw new LineRecordError(`--check-words: the editor heard no words in the recording of ${role} -- nothing kept`);
+ const anonHandles = red?.anon instanceof Map ? [...red.anon.keys()] : Object.keys(red?.anon ?? {}).filter((x) => x !== "postIds");
+ const p = heardProblem(heard, target.script, { handles: anonHandles, terms: termsFor(e, red).map((x) => x.term), lineTakeProblem });
+ if (p.refused) throw new LineRecordError(`--check-words: the recording of ${role} is refused -- ${p.refused}; nothing kept: record the line again`);
+ if (p.warning) notes.push(`--check-words: ${p.warning}`);
+ else notes.push("--check-words: heard saying the line");
+ } finally {
+ await rm(tmp, { recursive: true, force: true });
+ }
+ }
+ const { importRecording } = await import("./postNarrationCli.mjs");
+ const r = await importRecording(project, e, file, {
+ label, clean, trim, convert, pitch, semitones, note, emit, editor, ask, character,
+ screenLine: { screen: target.screen, n: target.n, said: target.written, speaker: target.speaker }, script: target.script,
+ });
+ return { ...r, notes: [...notes, ...r.notes], line: { role, prompt: target.prompt, speaker: target.speaker } };
+}
diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs
@@ -195,7 +195,7 @@ const ITEM_KEYS = new Set([...MIX_KEYS, "script", "excerpt", "engine", "voice",
// `said`: what a synthesized read SAID when an anonymous handle made it differ from its script (post-anon.mjs; the
// lint reads it); `speedAsked`: where its speed came from -- true (the command's --speed: kept as asked), "item" (the
// item's own), "preset" (its character's: drift when that changes). Absent: unknown -- never speed drift.
-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"]);
+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"]);
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).
@@ -658,6 +658,14 @@ export function validatePostNarration(e) {
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.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)`);
+ // A RECORDING OF ONE SCREEN LINE (postScreensCli.mjs `posts screen … record`, post-screens.mjs): the line it was
+ // recorded for -- its screen, its index, its words as a read writes them, its speaker. Never the item's read.
+ if (t.screenLine !== undefined) {
+ const sl = t.screenLine;
+ if (!(isObj(sl) && typeof sl.screen === "string" && /^[a-z0-9][a-z0-9-]{0,23}$/.test(sl.screen) && Number.isInteger(sl.n) && sl.n >= 0 && sl.n < 60 && typeof sl.said === "string" && sl.said.length <= 2000 && typeof sl.speaker === "string" && sl.speaker.length <= 64 && Object.keys(sl).every((kk) => ["screen", "n", "said", "speaker"].includes(kk)))) {
+ errors.push(`${tw}.screenLine must be { screen, n, said, speaker } (the screen line it is a recording of)`);
+ }
+ }
if (t.words !== undefined) {
// Its script's words, timed in take seconds (the editor's transcription, aligned: word-zoom.mjs scriptWordTimes).
const ws = t.words;
@@ -726,6 +734,10 @@ export function validatePostNarration(e) {
if (n.pick !== undefined && !(Number.isInteger(n.pick) && n.pick >= 0 && Array.isArray(n.takes) && n.pick < n.takes.length)) {
errors.push(`${w}.pick must be the index of one of its takes (0–${Math.max(0, (n.takes?.length ?? 1) - 1)})`);
}
+ // A take of ONE SCREEN LINE is a piece of a read (--line-take), never the item's read itself.
+ const pk = Array.isArray(n.takes) && n.takes.length ? (Number.isInteger(n.pick) && n.pick >= 0 && n.pick < n.takes.length ? n.pick : 0) : -1;
+ const pt = pk >= 0 ? n.takes[pk] : null;
+ if (isObj(pt) && isObj(pt.screenLine)) errors.push(`${w}.pick: take ${pk + 1} is a recording of line ${pt.screenLine.n} of screen ${pt.screenLine.screen} -- a line take is read inside the item's read (posts screen <p> ${e?.id ?? "<item>"} read --line-take …), never picked as it: pick another take`);
return errors;
}
diff --git a/umtool/report-to-video/post-screens.mjs b/umtool/report-to-video/post-screens.mjs
@@ -13,7 +13,8 @@
// screens: [{ id: "s1", media: 0, at: [3.5, 8], kind: "dm", title?, source?: "transcribed", checked?: { by, at },
// ref?: "<channel>/<postId>", unread?: "omit" | "dim",
// lines: [{ who?, side?: "left" | "right", text, time?, redact?: true }],
-// read: "all" | "none" | [{ line, text? }] }]
+// read: "all" | "none" | [{ line, text? }],
+// lineTakes?: { "<n>": "<take id>" } }]
//
// - `media` names the attachment (an index into the item's `media`); `at` the source span a video or GIF shows it.
// - `read`: every line ("all"), none ("none": transcribed only -- not drawn, not read), or the lines listed, each read
@@ -22,6 +23,9 @@
// drawn dim ("dim"). A line marked `redact: true` is never drawn nor read.
// - THE SHAPES: an e-mail address, a phone number, a long run of digits, an order or confirmation number in a line are
// MASKED (a bar on the card, never said) whether or not anyone marked them -- the lint says which line held one.
+// - `lineTakes`: the take the operator CHOSE for a line (a recording of it: `posts screen … record`, the bench's per-line
+// Record), by its id -- read in that line's place by every read of the item (postThreadRead.mjs); never chosen for
+// it by anything else.
// - `who`: a handle or a name; it is the post's author (her own lines, on the right), or another speaker, voiced through
// the project's characters and the cast as a thread read's pieces are (post-say.mjs) and drawn under the item's
// privacy rule (a subject, or `redact: false`, shown; else blurred), an anonymous one under its shown name.
@@ -55,6 +59,8 @@ export const POST_SCREEN_DRAW_V = 1;
export const SCREEN_ROLE_RE = /^screen:([a-z0-9][a-z0-9-]{0,23}):(\d{1,2})$/;
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
+/** A take's id (post-narration.mjs takeIdOf: its file's name without .wav -- not imported: that module imports this one's). */
+const takeIdOfFile = (t) => String(t?.file ?? "").split("/").pop().replace(/\.wav$/i, "");
const fin = (v) => typeof v === "number" && Number.isFinite(v);
const str = (v) => (typeof v === "string" ? v : "");
const r3 = (v) => Math.round(v * 1000) / 1000;
@@ -292,6 +298,12 @@ export function withoutLines(screen, drops) {
const to = (n) => n - [...gone].filter((d) => d < n).length;
const out = { ...screen, lines: (Array.isArray(screen?.lines) ? screen.lines : []).filter((_, n) => !gone.has(n)) };
if (Array.isArray(screen?.read)) out.read = screen.read.filter((x) => !gone.has(x?.line)).map((x) => ({ ...x, line: to(x.line) }));
+ // The takes chosen for its lines follow them too: a removed line's choice goes, the later ones' keys move down.
+ if (isObj(screen?.lineTakes)) {
+ const lt = Object.fromEntries(Object.entries(screen.lineTakes).filter(([k]) => /^\d{1,2}$/.test(k) && !gone.has(Number(k))).map(([k, v]) => [String(to(Number(k))), v]));
+ if (Object.keys(lt).length) out.lineTakes = lt;
+ else delete out.lineTakes;
+ }
return out;
}
@@ -488,7 +500,7 @@ export function validateScreens(e) {
errors.push(`${at} must be an object`);
return;
}
- const known = new Set(["id", "media", "at", "kind", "title", "source", "checked", "ref", "unread", "lines", "read"]);
+ const known = new Set(["id", "media", "at", "kind", "title", "source", "checked", "ref", "unread", "lines", "read", "lineTakes"]);
for (const k of Object.keys(sc)) if (!known.has(k)) errors.push(`${at}.${k} is not a screen's field (${[...known].join(", ")})`);
if (!SCREEN_ID_RE.test(str(sc.id))) errors.push(`${at}.id must be a short name (lower-case letters, digits, -)`);
else if (ids.has(sc.id)) errors.push(`${at}.id "${sc.id}" is the id of another screen of the item`);
@@ -530,6 +542,20 @@ export function validateScreens(e) {
if (l.redact !== undefined && l.redact !== true) errors.push(`${lw}.redact must be true (or absent)`);
});
}
+ // The takes CHOSEN for its lines (a recording of each): a line it has, a take of the item that is a recording of it.
+ if (sc.lineTakes !== undefined) {
+ const lt = sc.lineTakes;
+ const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : [];
+ if (!isObj(lt) || Object.keys(lt).length > SCREEN_LINES_MAX) errors.push(`${at}.lineTakes must be { "<line>": "<take id>" } (the take chosen for each line)`);
+ else for (const [k, v] of Object.entries(lt)) {
+ const n = /^\d{1,2}$/.test(k) ? Number(k) : -1;
+ if (n < 0 || !isObj(lines?.[n])) errors.push(`${at}.lineTakes.${k}: the screen has no line ${k}`);
+ else if (lines[n].redact === true) errors.push(`${at}.lineTakes.${k}: line ${k} is redacted -- it is never read`);
+ const t = typeof v === "string" ? takes.find((x) => takeIdOfFile(x) === v) : null;
+ if (!t) errors.push(`${at}.lineTakes.${k} must be the id of one of the item's takes (a recording of line ${k})`);
+ else if (!isObj(t.screenLine) || t.screenLine.screen !== sc.id || t.screenLine.n !== n) errors.push(`${at}.lineTakes.${k}: take ${takes.indexOf(t) + 1} is not a recording of line ${k} of screen ${sc.id}${isObj(t.screenLine) ? ` (it is of line ${t.screenLine.n} of screen ${t.screenLine.screen})` : ""}`);
+ }
+ }
const r = sc.read;
if (r === "all" || r === "none") return;
if (!Array.isArray(r)) {
diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs
@@ -620,6 +620,88 @@ export function screenLineChanged(entry, role, roles = partRoles(entry)) {
return a.length !== b.length || a.some((x, i) => x !== b[i]);
}
+// ---------------------------------------------------------------------------
+// A SCREEN LINE's OWN TAKE (a recording of the line: lib/report/screenLineRecord.mjs, `posts screen … record`).
+// ---------------------------------------------------------------------------
+
+/** A screen line's words AS A READ WRITES THEM (draftScript of what it says): what a part's `line` and a line take's `screenLine.said` hold. */
+export const screenLineWritten = (screen, n) => draftScript(screenLineSaid(screen, n)).script;
+
+/** A take's id (its file's name without .wav: post-narration.mjs takeIdOf). */
+const idOfTake = (t) => str(t?.file).split("/").pop().replace(/\.wav$/i, "");
+
+/**
+ * Whether a line take (`screenLine`) was recorded for the line AS IT IS NOW: its words as a read writes them and its
+ * speaker. A take that is no recording of a line: null (nothing to judge).
+ */
+export function lineTakeCurrent(entry, take) {
+ const sl = take?.screenLine;
+ if (!sl || typeof sl !== "object") return null;
+ const sc = screensOfEntry(entry).find((x) => x.id === sl.screen);
+ if (!sc || !sc.lines[sl.n] || sc.lines[sl.n].redact === true) return false;
+ return normText(sl.said) === normText(screenLineWritten(sc, sl.n)) && normText(sl.speaker).toLowerCase() === normText(sc.lines[sl.n]?.who).toLowerCase();
+}
+
+/**
+ * Each screen line's RECORDINGS, pure: `[{ role, screen, n, takes: [{ n, id, take, current, chosen }] }]` -- the item's
+ * takes that are recordings of a line (`screenLine`), by line, each with its number (as --list counts), whether it was
+ * recorded for the line as it is now, and whether the screen's `lineTakes` chose it. Lines with none are left out.
+ */
+export function lineTakesOf(entry) {
+ const takes = Array.isArray(entry?.narration?.takes) ? entry.narration.takes : [];
+ const by = new Map();
+ takes.forEach((t, i) => {
+ const sl = t?.screenLine;
+ if (!sl || typeof sl !== "object") return;
+ const role = screenRole(sl.screen, sl.n);
+ const sc = screensOfEntry(entry).find((x) => x.id === sl.screen);
+ const chosen = !!sc && sc.lineTakes?.[String(sl.n)] === idOfTake(t);
+ if (!by.has(role)) by.set(role, { role, screen: sl.screen, n: sl.n, takes: [] });
+ by.get(role).takes.push({ n: i + 1, id: idOfTake(t), take: t, current: lineTakeCurrent(entry, t) === true, chosen });
+ });
+ return [...by.values()];
+}
+
+/** The takes the screens CHOSE for their lines, as --line-take takes them: `{ "<role>": <take number> }` (none: {}). */
+export function chosenLineTakes(entry) {
+ const takes = Array.isArray(entry?.narration?.takes) ? entry.narration.takes : [];
+ const out = {};
+ for (const sc of screensOfEntry(entry)) {
+ if (!sc.lineTakes || typeof sc.lineTakes !== "object") continue;
+ for (const [k, v] of Object.entries(sc.lineTakes)) {
+ const i = takes.findIndex((t) => idOfTake(t) === v);
+ if (i >= 0 && /^\d{1,2}$/.test(k)) out[screenRole(sc.id, Number(k))] = i + 1;
+ }
+ }
+ return out;
+}
+
+/**
+ * THE LINE TAKES' WARNINGS (the lint; never refused here -- the read refuses a stale one when it is made): a chosen take
+ * recorded for the line as it was, a recording no read uses (not chosen), a chosen take the picked read does not play.
+ * They name lines and take numbers, never words.
+ */
+export function lineTakeWarnings(entry) {
+ const id = entry?.id ?? "?";
+ const out = [];
+ const t = pickedTake(entry);
+ const parts = Array.isArray(t?.parts) ? t.parts : [];
+ for (const L of lineTakesOf(entry)) {
+ const sc = screensOfEntry(entry).find((x) => x.id === L.screen);
+ if (!sc) continue;
+ const chosen = L.takes.find((x) => x.chosen);
+ if (chosen && !chosen.current) out.push(`timeline ${id}: line ${L.n} of screen ${L.screen}: its chosen take (take ${chosen.n}) was recorded for the line as it was -- record it again (umtool posts screen <p> ${id} record ${L.screen} ${L.n} --recording <file>) or unchoose it (umtool posts screen <p> ${id} set ${L.screen} take.${L.n}=off)`);
+ else if (!chosen && L.takes.some((x) => x.current) && screenReadLines(sc).some((r) => r.n === L.n)) {
+ out.push(`timeline ${id}: line ${L.n} of screen ${L.screen} has a recording no read uses (take ${L.takes.filter((x) => x.current).map((x) => x.n).join(", take ")}) -- choose one: umtool posts screen <p> ${id} set ${L.screen} take.${L.n}=<take> (or on the post bench), then make the read`);
+ }
+ if (chosen && chosen.current && isNarrated(entry)) {
+ const mine = parts.filter((p) => p?.role === L.role);
+ if (mine.length && !mine.every((p) => p.take === chosen.id)) out.push(`timeline ${id}: line ${L.n} of screen ${L.screen}: the picked read does not play its chosen take (take ${chosen.n}) -- make the read: umtool posts screen <p> ${id} read`);
+ }
+ }
+ return out;
+}
+
/** A tile's mode in a layout (null: no such tile). */
export const tileModeOf = (layout, scope) => layout?.tiles?.find((t) => t.scope === scope)?.mode ?? null;
@@ -961,6 +1043,8 @@ export function validateThreadReadWarnings(manifest) {
return tl.filter((e) => e?.type === "post").flatMap((e) => [
...threadReadWarnings(e),
...(Array.isArray(e.screens) ? screenWarnings(e, { narrated: isNarrated(e), takeRoles: isNarrated(e) ? partRoles(e).map((r) => r.role) : [], attachAfter: isNarrated(e) && postNarrationKnobs(e, manifest?.render).attach === "after" }) : []),
+ // Recordings of its screens' lines (screenLine takes): none on an item without them.
+ ...(Array.isArray(e.screens) ? lineTakeWarnings(e) : []),
]);
}