Archilyzer · Source

archilyzer

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

commit 46ee67c94d65bc5546d12b4b5b62bfd7a66919b8
parent e0d4436e63bcf312267eae7d3a7c0e6d477d452d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 18:01:31 -0500

umtool: the post bench's run AI on take sets a convert's pitch and semitones (seed-vc), starting from the author's character in the cast; the derive route passes and records them, and a missing f0 model is said in the editor's words

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

Diffstat:
Meditor/CHANGELOG.md | 2+-
Mumtool/app/api/report/post-narration/route.ts | 42++++++++++++++++++++++++++++++++----------
Mumtool/components/projects/PostNarrationPanel.tsx | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mumtool/docs/knobs.md | 7++++---
Aumtool/lib/report/derivePitch.mjs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/report/derivePitch.test.mjs | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postNarrationCli.mjs | 5++---
7 files changed, 243 insertions(+), 26 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## [Unreleased] -- **A converted read can follow your pitch.** Converting a recorded read to a stock voice threw the voice acting away. On 11 Nov, reads with a median pitch of 128, 212, 225 and 237 Hz all came out at 196–199 Hz, and a 152–321 Hz range came out as 165–240 Hz: both converters speak at the stock voice's own pitch. `pnpm ops voice-convert` now takes `"pitch"`: `target` (as before), `source` (the pitch you read at: raise your voice and the result rises) or `contour` (your rises and falls, moved as a whole to the stock voice's register), and `"semitones"` (-12 to 12) moves a followed pitch. The same read that came out at 197 Hz now comes out at 211 Hz with a 148–314 Hz range, against 212 Hz and 152–321 Hz read. `source` and `contour` are seed-vc's, on its f0-conditioned model: optional files, fetched by `archilyzer voice setup --engine seed-vc --with f0` (1.49 GB). An install without them converts as before, and a followed pitch is refused naming that command; openvoice refuses a pitch it cannot follow. It takes about 1.7 times as long, and more memory (5.8 GB at its peak on a take of 20 s or more). `settings.voice.convert.pitch` and `.semitones` are the defaults (`target`, 0). In umtool a character keeps its pitch in the cast (`umtool cast set <id> --convert-pitch contour --convert-semitones 2`, shown on Voices), and `--pitch` / `--semitones` on `posts narrate … --recording` or `--derive <n> --op convert` set it for one read. The disclosure line is unchanged. +- **A converted read can follow your pitch.** Converting a recorded read to a stock voice threw the voice acting away. On 11 Nov, reads with a median pitch of 128, 212, 225 and 237 Hz all came out at 196–199 Hz, and a 152–321 Hz range came out as 165–240 Hz: both converters speak at the stock voice's own pitch. `pnpm ops voice-convert` now takes `"pitch"`: `target` (as before), `source` (the pitch you read at: raise your voice and the result rises) or `contour` (your rises and falls, moved as a whole to the stock voice's register), and `"semitones"` (-12 to 12) moves a followed pitch. The same read that came out at 197 Hz now comes out at 211 Hz with a 148–314 Hz range, against 212 Hz and 152–321 Hz read. `source` and `contour` are seed-vc's, on its f0-conditioned model: optional files, fetched by `archilyzer voice setup --engine seed-vc --with f0` (1.49 GB). An install without them converts as before, and a followed pitch is refused naming that command; openvoice refuses a pitch it cannot follow. It takes about 1.7 times as long, and more memory (5.8 GB at its peak on a take of 20 s or more). `settings.voice.convert.pitch` and `.semitones` are the defaults (`target`, 0). In umtool a character keeps its pitch in the cast (`umtool cast set <id> --convert-pitch contour --convert-semitones 2`, shown on Voices), and `--pitch` / `--semitones` on `posts narrate … --recording` or `--derive <n> --op convert` set it for one read; the post bench's **run AI on take** has the same two controls for a convert on seed-vc, starting from the character's. The disclosure line is unchanged. - **The dashboard says when a media drive is not answering, slow, or not mounted.** A stalled external drive used to show only on `/storage` and in channel badges, so the editor looked broken with nothing on its front page saying why. The dashboard now opens with one card per storage location in trouble: **not answering** (an alert: pages and polls skip the drive, and its channels' jobs wait until it answers), **answering slowly** (everything still runs, just late), or **not mounted** (only when some channel's media is on it). Each card links to `/storage` and to that location's channels. On `/storage` each location has a **Drive** line that says when the drive last answered and how long it took (for example "answering — 12 ms (a read in the editor), last at 11:42"), and a **slow** chip appears next to Available when two reads in a row on it take half the 3-second limit or more (one long read is not enough). `pnpm ops get storage` reports the same for each location under `rows[].drive`: `state` (`ok`, `slow`, `stalled` or `unmounted`), `since`, `lastOkAt`, `latencyMs`, the cause and the one-line text. - **A transcription or backfill run waits while its channel's media drive is not answering.** Before, a run that started while the drive answered kept going after the drive stalled. Each next video asked the stalled drive for its audio, waited about 30 seconds and failed. Now the run pauses at the next video and says so in its log ("Holding: the media drive "…" is not answering (since 11:35) — no new transcription starts until it answers again"), then resumes by itself when the drive answers. If it has held for 5 minutes, the run checks the drive itself from a separate process, and it logs that it is still holding every 10 minutes. A run also follows a channel that is moved to another drive while it runs. A video that is refused because the drive is not answering is skipped, not added to the channel's failed-transcriptions list, and is transcribed on a later run. A downloaded video is also not moved into a saved-video store on a drive that is not answering. It stays in the video's folder, and a later pass stores it. - **The drive watch no longer overwrites a tier you change while it is pausing channels.** The five-minute storage watch, which pauses the channels on a drive that went away and restores them when it comes back, could save its change in the middle of yours and undo it. It now waits for the same settings lock that the channel-priority save uses. The editor's `dev` script also gives Node 16 file-access threads, as `start`, the systemd unit and the container already do. diff --git a/umtool/app/api/report/post-narration/route.ts b/umtool/app/api/report/post-narration/route.ts @@ -21,6 +21,9 @@ import { fitPostItem } from "@/lib/report/postFit.mjs"; import { itemReadVoice } from "@/lib/report/readVoice.mjs"; import { projectRedaction } from "@/lib/report/postRedaction.mjs"; import { spokenRead } from "umtool-report-to-video/post-redact"; +import { characterOf, convertTargetOf, narratorOf } from "umtool-report-to-video/cast"; +import { castForProject } from "@/lib/report/castStore.mjs"; +import { derivePitchOf, deriveRefusalOf, stepPitchOf } from "@/lib/report/derivePitch.mjs"; export const dynamic = "force-dynamic"; @@ -41,10 +44,15 @@ const benchVoice = (red: { slurs?: { voice?: string } | null } | null) => (red?. // POST {project, op: "take", id, note?, voice?, engine?, speed?, script?} // a new take asked of the EDITOR's tts op (a job) // POST {project, op: "fit", id, linger?} the attachment's best part for the read (posts fit) -// POST {project, op: "derive", id, from, op2: enhance|convert, engine?, voice?} +// GET ?project&id&convert=1 what a convert of this post defaults to: its author's character in +// the cast (else the narrator) and that character's convert +// target -- {character, convert: {engine, voice, pitch?, semitones?}} +// POST {project, op: "derive", id, from, op2: enhance|convert, engine?, voice?, pitch?, semitones?} // a NEW take made from take `from` by the editor's voice op -// (a job; kept by GET ?job&derive=<from>); `installed: false` -// when the editor has no engine for it +// (a job; kept by GET ?job&derive=<from>[&pitch&semitones]); +// `installed: false` when the editor has no engine for it. A +// convert's `pitch` (target | source | contour) and `semitones` +// are the pitch the read lands on (lib/report/derivePitch.mjs) // POST {project, op: "delete", id, take} a take out of the list, its file to .trash/ (soft) // POST {project, op: "reread", id, without?, dropParts?, dropUrls?} the picked take RE-JOINED without a piece // POST {project, op: "reread", id, tempo: "4-16=1.35", stretch?} its parts RE-TIMED (no TTS); {…, yell: true, yellGain?, yellStyle?}: its caps raised @@ -77,6 +85,14 @@ export async function GET(request: Request) { const render = (m.render ?? {}) as Record<string, unknown>; const id = q.get("id"); const job = q.get("job"); + if (id && !job && q.get("convert") !== null) { + // What a convert of this post defaults to (`posts narrate --recording`'s rule: the author's character, else the narrator). + const e = postsOf(m).find((x) => x.id === id); + if (!e) return Response.json({ error: `no post item ${id}` }, { status: 404 }); + const { cast } = await castForProject(r.project.dir); + const c = characterOf(cast, String((e as { handle?: unknown }).handle ?? "")) ?? narratorOf(cast); + return Response.json({ character: c ? { id: c.id, name: c.name } : null, convert: c ? convertTargetOf(c) : null }, { headers: noStore }); + } if (id && job) { // A GET that WRITES the manifest (a job followed to done): the proxy passes reads, so an <img> on another site // could ask it; refused cross-site here (lib/report/sameOrigin.mjs). @@ -109,13 +125,16 @@ export async function GET(request: Request) { if (!from) return Response.json({ state: "failed", error: `no take ${derive}` }, { headers: noStore }); const op = String(q.get("op") ?? ""); // The editor's defaults, when the ask named none (its `@@voice-result` line). - const vr = resultLine<{ engine?: string; voice?: string }>(st.tail, "@@voice-result ") ?? {}; + const vr = resultLine<{ engine?: string; voice?: string; pitch?: string; semitones?: number }>(st.tail, "@@voice-result ") ?? {}; + // The pitch it landed on, as the editor ran it (else as it was asked); the target's own is not recorded. + const asked = derivePitchOf({ pitch: q.get("pitch"), semitones: q.get("semitones") }); + const pitched = op === "convert" ? stepPitchOf(asked.ok ? asked.value : {}, vr) : {}; const engine = q.get("engine") ?? vr.engine ?? null; const voice = op === "convert" ? (q.get("voice") ?? vr.voice ?? null) : null; const partsRel = rel.replace(/\.wav$/, ".parts"); const derived = { file: rel, engine: "derived", voice: (voice ? voice.split(":").pop() : null) ?? from.voice ?? "?", seconds: meas.seconds, source: { kind: "take", from: takeIdOf(from) }, - steps: [{ op, ...(engine ? { engine } : {}), ...(voice ? { voice } : {}), ranAt: new Date().toISOString(), job }], + steps: [{ op, ...(engine ? { engine } : {}), ...(voice ? { voice } : {}), ...pitched, ranAt: new Date().toISOString(), job }], script: from.script ?? script, at: new Date().toISOString(), jobId: job, ...(Number.isFinite(meas.lufs) ? { lufs: meas.lufs } : {}), ...(Array.isArray(from.parts) ? { parts: from.parts.map((p) => ({ ...p, file: `${partsRel}/p${String(p.n).padStart(2, "0")}.wav` })) } : {}), }; @@ -250,6 +269,9 @@ async function postHere(request: Request) { if (!(POST_DERIVE_OPS as readonly string[]).includes(op)) return Response.json({ error: `op2 is one of ${POST_DERIVE_OPS.join(", ")}` }, { status: 400 }); const engine = body.engine ? String(body.engine) : null; const voice = body.voice ? String(body.voice) : null; + // A convert's pitch (target | source | contour) and semitones, checked here; the editor refuses what its engine cannot do. + const pitched = derivePitchOf({ pitch: body.pitch, semitones: body.semitones }, op); + if (!pitched.ok) return Response.json({ error: pitched.error }, { status: 400 }); const pid = postIdOf(e); const dir = path.join(r.project.dir, ...takesDirOf(pid).split("/")); await mkdir(dir, { recursive: true }); @@ -261,15 +283,15 @@ async function postHere(request: Request) { : null; try { // `voice` is the convert op's stock target; enhance takes none. - const jobId = await startJob(POST_DERIVE_ROUTES[op as keyof typeof POST_DERIVE_ROUTES], { file: abs(t.file), out: abs(rel), ...(engine ? { engine } : {}), ...(voice && op === "convert" ? { voice } : {}), ...(parts ? { parts } : {}) }); - return Response.json({ ok: true, jobId, file: rel, from, op: op, engine, voice }, { headers: noStore }); + const jobId = await startJob(POST_DERIVE_ROUTES[op as keyof typeof POST_DERIVE_ROUTES], { file: abs(t.file), out: abs(rel), ...(engine ? { engine } : {}), ...(voice && op === "convert" ? { voice } : {}), ...pitched.value, ...(parts ? { parts } : {}) }); + return Response.json({ ok: true, jobId, file: rel, from, op: op, engine, voice, ...pitched.value }, { headers: noStore }); } catch (err) { const status = (err as { status?: number }).status ?? 502; const msg = err instanceof Error ? err.message : String(err); // The editor has no engine for it (an older editor has no route; a newer one names the setup to run): say so, plainly, with its words. - if (status === 404 || /not installed|no engine|unknown|not found|404/i.test(msg)) { - return Response.json({ ok: false, installed: false, error: `the editor has no ${op} engine installed (not installed: ${msg.replace(/^the editor refused it: /, "")})` }, { status: 200, headers: noStore }); - } + // A missing optional model (`… --with f0`) is passed through in the editor's words (derivePitch.mjs deriveRefusalOf). + const refusal = deriveRefusalOf(op, status, msg); + if (refusal) return Response.json({ ok: false, ...refusal }, { status: 200, headers: noStore }); return Response.json({ error: msg }, { status }); } } diff --git a/umtool/components/projects/PostNarrationPanel.tsx b/umtool/components/projects/PostNarrationPanel.tsx @@ -7,6 +7,7 @@ import Waveform from "@/components/Waveform"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { postBenchHref } from "@/lib/hrefs"; +import { CAST_CONVERT_ENGINES, CAST_CONVERT_PITCH, CAST_PITCH_ENGINES, CAST_SEMITONES_MAX, convertPitchLabel } from "umtool-report-to-video/cast"; import { POST_DERIVE_OPS, POST_NARRATION_DEFAULTS, mixPhaseAt, pickedTake, postNarrationKnobs, scriptParts, takeIdOf, takeSourceOf } from "umtool-report-to-video/post-narration"; import { projectFileMedia } from "./bench/benchMedia"; import { usePeaks } from "./bench/usePeaks"; @@ -37,7 +38,15 @@ import PostAttachmentLane from "./PostAttachmentLane"; // `umtool posts narrate` runs; the bench takes the entry it returns. // --------------------------------------------------------------------------- -type Step = { op: string; engine?: string; voice?: string }; +// A derived take's step. A convert's `pitch` / `semitones`: the pitch the converted read lands on (knobs.md, "The +// pitch a converted read lands on") -- absent for the stock voice's own. +type Step = { op: string; engine?: string; voice?: string; pitch?: string; semitones?: number }; +// The engines whose convert can FOLLOW the read's pitch (cast.mjs CAST_PITCH_ENGINES), and the modes in plain words. +const PITCH_WORDS: Record<string, string> = { + target: "the stock voice's own pitch", + source: "follow my pitch", + contour: "my intonation, at the voice's register", +}; type Take = { file: string; engine?: string; voice?: string; seconds: number; note?: string; script?: string; label?: string; source?: { kind: string; from?: string; voice?: string; engine?: string }; steps?: Step[]; parts?: Array<{ n: number; para?: number; text?: string; start: number; seconds: number; file?: string }>; words?: Array<{ w: string; start: number; end: number }> }; type Narration = { script?: string; takes?: Take[]; pick?: number; approved?: boolean; off?: boolean; window?: { media: number; start: number; end: number; score?: number; reason?: string } } & Record<string, unknown>; type Entry = Record<string, unknown> & { id: string; narration?: Narration; media?: Array<Record<string, unknown> & { src: string; kind: string; seconds?: number; start?: number; end?: number }> }; @@ -212,20 +221,20 @@ export default function PostNarrationPanel({ // ---- a re-take with direction (the editor's tts op) -------------------------- const [dir, setDir] = useState({ note: "", voice: "", speed: "" }); - const [job, setJob] = useState<{ id: string; file: string; note: string; script: string; state: string; error?: string; polls?: number; derive?: { from: number; op: string; engine?: string | null; voice?: string | null } } | null>(null); + const [job, setJob] = useState<{ id: string; file: string; note: string; script: string; state: string; error?: string; polls?: number; derive?: { from: number; op: string; engine?: string | null; voice?: string | null; pitch?: string | null; semitones?: number | null } } | null>(null); // Derived takes still to make after a re-record ("re-run the chain"), from the new take. const [chain, setChain] = useState<Array<{ from: number; step: Step }>>([]); const [rerunChain, setRerunChain] = useState(true); const [notInstalled, setNotInstalled] = useState<string | null>(null); const derive = async (from: number, step: Step) => { setNotInstalled(null); - const j = (await post({ op: "derive", from, op2: step.op, engine: step.engine || undefined, voice: step.voice || undefined })) as ({ jobId?: string; file?: string; installed?: boolean; error?: string } & Record<string, unknown>) | null; + const j = (await post({ op: "derive", from, op2: step.op, engine: step.engine || undefined, voice: step.voice || undefined, ...(step.op === "convert" && step.pitch ? { pitch: step.pitch, ...(typeof step.semitones === "number" ? { semitones: step.semitones } : {}) } : {}) })) as ({ jobId?: string; file?: string; installed?: boolean; error?: string } & Record<string, unknown>) | null; if (j && j.installed === false) { setNotInstalled(j.error ?? `the editor has no ${step.op} engine yet`); setChain([]); return; } - if (j?.jobId && j.file) setJob({ id: j.jobId, file: j.file, note: "", script, state: "running", derive: { from, op: step.op, engine: step.engine ?? null, voice: step.voice ?? null } }); + if (j?.jobId && j.file) setJob({ id: j.jobId, file: j.file, note: "", script, state: "running", derive: { from, op: step.op, engine: step.engine ?? null, voice: step.voice ?? null, pitch: step.pitch ?? null, semitones: step.semitones ?? null } }); }; const retake = async () => { const j = await post({ op: "take", note: dir.note || undefined, voice: dir.voice || undefined, speed: dir.speed ? Number(dir.speed) : undefined, script }); @@ -236,7 +245,7 @@ export default function PostNarrationPanel({ const t = setTimeout(async () => { const q = new URLSearchParams({ project, id: entry.id, job: job.id, file: job.file, script: job.script, ...(job.note ? { note: job.note } : {}), - ...(job.derive ? { derive: String(job.derive.from), op: job.derive.op, ...(job.derive.engine ? { engine: job.derive.engine } : {}), ...(job.derive.voice ? { voice: job.derive.voice } : {}) } : {}), + ...(job.derive ? { derive: String(job.derive.from), op: job.derive.op, ...(job.derive.engine ? { engine: job.derive.engine } : {}), ...(job.derive.voice ? { voice: job.derive.voice } : {}), ...(job.derive.pitch ? { pitch: job.derive.pitch } : {}), ...(typeof job.derive.semitones === "number" ? { semitones: String(job.derive.semitones) } : {}) } : {}), }); const r = await fetch(`/api/report/post-narration?${q}`, { cache: "no-store" }); const j = (await r.json().catch(() => ({}))) as { state?: string; error?: string; entry?: Entry; token?: string }; @@ -279,7 +288,47 @@ export default function PostNarrationPanel({ roots.forEach((i) => walk(i, 0)); return { rows: out, kids }; }, [takes]); - const [deriveDraft, setDeriveDraft] = useState<{ op: string; engine: string; voice: string }>({ op: "enhance", engine: "", voice: "" }); + const [deriveDraft, setDeriveDraft] = useState<{ op: string; engine: string; voice: string; pitch: string; semitones: string }>({ op: "enhance", engine: "", voice: "", pitch: "target", semitones: "" }); + // What a convert of THIS post defaults to: its author's character in the cast (else the narrator) -- the engine, the + // stock voice and the pitch every recording made that character's lands on (`umtool cast set <id> --convert-pitch …`). + const [castConvert, setCastConvert] = useState<{ name: string; engine?: string | null; voice?: string | null; pitch?: string; semitones?: number } | null>(null); + useEffect(() => { + let live = true; + setCastConvert(null); + fetch(`/api/report/post-narration?project=${encodeURIComponent(project)}&id=${encodeURIComponent(entry.id)}&convert=1`, { cache: "no-store" }) + .then((r) => (r.ok ? r.json() : null)) + .then((j: { character?: { name: string } | null; convert?: { engine?: string | null; voice?: string | null; pitch?: string; semitones?: number } | null } | null) => { + if (live && j?.character && j.convert) setCastConvert({ name: j.character.name, ...j.convert }); + }) + .catch(() => {}); + return () => { + live = false; + }; + }, [project, entry.id]); + // Choosing the op: a convert starts from the character's entry (its engine and voice only where the field is + // empty); an enhance drops a convert engine left in the field. + const chooseDeriveOp = (op: string) => + setDeriveDraft((d) => + op !== "convert" + ? { ...d, op, engine: (CAST_CONVERT_ENGINES as readonly string[]).includes(d.engine.trim()) ? "" : d.engine } + : { + op, + engine: d.engine || castConvert?.engine || "", + voice: d.voice || castConvert?.voice || "", + pitch: castConvert?.pitch ?? "target", + semitones: castConvert?.semitones ? String(castConvert.semitones) : "", + }, + ); + // The pitch controls are an engine's that can follow one; without it the convert lands on the stock voice's own. + const derivePitched = deriveDraft.op === "convert" && (CAST_PITCH_ENGINES as readonly string[]).includes(deriveDraft.engine.trim()); + const deriveSemitones = Number(deriveDraft.semitones || 0); + const deriveSemitonesBad = derivePitched && deriveDraft.pitch !== "target" && !(Number.isFinite(deriveSemitones) && Math.abs(deriveSemitones) <= CAST_SEMITONES_MAX); + const deriveStep = (): Step => ({ + op: deriveDraft.op, + ...(deriveDraft.engine.trim() ? { engine: deriveDraft.engine.trim() } : {}), + ...(deriveDraft.op === "convert" && deriveDraft.voice.trim() ? { voice: deriveDraft.voice.trim() } : {}), + ...(derivePitched ? { pitch: deriveDraft.pitch, ...(deriveDraft.pitch !== "target" ? { semitones: deriveSemitones } : {}) } : {}), + }); // ---- the lanes ------------------------------------------------------------------ // One lane per timed attachment (a video, a GIF), its in and out the bench's draft (onTrim). @@ -589,7 +638,7 @@ export default function PostNarrationPanel({ <div className="flex flex-wrap items-center gap-2"> <span className="font-mono">{depth ? "└ " : ""}#{i + 1}</span> <span> - {src.kind === "recorded" ? `recorded · ${src.voice ?? t.voice ?? "?"}` : src.kind === "take" ? `${step?.op ?? "derived"}${step?.engine ? ` · ${step.engine}` : ""}${step?.voice ? ` → ${step.voice}` : ""}` : `${t.engine ?? "?"} · ${t.voice ?? "?"}`} + {src.kind === "recorded" ? `recorded · ${src.voice ?? t.voice ?? "?"}` : src.kind === "take" ? `${step?.op ?? "derived"}${step?.engine ? ` · ${step.engine}` : ""}${step?.voice ? ` → ${step.voice}` : ""}${convertPitchLabel(step) ? ` · pitch: ${convertPitchLabel(step)}` : ""}` : `${t.engine ?? "?"} · ${t.voice ?? "?"}`} </span> <span className="tabular-nums">{Number(t.seconds).toFixed(1)} s</span> {/* eslint-disable-next-line jsx-a11y/media-has-caption */} @@ -642,7 +691,7 @@ export default function PostNarrationPanel({ {picked && ( <div className="flex flex-wrap items-center gap-1.5" data-post-derive=""> <span className="micro">run AI on take #{picked.index + 1}</span> - <select value={deriveDraft.op} onChange={(e) => setDeriveDraft({ ...deriveDraft, op: e.target.value })} data-post-derive-op=""> + <select value={deriveDraft.op} onChange={(e) => chooseDeriveOp(e.target.value)} data-post-derive-op=""> {POST_DERIVE_OPS.map((o) => ( <option key={o} value={o}> {o === "enhance" ? "enhance (denoise, level)" : "convert (to a stock synthetic voice)"} @@ -653,7 +702,30 @@ export default function PostNarrationPanel({ {deriveDraft.op === "convert" && ( <input value={deriveDraft.voice} onChange={(e) => setDeriveDraft({ ...deriveDraft, voice: e.target.value })} placeholder="stock voice" className="w-24 rounded border border-seam bg-ground px-1 py-0.5" data-post-derive-voice="" /> )} - <button type="button" className={btn} disabled={job?.state === "running"} onClick={() => void derive(picked.index, { op: deriveDraft.op, ...(deriveDraft.engine ? { engine: deriveDraft.engine } : {}), ...(deriveDraft.voice ? { voice: deriveDraft.voice } : {}) })} data-post-derive-run=""> + {derivePitched && ( + <label className="flex items-center gap-1" title="where the converted read's pitch comes from: the stock voice's own (your intonation is flattened to it), the pitch you read at, or your rises and falls moved to the stock voice's register"> + <span className="micro">pitch</span> + <select value={deriveDraft.pitch} onChange={(e) => setDeriveDraft({ ...deriveDraft, pitch: e.target.value })} aria-label="the pitch the converted read lands on" data-post-derive-pitch=""> + {CAST_CONVERT_PITCH.map((p) => ( + <option key={p} value={p}> + {PITCH_WORDS[p] ?? p} + </option> + ))} + </select> + </label> + )} + {derivePitched && deriveDraft.pitch !== "target" && ( + <label className="flex items-center gap-1" title={`moves the followed pitch up or down, in semitones (-${CAST_SEMITONES_MAX} to ${CAST_SEMITONES_MAX}); 0: as followed`}> + <input type="number" min={-CAST_SEMITONES_MAX} max={CAST_SEMITONES_MAX} step={0.5} value={deriveDraft.semitones} onChange={(e) => setDeriveDraft({ ...deriveDraft, semitones: e.target.value })} placeholder="0" aria-label="semitones the followed pitch is moved by" aria-invalid={deriveSemitonesBad || undefined} className="w-14 rounded border border-seam bg-ground px-1 py-0.5" data-post-derive-semitones="" /> + <span className="micro">semitones</span> + </label> + )} + {deriveDraft.op === "convert" && castConvert && ( + <span className="micro text-text-2" data-post-derive-cast=""> + {castConvert.name}&apos;s in the cast: {[castConvert.engine, castConvert.voice, convertPitchLabel(castConvert) ? `pitch ${convertPitchLabel(castConvert)}` : null].filter(Boolean).join(" · ")} + </span> + )} + <button type="button" className={btn} disabled={job?.state === "running" || deriveSemitonesBad} onClick={() => void derive(picked.index, deriveStep())} data-post-derive-run=""> Run → a new take </button> {notInstalled && ( diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -1168,7 +1168,7 @@ the shape, the mix, recordings, parts, the best part). One writer for a post's n | a recorded take — your own read, part by part, kept as `take-<n>.recorded-<label>.wav`, picked | post bench, **record your read**: the mic, the level, **Record** (R) / **Stop** (S) / **Redo part** / **Next part**, **Keep** / **Discard**, **voice** (the label, default `operator`) | — | `POST` multipart `{project, id, label, script?, part[], text[], para[]}` | | a synthesized take — the editor's tts op, with direction | post bench, **Re-take with direction** (a note, a voice) | `umtool posts narrate <p> <item> --take [--note "…"] [--voice v] [--engine e] [--speed s]` · every missing one: `--all --take` | `op: "take"` → `{jobId, file}` · `GET ?project&id&job&file` keeps it when done | | a THREAD READ — the post it answers (or every ancestor), the post it quotes, the linked posts and his words, each in its author's voice, parts cached, one take picked ([below](#pronunciation-and-voices-the-lexicon-the-voice-map-a-thread-read)) | — | `umtool posts narrate <p> <item> --take --thread [--parents 0\|all] [--skip-parent <id>]… [--voice-for <handle>=<voice>]… [--dry-run] [--json]` | — | -| a derived take — a take run through the editor's `enhance` or `convert` (a stock synthetic voice: `zac`, `leah`, `orpheus:zac`, never a recording) into a NEW take, the original kept; enhance engines `deepfilternet` · `rnnoise`, convert `openvoice` · `seed-vc` (unnamed: the editor's settings.voice, recorded on the take); "not installed" until `archilyzer voice setup --engine <id>`; a convert's **pitch** ([below](#the-pitch-a-converted-read-lands-on)) from a terminal | post bench, **run AI on take #n** (the op, an engine, a stock voice) → **Run → a new take**; a derived take's **Re-run**; a recording's **Re-record** with **then re-run the chain** | `umtool posts narrate <p> <item> --derive <n> --op enhance\|convert [--engine e] [--voice v] [--pitch target\|source\|contour] [--semitones n]` | `op: "derive", from, op2, engine?, voice?` → `{jobId, file}` (or `{installed: false}`) · `GET ?project&id&job&file&derive=<from>&op=…` keeps it | +| a derived take — a take run through the editor's `enhance` or `convert` (a stock synthetic voice: `zac`, `leah`, `orpheus:zac`, never a recording) into a NEW take, the original kept; enhance engines `deepfilternet` · `rnnoise`, convert `openvoice` · `seed-vc` (unnamed: the editor's settings.voice, recorded on the take); "not installed" until `archilyzer voice setup --engine <id>`; a convert's **pitch** ([below](#the-pitch-a-converted-read-lands-on)) | post bench, **run AI on take #n** (the op, an engine, a stock voice; for a convert on `seed-vc`, **pitch** and **semitones**) → **Run → a new take**; a derived take's **Re-run**; a recording's **Re-record** with **then re-run the chain** | `umtool posts narrate <p> <item> --derive <n> --op enhance\|convert [--engine e] [--voice v] [--pitch target\|source\|contour] [--semitones n]` | `op: "derive", from, op2, engine?, voice?, pitch?, semitones?` → `{jobId, file}` (or `{installed: false}`) · `GET ?project&id&job&file&derive=<from>&op=…` keeps it | | delete a take (soft: its file to the post's `.trash/`) | post bench, the take's **Delete** | `--delete <n>` | `op: "delete", take` (an index) | | `narration.pick` — the take that plays | post bench, the take's **Pick** | `--pick <n>` (1 = the first, as `--list` shows) | `patch: {pick}` (an index) | | `narration.approved` — the picked take on this script, approved (a new script or pick takes it away) | post bench, **approved** | `--approve` · `--unapprove` | `patch: {approved: true \| null}` | @@ -1380,7 +1380,8 @@ from (the editor's `voice-convert`: `pitch`, `semitones`): - **`contour`** -- your rises and falls, moved as a whole so their median sits on the stock voice's median: read in your ordinary voice, and the character speaks in its own register with your intonation. - **`semitones`** (-12 to 12) then moves a followed pitch (`source`, `contour`) up or down. With `target` it is - refused: nothing is followed to move. + refused: nothing is followed to move. A convert that names a followed pitch and no semitones takes + `settings.voice.convert.semitones` (0 unless set). `source` and `contour` are **seed-vc's**, on its f0-conditioned model -- optional files, `archilyzer voice setup --engine seed-vc --with f0` (1.49 GB); it takes about 1.7 times as long as seed-vc at the target's pitch. openvoice has one @@ -1390,7 +1391,7 @@ pitch and refuses another; a followed pitch without the f0 files is refused nami | Knob | In umtool | From a terminal | Route | |---|---|---|---| | a character's convert pitch -- `convert.pitch`, `convert.semitones` in the cast: what every recording made that character's lands on | **Voices**: the cast row says it ("pitch: follows your pitch +2 st"), and the recording form's *as …* choice | `umtool cast set <id> --convert-engine seed-vc --convert-pitch source\|contour\|target [--convert-semitones n]` (the flags given are laid over the entry; `--no-convert` clears it) | `POST /api/report/voices {op: "cast-set", id, convertPitch?, convertSemitones?}` | -| one read's pitch -- this conversion only, over the character's | — | `umtool posts narrate <p> <item> --recording <file> [--as <character>] --pitch source\|contour\|target [--semitones n]` · `--derive <n> --op convert --engine seed-vc [--voice v] --pitch … [--semitones n]` | the editor's `POST /api/ops/voice-convert {…, pitch?, semitones?}` | +| one read's pitch -- this conversion only, over the character's | post bench, **run AI on take #n** → *convert*, engine `seed-vc`: **pitch** (the stock voice's own pitch · follow my pitch · my intonation, at the voice's register) and **semitones**, starting from the post author's character in the cast (else the narrator), which the row names; a converted take's row says its pitch, and **Re-run** keeps it | `umtool posts narrate <p> <item> --recording <file> [--as <character>] --pitch source\|contour\|target [--semitones n]` · `--derive <n> --op convert --engine seed-vc [--voice v] --pitch … [--semitones n]` | `POST /api/report/post-narration {op: "derive", …, pitch?, semitones?}` · `GET …?project&id&convert=1` (the character's default) · the editor's `POST /api/ops/voice-convert {…, pitch?, semitones?}` | | the default for every conversion that names none | — | `settings.voice.convert.pitch`, `.semitones` ([SETTINGS.md](../../SETTINGS.md)) | — | A converted take's step keeps the pitch it was run at (`steps: [{op: "convert", engine, voice, pitch, semitones}]`), diff --git a/umtool/lib/report/derivePitch.mjs b/umtool/lib/report/derivePitch.mjs @@ -0,0 +1,58 @@ +// A CONVERT'S PITCH, between umtool and the editor's voice-convert (the pitch a converted read lands on: knobs.md, +// "The pitch a converted read lands on"). The pure pieces the CLI's derive (postNarrationCli.mjs deriveTake) and the +// app's (app/api/report/post-narration/route.ts, the post bench's "run AI on take") share, so they ask, record and +// refuse alike: +// +// derivePitchOf what a derive is asked with (`pitch`, `semitones`), checked before any job +// stepPitchOf what the new take's step keeps: the pitch as the editor RAN it, never the target's own +// deriveRefusalOf an editor refusal read as "no engine for it" -- or passed through as it is, when it already +// names the command that fixes it +// +// Dependency-free but for cast.mjs's constants. +import { CAST_CONVERT_PITCH, CAST_SEMITONES_MAX } from "umtool-report-to-video/cast"; + +/** + * A derive's `pitch` / `semitones` as asked (a body's, a flag's): `{ ok: true, value: {pitch?, semitones?} }` with only + * what was given, or `{ ok: false, error }`. `semitones` may be a number or its string (a form field, a query). They + * are a convert's: asked of another op they are refused. + */ +export function derivePitchOf({ pitch, semitones } = {}, op = "convert") { + const none = (v) => v === undefined || v === null || v === ""; + if (none(pitch) && none(semitones)) return { ok: true, value: {} }; + if (op !== "convert") return { ok: false, error: `pitch and semitones are a convert's: ${op} keeps the read's own pitch` }; + const value = {}; + if (!none(pitch)) { + if (!CAST_CONVERT_PITCH.includes(pitch)) return { ok: false, error: `pitch is one of ${CAST_CONVERT_PITCH.join(", ")} (got ${JSON.stringify(pitch)})` }; + value.pitch = pitch; + } + if (!none(semitones)) { + const n = typeof semitones === "number" ? semitones : typeof semitones === "string" && semitones.trim() !== "" ? Number(semitones) : NaN; + if (!Number.isFinite(n) || Math.abs(n) > CAST_SEMITONES_MAX) return { ok: false, error: `semitones is a number from -${CAST_SEMITONES_MAX} to ${CAST_SEMITONES_MAX} (got ${JSON.stringify(semitones)})` }; + value.semitones = n; + } + return { ok: true, value }; +} + +/** + * The pitch a derived take's step keeps: what the editor says it ran (its `@@voice-result`: its default when none was + * asked), else what was asked. The stock voice's own pitch is not a step's news (`{}`), and 0 semitones is none. + */ +export function stepPitchOf(asked = {}, said = {}) { + const pitch = typeof said?.pitch === "string" ? said.pitch : asked?.pitch; + if (!pitch || pitch === "target" || !CAST_CONVERT_PITCH.includes(pitch)) return {}; + const n = typeof said?.semitones === "number" ? said.semitones : asked?.semitones; + return { pitch, ...(typeof n === "number" && Number.isFinite(n) && n !== 0 ? { semitones: n } : {}) }; +} + +/** + * An editor refusal of a derive, read: `null` (an ordinary error), or `{ installed: false, error }` -- the editor has + * no engine for the op (an older editor has no route; a newer one names the setup to run). A refusal that names an + * OPTIONAL group to fetch (`… --with f0`: the engine is there, its pitch-following model is not) is passed through in + * the editor's words: "no convert engine installed" would be false. + */ +export function deriveRefusalOf(op, status, message) { + const msg = String(message ?? "").replace(/^the editor refused it: /, ""); + if (!(status === 404 || /not installed|no engine|unknown|not found|404/i.test(msg))) return null; + if (/--with\b/.test(msg)) return { installed: false, error: msg }; + return { installed: false, error: `the editor has no ${op} engine installed (not installed: ${msg})` }; +} diff --git a/umtool/lib/report/derivePitch.test.mjs b/umtool/lib/report/derivePitch.test.mjs @@ -0,0 +1,65 @@ +// lib/report/derivePitch.mjs: a convert's pitch between umtool and the editor -- what a derive is asked with, what the +// new take's step keeps, and which editor refusals mean "no engine". The app's derive route +// (app/api/report/post-narration/route.ts) and the CLI's (postNarrationCli.mjs deriveTake) both go through it. +// Run: node --test umtool/lib/report/derivePitch.test.mjs +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { validatePostNarration } from "umtool-report-to-video/post-narration"; +import { derivePitchOf, deriveRefusalOf, stepPitchOf } from "./derivePitch.mjs"; + +test("a derive's pitch as asked: only what was given, a body's number or a query's string, a convert's alone", () => { + assert.deepEqual(derivePitchOf({}), { ok: true, value: {} }); + assert.deepEqual(derivePitchOf({ pitch: null, semitones: "" }), { ok: true, value: {} }, "a query with neither"); + assert.deepEqual(derivePitchOf({ pitch: "contour", semitones: 2 }), { ok: true, value: { pitch: "contour", semitones: 2 } }); + assert.deepEqual(derivePitchOf({ pitch: "source", semitones: "-1.5" }), { ok: true, value: { pitch: "source", semitones: -1.5 } }); + assert.deepEqual(derivePitchOf({ pitch: "target" }), { ok: true, value: { pitch: "target" } }); + assert.deepEqual(derivePitchOf({ semitones: 0 }), { ok: true, value: { semitones: 0 } }, "0 is said, not dropped: the editor's default may be another"); + for (const [given, re] of [ + [{ pitch: "up" }, /^pitch is one of target, source, contour \(got "up"\)$/], + [{ pitch: 2 }, /pitch is one of/], + [{ pitch: "source", semitones: 13 }, /^semitones is a number from -12 to 12 \(got 13\)$/], + [{ pitch: "source", semitones: "two" }, /semitones is a number from -12 to 12 \(got "two"\)/], + [{ pitch: "source", semitones: true }, /semitones is a number/], + ]) { + const r = derivePitchOf(given); + assert.equal(r.ok, false, JSON.stringify(given)); + assert.match(r.error, re); + } + const en = derivePitchOf({ pitch: "source" }, "enhance"); + assert.equal(en.ok, false); + assert.match(en.error, /pitch and semitones are a convert's: enhance keeps the read's own pitch/); + assert.deepEqual(derivePitchOf({}, "enhance"), { ok: true, value: {} }); +}); + +test("the step keeps the pitch the editor ran, else the one asked; never the target's own, never 0 semitones", () => { + assert.deepEqual(stepPitchOf({}, {}), {}); + assert.deepEqual(stepPitchOf({ pitch: "target" }, {}), {}); + assert.deepEqual(stepPitchOf({ pitch: "contour", semitones: 2 }, {}), { pitch: "contour", semitones: 2 }, "an editor that says nothing"); + assert.deepEqual(stepPitchOf({ pitch: "source", semitones: 0 }, null), { pitch: "source" }); + // The editor's default, when none was asked. + assert.deepEqual(stepPitchOf({}, { pitch: "contour", semitones: 2 }), { pitch: "contour", semitones: 2 }); + // What it ran beats what was asked (its settings' semitones under an asked pitch). + assert.deepEqual(stepPitchOf({ pitch: "source" }, { pitch: "source", semitones: -1 }), { pitch: "source", semitones: -1 }); + assert.deepEqual(stepPitchOf({ pitch: "contour", semitones: 2 }, { pitch: "target" }), {}); + assert.deepEqual(stepPitchOf({}, { pitch: "sideways" }), {}, "not a pitch the manifest takes"); + // Whatever it returns is a step the manifest's validator takes. + for (const p of [{ pitch: "contour", semitones: 2 }, { pitch: "source" }, {}]) { + const entry = { id: "p-1", narration: { script: "x", takes: [{ file: "narration/posts/1/take-2.convert-seed-vc.wav", engine: "derived", voice: "af_bella", seconds: 1, source: { kind: "take", from: "take-1.recorded-operator" }, steps: [{ op: "convert", engine: "seed-vc", voice: "kokoro:af_bella", ...stepPitchOf(p, {}) }] }], pick: 0 } }; + assert.deepEqual(validatePostNarration(entry).filter((e) => /steps/.test(e)), [], JSON.stringify(p)); + } +}); + +test("an editor refusal: no engine, an ordinary error, or a missing optional model said in the editor's words", () => { + assert.deepEqual(deriveRefusalOf("enhance", 404, "HTTP 404"), { installed: false, error: "the editor has no enhance engine installed (not installed: HTTP 404)" }); + assert.deepEqual( + deriveRefusalOf("convert", 400, "the editor refused it: OpenVoice v2 is not installed (/v/openvoice): missing the python venv — run `archilyzer voice setup --engine openvoice`"), + { installed: false, error: "the editor has no convert engine installed (not installed: OpenVoice v2 is not installed (/v/openvoice): missing the python venv — run `archilyzer voice setup --engine openvoice`)" }, + ); + // seed-vc IS installed; its pitch-following model is not: the editor's sentence, as it is. + const f0 = "pitch \"source\" needs Seed-VC (v1, 22 kHz speech)'s f0 model, which is not installed (/v/seed-vc: missing rmvpe.pt) — run `archilyzer voice setup --engine seed-vc --with f0`"; + assert.deepEqual(deriveRefusalOf("convert", 400, `the editor refused it: ${f0}`), { installed: false, error: f0 }); + assert.equal(/no convert engine/.test(deriveRefusalOf("convert", 400, f0).error), false); + // Not about an install: the caller answers it as the error it is. + assert.equal(deriveRefusalOf("convert", 400, "OpenVoice v2 (tone-colour converter) has no pitch control — it lands every read on the target's own pitch"), null); + assert.equal(deriveRefusalOf("convert", 400, "\"semitones\" moves a followed pitch"), null); +}); diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -27,6 +27,7 @@ import { NARRATION_INDEX, POST_DERIVE_OPS, POST_DERIVE_ROUTES, derivedFileOf, draftScript, takeIdOf, isNarrated, nextTakeNumber, pickedTake, postIdOf, postNarrationKnobs, takeFileOf, takesDirOf, } from "umtool-report-to-video/post-narration"; import { CAST_CONVERT_PITCH, CAST_SEMITONES_MAX } from "umtool-report-to-video/cast"; +import { stepPitchOf } from "./derivePitch.mjs"; import { excerptSpansOf, postItemPlan, postReadText } from "umtool-report-to-video/post-item"; import { partRoles } from "umtool-report-to-video/post-thread"; import { spokenRead } from "umtool-report-to-video/post-redact"; @@ -730,9 +731,7 @@ export async function deriveTake(project, e, { from, op, engine = null, voice = const ran = engine ?? (typeof said?.engine === "string" ? said.engine : null); const landed = op === "convert" ? (target ?? (typeof said?.voice === "string" ? said.voice : null)) : null; // The pitch it landed on, as the editor ran it (its default when none was asked); the target's own is not a step's news. - const ranPitch = op === "convert" ? (typeof said?.pitch === "string" ? said.pitch : pitch) : null; - const ranSemitones = typeof said?.semitones === "number" ? said.semitones : semitones; - const pitched = ranPitch && ranPitch !== "target" ? { pitch: ranPitch, ...(typeof ranSemitones === "number" && ranSemitones !== 0 ? { semitones: ranSemitones } : {}) } : {}; + const pitched = op === "convert" ? stepPitchOf({ pitch, semitones }, said) : {}; const take = { // A take's voice is the bare stock voice ("am_michael"); its step keeps the target as asked ("kokoro:am_michael"). file: rel, engine: "derived", voice: (landed ? String(landed).split(":").pop() : null) ?? t.voice ?? "?", seconds: m.seconds ?? t.seconds,