commit ce1aa2d32e4f83f0ace8d51d317dbd09be5d7d1a
parent 08798728b463f0710edd5c90308e2fabde198525
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 16 Nov 2026 08:40:52 -0500
umtool tuning: no echo of an ignored tuning, the note handed on, known fields only, cards normalised
- The bench's op "take" echoes tuning and reading only for Orpheus; its
GET ?job completion hands on the editor's `note` (a tuning Kokoro or
eSpeak NG ignored). The e2e test pins both.
- tunedOfResult (and the kept narration's record) copy only the known
tuning fields, as numbers, so a field a later editor adds never makes a
take's write fail after its audio exists.
- A card's tuning goes through the editor's normaliser (lib/ttsTuning.mjs):
a spelled-out default, or one within rounding, asks and keys as no tuning
(main's key still pinned); takes is kept as written.
- keepNarration records the result's tuning, reading and seedBase beside
the kept copy (additive; a record without them reads as before).
- The CLI's tuning flags are quantised as the editor quantises them.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 116 insertions(+), 18 deletions(-)
diff --git a/umtool/app/api/report/post-narration/route.ts b/umtool/app/api/report/post-narration/route.ts
@@ -161,7 +161,7 @@ export async function GET(request: Request) {
const res = resultLine<{ wav?: string }>(st.tail, "@@tts-result ");
return Response.json({ state: "failed", error: `the job is done but ${rel} is not there (it wrote ${res?.wav ?? "nothing"})` }, { headers: noStore });
}
- const res = resultLine<{ engine?: string; voice?: string; tuning?: Record<string, number>; reading?: number }>(st.tail, "@@tts-result ") ?? {};
+ const res = resultLine<{ engine?: string; voice?: string; tuning?: Record<string, number>; reading?: number; note?: string }>(st.tail, "@@tts-result ") ?? {};
const meas = await measureTake(abs);
const note = q.get("note");
const script = q.get("script") ?? String(e.narration?.script ?? "");
@@ -217,7 +217,8 @@ export async function GET(request: Request) {
const { result } = await withEditNotes(r.project, async () =>
updatePostNarration(r.project.dir, id, { addTake: take, ...(script !== e.narration?.script ? { script } : {}) }, { token: await manifestToken(r.project.dir) }),
);
- return Response.json({ state: "done", file: rel, entry: result.entry, token: result.token }, { headers: noStore });
+ // The editor's `note` (a tuning or reading its engine ignored), handed on so the bench can say so.
+ return Response.json({ state: "done", file: rel, entry: result.entry, token: result.token, ...(typeof res.note === "string" && res.note ? { note: res.note } : {}) }, { headers: noStore });
}
return Response.json({ state: "done", file: rel }, { headers: noStore });
} catch (err) {
@@ -343,7 +344,10 @@ async function postHere(request: Request) {
if (speed) await writeFile(`${out}.ask.json`, JSON.stringify({ speed, speedAsked: body.speed !== undefined && body.speed !== null ? true : (e.narration as { speed?: number } | undefined)?.speed != null ? "item" : "preset" }));
const tuning = tuned?.ok && Object.keys(tuned.value).length ? tuned.value : null;
const jobId = await startJob("/api/ops/tts", { text: spoken, engine, voice, out, ...(speed ? { speed } : {}), ...(tuning ? { tuning } : {}), ...(reading !== null ? { reading } : {}) });
- return Response.json({ ok: true, jobId, file: rel, engine, voice, script, ...(tuning ? { tuning } : {}), ...(reading !== null ? { reading } : {}) }, { headers: noStore });
+ // Echoed only for the engine that takes them (Orpheus): Kokoro and eSpeak NG ignore them (the editor's result
+ // says so in its `note`, which the GET below hands on), so the answer never claims a tuning that is not used.
+ const tunes = engine === "orpheus";
+ return Response.json({ ok: true, jobId, file: rel, engine, voice, script, ...(tunes && tuning ? { tuning } : {}), ...(tunes && reading !== null ? { reading } : {}) }, { headers: noStore });
}
if (body.op === "derive") {
const takes = (e.narration?.takes ?? []) as Array<{ file: string; parts?: Array<{ n: number; file?: string }> }>;
diff --git a/umtool/e2e/post-narration.spec.ts b/umtool/e2e/post-narration.spec.ts
@@ -285,6 +285,22 @@ test("ANOTHER READING, TUNED (lane orpheus-tuning): the take op sends a tuning a
expect(t.tuning).toEqual({ temperature: 0.7, top_p: 0.85, top_k: 40, min_p: 0, repeat_penalty: 1.2, takes: 3 });
expect(t.reading).toBe(2);
expect(JSON.stringify((timeline().find((e) => e.id === "p-11") as Record<string, unknown>).text)).toBe(shownBefore);
+ // An engine that ignores them (Kokoro): the answer does not claim a tuning or a reading, the take records none, and
+ // the editor's note comes back with the kept take so the bench can say it was ignored.
+ const k = await page.request.post(api, { data: { project: PROJECT, op: "take", id: "p-11", engine: "kokoro", voice: "af_heart", tuning: { temperature: 0.7 }, reading: 1 } });
+ expect(k.ok()).toBe(true);
+ const kj = (await k.json()) as { jobId: string; file: string; engine: string; tuning?: unknown; reading?: unknown };
+ expect(kj.engine).toBe("kokoro");
+ expect("tuning" in kj).toBe(false);
+ expect("reading" in kj).toBe(false);
+ const kq = `${api}?project=${encodeURIComponent(PROJECT)}&id=p-11&job=${encodeURIComponent(kj.jobId)}&file=${encodeURIComponent(kj.file)}`;
+ let done: { state?: string; note?: string } = {};
+ await expect.poll(async () => (done = (await (await page.request.get(kq)).json()) as typeof done).state, { timeout: 20_000 }).toBe("done");
+ expect(done.note).toMatch(/has no sampler or seed: the tuning and reading were ignored/);
+ const kt = narr("p-11").takes!.at(-1) as Take & { tuning?: unknown; reading?: unknown };
+ expect(kt.file).toBe(kj.file);
+ expect(kt.tuning).toBeUndefined();
+ expect(kt.reading).toBeUndefined();
});
test.describe("the recording session", () => {
diff --git a/umtool/lib/report/postNarration.test.mjs b/umtool/lib/report/postNarration.test.mjs
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { after, test } from "node:test";
import { postsCommand } from "./postsCli.mjs";
-import { importPatches, makeTake, mixPatchOf, pitchFlags } from "./postNarrationCli.mjs";
+import { importPatches, makeTake, mixPatchOf, pitchFlags, tunedOfResult, tuningFlags } from "./postNarrationCli.mjs";
import { fitPostItem, rmsFrames, scanAttachment, scoreWindows } from "./postFit.mjs";
import { manifestToken, updatePostNarration } from "./manifest.mjs";
import { postItemPlan } from "umtool-report-to-video/post-item";
@@ -203,6 +203,29 @@ test("ANOTHER READING, TUNED (lane orpheus-tuning): --reading and the tuning are
assert.ok(notes.some((m) => /has no sampler or seed/.test(m)), notes.join("\n"));
});
+test("a field a later editor adds to its tuning is not copied: the take is still written (its validator knows only today's)", async () => {
+ const made = { temperature: 0.7, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3 };
+ // An unknown field is left out, and so is a known one that is not a number.
+ const { top_k: _k, ...noTopK } = made;
+ assert.deepEqual(tunedOfResult({ tuning: { ...made, mirostat: 2, top_k: "50" }, reading: 1 }), { tuning: noTopK, reading: 1 });
+ assert.deepEqual(tunedOfResult({ reading: -1 }), {});
+ assert.deepEqual(tunedOfResult(null), {});
+ const p = await project("tn", [item("1", { narration: { script: "read me" } })]);
+ const ask = async (body) => {
+ wav(body.out, 1);
+ return { jobId: "j", result: { wav: body.out, engine: "orpheus", voice: "zac", seconds: 1, tuning: { ...made, mirostat: 2 }, reading: 0, seedBase: 1234 } };
+ };
+ const r = await makeTake(p, (await manifest(p)).timeline[0], { ask });
+ assert.deepEqual(r.take.tuning, made);
+ assert.deepEqual((await manifest(p)).timeline[0].narration.takes[0].tuning, made);
+});
+
+test("the tuning flags are quantised as the editor quantises them", () => {
+ const s = (o) => (f) => o[f] ?? null;
+ assert.deepEqual(tuningFlags(s({ "--temperature": "0.7000000000000001", "--min-p": "-0" })).tuning, { temperature: 0.7, min_p: 0 });
+ assert.equal(tuningFlags(s({ "--temperature": "1.5004" })).tuning.temperature, 1.5);
+});
+
test("the tuning flags: refused out of range in the flag's words, and anywhere but one item's --take", async () => {
await project("tf", [item("1", { narration: { script: "read me" } })]);
for (const [args, re] of [
diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs
@@ -36,7 +36,7 @@ import { projectRedaction } from "./postRedaction.mjs";
import { readManifest } from "../projects/report.mjs";
import { withEditNotes } from "./edit-guard.mjs";
import { manifestToken, updatePostNarration, updatePostNarrationRender, updatePostNarrations } from "./manifest.mjs";
-import { ttsReadingError, ttsTuningValueError } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
+import { TTS_TUNING_FIELDS, quantizeTtsTuningValue, ttsReadingError, ttsTuningValueError } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
const execFileP = promisify(execFile);
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
@@ -450,11 +450,19 @@ export async function makeTake(project, e, { script = null, note = null, engine
return { take, result: wrote, editNotes, ...(deferred ? { deferred } : {}) };
}
-/** The tuning and reading a tts result says a take was made with (Orpheus's), as take keys; `{}` for any other engine. */
+/**
+ * The tuning and reading a tts result says a take was made with (Orpheus's), as take keys; `{}` for any other engine.
+ * Only the known tuning fields are copied, as numbers: a field a later editor adds never makes the take's write (its
+ * validator) fail after the audio exists.
+ */
export function tunedOfResult(result) {
+ const tuning = {};
+ if (isObj(result?.tuning)) {
+ for (const k of TTS_TUNING_FIELDS) if (typeof result.tuning[k] === "number" && Number.isFinite(result.tuning[k])) tuning[k] = result.tuning[k];
+ }
return {
- ...(isObj(result?.tuning) ? { tuning: { ...result.tuning } } : {}),
- ...(Number.isInteger(result?.reading) ? { reading: result.reading } : {}),
+ ...(Object.keys(tuning).length ? { tuning } : {}),
+ ...(Number.isInteger(result?.reading) && result.reading >= 0 ? { reading: result.reading } : {}),
};
}
@@ -477,8 +485,10 @@ export function tuningFlags(str) {
return String(raw).trim() === "" ? Number.NaN : Number(raw);
};
for (const [flag, field] of Object.entries(TUNING_FLAGS)) {
- const v = num(flag);
- if (v === null) continue;
+ const raw = num(flag);
+ if (raw === null) continue;
+ // Quantised as the editor's tts op quantises (3 places, -0 as 0), then checked.
+ const v = quantizeTtsTuningValue(field, raw);
const err = ttsTuningValueError(field, v, flag);
if (err) throw new NarrateError(err.replace(/ \(got NaN\)$/, ` (got ${str(flag) || "nothing"})`));
tuning[field] = v;
diff --git a/umtool/report-to-video/narrate.test.mjs b/umtool/report-to-video/narrate.test.mjs
@@ -23,7 +23,7 @@ import { buildVideo, cardEncodeArgs, narratedCardEncodeArgs, setProgressMode } f
import { MONO_BOLD_FONT_FILE, MONO_FONT_FILE } from "./brand.mjs";
import { TTS_RESULT_MARKER, narrateCut, ttsBody, ttsResultIn } from "./narrate-via-editor.mjs";
import { narrationKey, narrationsOf } from "./narration.mjs";
-import { narrationDir, readNarrationRecord } from "./narration-store.mjs";
+import { keepNarration, narrationDir, readNarrationRecord } from "./narration-store.mjs";
const SCRIPT = path.join(path.dirname(fileURLToPath(import.meta.url)), "narrate-via-editor.mjs");
const haveFf = ["ffmpeg", "ffprobe"].every((b) => spawnSync(b, ["-version"]).status === 0);
@@ -141,6 +141,24 @@ test("the ask's body: engine, voice and speed always; a tuning and reading only
assert.deepEqual(ttsBody(n), { text: "Hi.", engine: "orpheus", voice: "zac", speed: 1, reading: 1 });
});
+test("a kept narration records what Orpheus made it with (its known tuning fields, the reading, the seed base); one without still reads", { skip: !haveFf && "needs ffmpeg and ffprobe" }, async (t) => {
+ const root = mkdtempSync(path.join(tmpdir(), "narration-made-with-"));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const dir = narrationDir(root);
+ const src = path.join(root, "editor.wav");
+ spawnSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "sine=f=220:d=1", "-ar", "48000", "-ac", "1", src]);
+ const n = { id: "c1", key: narrationKey({ text: "Hi.", engine: "orpheus", voice: "zac", speed: 1, reading: 2 }), text: "Hi.", engine: "orpheus", voice: "zac", speed: 1 };
+ const made = { temperature: 0.7, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3 };
+ const rec = await keepNarration(dir, n, { wav: src, engine: "orpheus", voice: "zac", tuning: { ...made, someday: 1 }, reading: 2, seedBase: 21_180 }, { jobId: "j1" });
+ assert.deepEqual({ tuning: rec.tuning, reading: rec.reading, seedBase: rec.seedBase }, { tuning: made, reading: 2, seedBase: 21_180 });
+ assert.deepEqual((await readNarrationRecord(dir, n.key)).tuning, made);
+ // Kokoro's result carries none: neither does its record, and it reads as before.
+ const k = { ...n, id: "c2", key: narrationKey({ text: "Hi.", engine: "kokoro", voice: "af_heart", speed: 1 }), engine: "kokoro", voice: "af_heart" };
+ const kr = await keepNarration(dir, k, { wav: src, engine: "kokoro", voice: "af_heart" });
+ assert.ok(!("tuning" in kr) && !("reading" in kr) && !("seedBase" in kr));
+ assert.equal((await readNarrationRecord(dir, k.key)).engine, "kokoro");
+});
+
test("the result line is found anywhere on a log line, the last one winning", () => {
assert.equal(ttsResultIn(["a", "b"]), null);
assert.deepEqual(ttsResultIn([`${TTS_RESULT_MARKER}{"wav":"/a.wav"}`, `[12:00] ${TTS_RESULT_MARKER}{"wav":"/b.wav"}`]), { wav: "/b.wav" });
diff --git a/umtool/report-to-video/narration-store.mjs b/umtool/report-to-video/narration-store.mjs
@@ -21,6 +21,7 @@ import { promisify } from "node:util";
import { disclosureLine, disclosureLines, narrationsOf } from "./narration.mjs";
import { postNarrationDisclosure } from "./post-narration.mjs";
import { tmpPathFor } from "yt-dlp-transcript-common/lib/atomicFile.mjs";
+import { TTS_TUNING_FIELDS } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
const execFileP = promisify(execFile);
const FFMPEG = () => process.env.FFMPEG_BIN ?? "ffmpeg";
@@ -81,7 +82,8 @@ const sha256File = async (file) => createHash("sha256").update(await readFile(fi
* @param {string} dir narrationDir(outRoot)
* @param {{ id: string, key: string, text: string, engine: string, voice: string, speed: number }} n
* @param {{ wav: string, seconds?: number, engine?: string, voice?: string, cached?: boolean,
- * durationMs?: number, waitedMs?: number }} result the editor's `@@tts-result`
+ * durationMs?: number, waitedMs?: number, tuning?: Record<string, number>, reading?: number,
+ * seedBase?: number }} result the editor's `@@tts-result`
* @param {{ jobId?: string }} [meta]
* @returns the record
*/
@@ -116,6 +118,9 @@ export async function keepNarration(dir, n, result, { jobId = null } = {}) {
lufs: lufs === null ? null : Number(lufs.toFixed(2)),
sha256: await sha256File(wav),
wav: path.basename(wav),
+ // What Orpheus made it with, as the editor says (every tuning value, the reading, its seed base), so the reading
+ // can be made again exactly. Absent for another engine, and in a record kept before (it still reads).
+ ...madeWith(result),
editor: {
jobId,
cached: result.cached === true,
@@ -136,6 +141,19 @@ export async function keepNarration(dir, n, result, { jobId = null } = {}) {
return record;
}
+/** The editor's `tuning` (its known fields), `reading` and `seedBase`, as a record's keys; `{}` when it gave none. */
+function madeWith(result) {
+ const tuning = {};
+ if (result?.tuning && typeof result.tuning === "object") {
+ for (const k of TTS_TUNING_FIELDS) if (typeof result.tuning[k] === "number" && Number.isFinite(result.tuning[k])) tuning[k] = result.tuning[k];
+ }
+ return {
+ ...(Object.keys(tuning).length ? { tuning } : {}),
+ ...(Number.isInteger(result?.reading) && result.reading >= 0 ? { reading: result.reading } : {}),
+ ...(Number.isInteger(result?.seedBase) ? { seedBase: result.seedBase } : {}),
+ };
+}
+
/**
* A cut's disclosure, from the narrations it keeps (`out/narration/`): the
* editor's lines, each once, joined by `sep`; null when nothing is narrated.
diff --git a/umtool/report-to-video/narration.mjs b/umtool/report-to-video/narration.mjs
@@ -22,7 +22,7 @@
// filter and the disclosure line -- shared by the build, the lint, the deck's
// estimate and the exports. No ffmpeg, no fs, no network.
import { createHash } from "node:crypto";
-import { TTS_TUNING_FIELDS, ttsReadingError, ttsTuningValueError } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
+import { TTS_TUNING_FIELDS, normalizeTtsTuning, ttsReadingError, ttsTuningValueError } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
/** The engines a manifest may name (`orpheus` is refused by the editor until it lands there). */
export const NARRATION_ENGINES = Object.freeze(["kokoro", "orpheus", "espeak-ng"]);
@@ -83,13 +83,14 @@ const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
const numIn = (v, [lo, hi]) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi;
/**
- * A narration's tuning as it is asked and keyed: its set fields in the
- * registry's order, or null when it sets none.
+ * A narration's tuning as it is asked and keyed: the editor's normaliser
+ * (lib/ttsTuning.mjs: quantised, a sampler value equal to Orpheus's default
+ * dropped, in the registry's order), or null when nothing is left -- so a card
+ * spelling a default asks and keys as one without it. `takes` is kept as
+ * written: its default is the editor's settings, which a cut cannot see.
*/
export function narrationTuningOf(tuning) {
- if (!isObj(tuning)) return null;
- const out = {};
- for (const k of TTS_TUNING_FIELDS) if (typeof tuning[k] === "number") out[k] = tuning[k];
+ const out = normalizeTtsTuning(tuning);
return Object.keys(out).length ? out : null;
}
diff --git a/umtool/report-to-video/narration.test.mjs b/umtool/report-to-video/narration.test.mjs
@@ -104,6 +104,14 @@ test("a card's tuning and reading: checked in the editor's ranges, asked and key
assert.notEqual(warm, narrationKey(base));
assert.notEqual(narrationKey({ ...base, reading: 1 }), narrationKey(base));
assert.notEqual(narrationKey({ ...base, reading: 1 }), narrationKey({ ...base, reading: 2 }));
+ // A card spelling a default -- or a default within rounding -- asks and keys as one without it (the editor's
+ // normaliser, lib/ttsTuning.mjs); takes is kept as written (its default is the editor's settings).
+ assert.equal(narrationKey({ ...base, tuning: { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: -0, repeat_penalty: 1.2 } }), narrationKey(base));
+ assert.equal(narrationKey({ ...base, tuning: { temperature: 0.550000001 } }), narrationKey(base));
+ assert.equal(narrationKey({ ...base, tuning: { temperature: 0.7000000000000001 } }), warm);
+ assert.notEqual(narrationKey({ ...base, tuning: { takes: 3 } }), narrationKey(base));
+ const spelled = resolveNarration(card({ narration: { text: "Six.", engine: "orpheus", tuning: { temperature: 0.55 }, reading: 0 } }), {});
+ assert.ok(!("tuning" in spelled) && !("reading" in spelled));
// The fields' order does not matter.
assert.equal(narrationKey({ ...base, tuning: { top_k: 40, temperature: 0.7 } }), narrationKey({ ...base, tuning: { temperature: 0.7, top_k: 40 } }));
const tuned = card({ narration: { text: "Six months later.", engine: "orpheus", voice: "zac", tuning: { temperature: 0.7 }, reading: 2 } });