// AN AUDITION (operator, 6 Nov 2026: "in UI alone be able to try rendering different ones to compare"): ONE LINE // read by 2-6 candidate stock voices, each synthesized by the EDITOR (its tts op, a job on its queue: the GPU and the // heavy slot are its to arbitrate -- Orpheus pins ~8.5 GB, Kokoro is fast), kept beside the project and brought to // ONE LOUDNESS so they compare by ear, not by level; and each scored for its CLOSENESS TO THE CHARACTER'S REAL VOICE // when the project names one (speakers.json, as `umtool speaker-check` reads it: TitaNet-small, local) -- a // reference to compare with, NEVER a target. // // /narration/auditions/.wav the candidate, -20 LUFS, 48 kHz mono (key: sha1(engine|voice|text); a // TUNED one's -- an Orpheus tuning or a reading: characterTuning.mjs // `umtool cast try` -- sha1(engine|voice|text|tuning|reading)) // /narration/auditions/.json { key, engine, voice, text, seconds, lufs, at, jobId, disclosure, tuning?, reading? } // /narration/auditions/ref-.wav an excerpt of the real voice, the same loudness (to listen to) // /narration/auditions/scores.json { version, rows: { "|": { score, speaker, at, model } } } // // Without a project the candidates are kept in /.umtool/cast/auditions/ and not scored. The same line // in the same voice is never asked twice: a re-audition is a cache hit. // // Plain ESM: the CLI runs under bare node. import { execFile } from "node:child_process"; import { createHash } from "node:crypto"; import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { promisify } from "node:util"; import { draftScript, scriptParts } from "umtool-report-to-video/post-narration"; import { cardText } from "umtool-report-to-video/post-item"; import { handleKey, voiceRefOf, voiceSpecOf } from "umtool-report-to-video/post-say"; import { ENGINE_WEIGHT, speakerFor } from "umtool-report-to-video/cast"; import { REPORTS_ROOT } from "../paths.mjs"; import { tmpPathFor } from "yt-dlp-transcript-common/lib/atomicFile.mjs"; import { ORPHEUS_DEFAULT_TAKES, normalizeTtsTuning } from "yt-dlp-transcript-common/lib/ttsTuning.mjs"; const execFileP = promisify(execFile); const FFMPEG = () => process.env.FFMPEG_BIN ?? "ffmpeg"; const r3 = (v) => Math.round(v * 1000) / 1000; const str = (v) => (typeof v === "string" ? v : ""); /** Where a project's auditions are kept (relative to it). */ export const AUDITION_DIR = "narration/auditions"; export const AUDITION_SCORES = `${AUDITION_DIR}/scores.json`; /** The level every candidate (and the reference) is brought to. */ export const AUDITION_LUFS = -20; /** At most this many candidates in one audition; at most this many characters in its line. */ export const AUDITION_MAX = 6; export const AUDITION_TEXT_MAX = 400; /** The line read when the character has none of its own in the project. */ export const STOCK_LINE = "Well, here's the thing. I said it before, and I'll say it again: you cannot make this stuff up."; /** The words that ask for the stock line (the panel's "a stock line", the CLI's --stock). */ export const STOCK_ASK = "__stock__"; /** How long the reference excerpt of the real voice is, at most. */ export const REFERENCE_SECONDS = 12; export class AuditionError extends Error { constructor(message) { super(message); this.name = "AuditionError"; } } /** * A candidate's cache key: sha1 of `engine|voice|text`, 20 hex -- and, for a TUNED one (an Orpheus tuning off the * defaults, normalised; or a reading past the first), of `tuned:` and the JSON of [engine, voice, text, tuning, * reading]. An untuned key starts with an engine's name, never `tuned:`, so no text makes the two collide. With neither * the key is the one it always was (a candidate kept before is still a cache hit). */ export function auditionKey(engine, voice, text, { tuning = null, reading = 0 } = {}) { const t = normalizeTtsTuning(tuning, { takes: ORPHEUS_DEFAULT_TAKES }); const r = Number.isInteger(reading) && reading > 0 ? reading : 0; const tuned = Object.keys(t).length > 0 || r > 0; return createHash("sha1").update(tuned ? `tuned:${JSON.stringify([engine, voice, text, t, r])}` : `${engine}|${voice}|${text}`).digest("hex").slice(0, 20); } /** Is a key's ask a tuned one (a tuning off the defaults, or a reading past the first)? */ export const isTunedAsk = ({ tuning = null, reading = 0 } = {}) => Object.keys(normalizeTtsTuning(tuning, { takes: ORPHEUS_DEFAULT_TAKES })).length > 0 || (Number.isInteger(reading) && reading > 0); /** The candidates as `[{ engine, voice, spec, weight }]` from `kokoro:am_michael,orpheus:zac` (a bare voice: `engine`). */ export function candidatesOf(list, engine = "kokoro") { const out = []; for (const raw of (Array.isArray(list) ? list : [list]).flatMap((x) => String(x ?? "").split(",")).map((x) => x.trim()).filter(Boolean)) { const ref = voiceRefOf(raw, engine); if (!ref?.engine) throw new AuditionError(`"${raw}" is not a stock voice ("kokoro:am_michael", "orpheus:zac"): a file or a recording is never a candidate`); const spec = voiceSpecOf(ref); if (!out.some((c) => c.spec === spec)) out.push({ engine: ref.engine, voice: ref.voice, spec, weight: ENGINE_WEIGHT[ref.engine] ?? "fast" }); } if (!out.length) throw new AuditionError("--voices names the candidates: --voices kokoro:am_michael,kokoro:am_onyx,orpheus:zac"); if (out.length > AUDITION_MAX) throw new AuditionError(`at most ${AUDITION_MAX} candidates in one audition (got ${out.length})`); return out; } /** A line cut to what an audition reads: its first part (post-narration.mjs scriptParts), at most AUDITION_TEXT_MAX at a sentence end. */ export function auditionText(text) { const first = scriptParts(str(text).trim())[0]?.text ?? str(text).trim(); if (first.length <= AUDITION_TEXT_MAX) return first; const cut = first.slice(0, AUDITION_TEXT_MAX); const at = Math.max(cut.lastIndexOf(". "), cut.lastIndexOf("? "), cut.lastIndexOf("! ")); return (at > 80 ? cut.slice(0, at + 1) : cut).trim(); } /** * THE CHARACTER's LINES in a project, pure: `[{ item, text, own }]` -- each post item of theirs (its script, else its * words cleaned to be spoken), then each context post of theirs another item carries (its words). `handles` keyed * as the map keys them. */ export function characterLines(manifest, handles) { const hs = new Set((handles ?? []).map(handleKey).filter(Boolean)); const lines = []; for (const e of Array.isArray(manifest?.timeline) ? manifest.timeline : []) { if (e?.type !== "post") continue; if (hs.has(handleKey(e.handle))) { const t = str(e.narration?.script).trim() || draftScript(cardText(e)).script; if (t) lines.push({ item: e.id, text: auditionText(t), own: true }); } const ctx = [...(Array.isArray(e.parents) ? e.parents : []), ...(e.quoted ? [e.quoted] : []), ...(Array.isArray(e.links) ? e.links : [])]; for (const p of ctx) { if (!hs.has(handleKey(p?.handle))) continue; const t = draftScript(str(p.paraphrase) || str(p.text)).script; if (t) lines.push({ item: e.id, text: auditionText(t), own: false, context: str(p.id) || null }); } } return lines.filter((l, i) => lines.findIndex((x) => x.text === l.text) === i); } /** * The character `who` names for an audition: one of the project's own characters (its id, a handle), a cast character (its id, a handle, its name), else an AUTHOR of the * project by @handle (`{ id, name, handles, voice: null }`). Throws AuditionError naming what is missing. */ export async function auditionCharacter(cast, who, { project = null, manifest = null } = {}) { const { characterOf, findCharacter, projectCharactersOf, shownNameOf } = await import("umtool-report-to-video/cast"); const w = String(who ?? "").trim(); if (!w) throw new AuditionError("an audition is of a character (its id, or @handle)"); // This video's own characters first (narration/characters.json): by id, then by a handle -- named as it is shown. const own = project ? projectCharactersOf((await (await import("./castStore.mjs")).readProjectCharacters(project.dir)).doc) : []; const mine = (c) => ({ ...c, name: shownNameOf(c), handles: c.handles ?? [], voice: c.voice ?? null }); if (!w.startsWith("@")) { const p = own.find((x) => x.id === w.toLowerCase()); if (p) return mine(p); const c = findCharacter(cast, w); if (c) return c; } const h = handleKey(w); const p = own.find((x) => (x.handles ?? []).includes(h)); if (p) return mine(p); const c = characterOf(cast, h); if (c) return c; if (!project) throw new AuditionError(`${w} is not in the cast (umtool cast ls), and no --project names it`); const { authorsOf } = await import("./castProject.mjs"); const a = manifest ? authorsOf(manifest).get(h) : null; if (!a) throw new AuditionError(`${w} is neither in the cast nor an author in ${project.id}`); return { id: h, name: a.name || h, handles: [h], voice: null }; } /** * THE LINE an audition reads: `text`, else the character's line from `item`, else its `line`-th (1-based), else its * first own line of AUDITION_MIN_WORDS words or more (else its longest: defaultLine), else STOCK_LINE -- cut to one part, and with a project WHAT A VOICE SAYS (its redaction, slur * filter -- a slur skipped -- and lexicon). Returns `{ text, from }` (`from`: "text", "item:", "stock"). */ export async function auditionLine(project, manifest, character, { text = null, item = null, line = null } = {}) { // The stock line asked for outright (`--stock`; the panel's "a stock line"). if (text === STOCK_ASK) return { text: STOCK_LINE, from: "stock" }; let t = text ? String(text) : null; let from = t ? "text" : null; let e = null; if (!t && manifest) { const lines = characterLines(manifest, character.handles ?? []); const pick = item ? lines.find((l) => l.item === item) : line ? lines[Number(line) - 1] : defaultLine(lines); if ((item || line) && !pick) throw new AuditionError(`${character.name} has no such line in ${project?.id ?? "the project"} (umtool cast project ${project?.id ?? "

"} lists them)`); if (pick) { t = pick.text; from = `item:${pick.item}`; e = manifest.timeline.find((x) => x?.id === pick.item) ?? null; } } if (!t) { t = STOCK_LINE; from = "stock"; } t = auditionText(t); if (project && manifest) { const { projectRedaction } = await import("./postRedaction.mjs"); const { spokenRead } = await import("umtool-report-to-video/post-redact"); const red = await projectRedaction(project.dir, manifest); t = spokenRead(t, e ?? { id: null }, red, { voice: "skip" }).text.trim() || t; } return { text: t, from }; } /** Enough words to hear a voice by (and for its closeness to be scored: a two-word line is too little speech). */ export const AUDITION_MIN_WORDS = 8; /** The line an audition reads by default: the first of the character's own with enough words, else its longest. */ export function defaultLine(lines) { const words = (l) => l.text.split(/\s+/).filter(Boolean).length; return lines.find((l) => l.own && words(l) >= AUDITION_MIN_WORDS) ?? lines.find((l) => words(l) >= AUDITION_MIN_WORDS) ?? [...lines].sort((a, b) => words(b) - words(a))[0] ?? null; } /** The folder an audition is kept in: the project's, else the cast's own. */ export const auditionDirOf = (project, reportsRoot = REPORTS_ROOT) => project ? path.join(project.dir, ...AUDITION_DIR.split("/")) : path.join(/* turbopackIgnore: true */ reportsRoot, ".umtool", "cast", "auditions"); const fileThere = async (f) => !!(await stat(f).catch(() => null))?.isFile(); /** * Each candidate's record and file: `[{ ...candidate, key, file, rel, cached, meta }]`. A candidate may carry its own * `tuning` and `reading` (`umtool cast try`): they are in its key and its ask. */ export async function auditionPlan(dir, candidates, text, { relBase = AUDITION_DIR } = {}) { const out = []; for (const c of candidates) { const key = auditionKey(c.engine, c.voice, text, { tuning: c.tuning ?? null, reading: c.reading ?? 0 }); const file = path.join(dir, `${key}.wav`); const meta = await readFile(path.join(dir, `${key}.json`), "utf8").then((t) => JSON.parse(t), () => null); out.push({ ...c, key, file, rel: `${relBase}/${key}.wav`, cached: !!meta && (await fileThere(file)), meta }); } return out; } /** A sound brought to AUDITION_LUFS, 48 kHz mono (one loudnorm pass), `from` -> `to`; `from` removed when asked. */ export async function levelTo(from, to, { start = null, seconds = null } = {}) { const tmp = tmpPathFor(to, { ext: ".wav" }); await execFileP(FFMPEG(), [ "-nostdin", "-v", "error", "-y", ...(start !== null ? ["-ss", String(start)] : []), "-i", from, ...(seconds !== null ? ["-t", String(seconds)] : []), "-vn", "-af", `loudnorm=I=${AUDITION_LUFS}:TP=-2:LRA=11`, "-ar", "48000", "-ac", "1", "-c:a", "pcm_s16le", tmp, ], { maxBuffer: 1 << 24 }); await rename(tmp, to); } /** * SYNTHESIZE THE CANDIDATES not kept yet: each asked of the editor's tts op in turn (`ask`: askEditorTts's shape, the * tests' to stub), levelled, its record written. With an Orpheus candidate to make the transcription lane is held * while they are asked (only when it was not held; released after -- `lanes`, renderMode.mjs editorLanes' shape, or * null: none; `hold: false` leaves it alone). Returns the plan with `fresh` and the editor's `jobs`. */ export async function synthesizeAuditions(dir, plan, text, { ask = null, editor = null, emit = () => {}, hold = true, lanes: lanes0 = undefined } = {}) { await mkdir(dir, { recursive: true }); const todo = plan.filter((c) => !c.cached); const jobs = []; let release = async () => {}; if (hold && todo.some((c) => c.engine === "orpheus")) { let lanes = lanes0; if (lanes === undefined) { const { editorLanes } = await import("./renderMode.mjs"); const { editorConfig } = await import("./fetchWindows.mjs"); lanes = editorLanes(editorConfig(process.env)); } try { if (lanes && !(await lanes.isHeld("transcription"))) { await lanes.hold("transcription"); emit("note", { message: "the transcription lane: held while Orpheus reads, released after" }); release = async () => { await lanes.release("transcription").catch((err) => emit("note", { message: `the transcription lane could NOT be released (${err?.message ?? err}): pnpm ops lane --json '{"lane":"transcription","held":false}'` })); }; } } catch (err) { emit("note", { message: `the transcription lane: not held (${err instanceof Error ? err.message : err})` }); } } try { const via = await import("umtool-report-to-video/narrate-via-editor"); const askTts = ask ?? via.askEditorTts; const { opWaitOf } = via; for (const [n, c] of todo.entries()) { emit("audition", { phase: "ask", n: n + 1, of: todo.length, voice: c.spec, weight: c.weight }); emit("note", { message: `${c.spec}${c.weight === "heavy" ? " (heavy: Orpheus)" : ""}: asking the editor (${n + 1}/${todo.length})…` }); const raw = path.join(dir, `${c.key}.raw.wav`); let res; // A tuned candidate's tuning and reading are asked; an untuned one's ask is the one it always was. const tuning = normalizeTtsTuning(c.tuning ?? null, { takes: ORPHEUS_DEFAULT_TAKES }); const reading = Number.isInteger(c.reading) && c.reading > 0 ? c.reading : 0; let waitSaid = false; // While render mode holds the machine, an Orpheus job waits at the heavy slot: said once, in the job's log. const onState = (st) => { const w = opWaitOf(st); if (waitSaid || w.state !== "slot" || !/render/i.test(String(w.line ?? ""))) return; waitSaid = true; emit("note", { message: `${c.spec}: waiting for the render -- render mode holds the machine; the read is made when it lets go (${w.line})` }); emit("audition", { phase: "waiting", for: "render", voice: c.spec, line: w.line }); }; try { res = await askTts({ text, engine: c.engine, voice: c.voice, out: raw, ...(Object.keys(tuning).length ? { tuning } : {}), ...(reading ? { reading } : {}) }, { ...(editor ? { editor } : {}), emit, onState }); } catch (err) { throw new AuditionError(`${c.spec} was not synthesized: ${err instanceof Error ? err.message : err} -- the candidates made are kept; run it again`); } if (!(await fileThere(raw))) throw new AuditionError(`the editor's job ${res?.jobId ?? "?"} finished but ${c.key}.raw.wav is not there`); await levelTo(raw, c.file); await rm(raw, { force: true }); const { measureTake, tunedOfResult } = await import("./postNarrationCli.mjs"); const m = await measureTake(c.file); if (typeof res?.result?.note === "string" && res.result.note) emit("note", { message: `${c.spec}: ${res.result.note}` }); const meta = { key: c.key, engine: c.engine, voice: c.voice, text, seconds: m.seconds, lufs: m.lufs, at: new Date().toISOString(), ...(res?.jobId ? { jobId: res.jobId } : {}), ...(typeof res?.result?.disclosure === "string" ? { disclosure: res.result.disclosure } : {}), // What it was made with, as the editor reports it (Orpheus: every tuning value and the reading). ...tunedOfResult(res?.result), // A TUNED ask's (characterTuning.mjs: a try): what was asked, so a sweep tells it from a candidate's cache. ...(Object.keys(tuning).length || reading ? { asked: { tuning, reading } } : {}), }; await writeFile(path.join(dir, `${c.key}.json`), `${JSON.stringify(meta, null, 1)}\n`); c.meta = meta; c.cached = true; c.fresh = true; if (res?.jobId) jobs.push(res.jobId); } } finally { await release(); } return { plan, fresh: todo.length, jobs }; } // --------------------------------------------------------------------------- // The closeness to the real voice (speaker-check's arithmetic, on the candidates). // --------------------------------------------------------------------------- /** The project's audition scores (`{ rows: {} }` with none). */ export async function readAuditionScores(dir) { try { const j = JSON.parse(await readFile(path.join(dir, ...AUDITION_SCORES.split("/")), "utf8")); return j && typeof j.rows === "object" && j.rows ? j : { version: 1, rows: {} }; } catch { return { version: 1, rows: {} }; } } const slug = (s) => str(s).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "voice"; /** The reference excerpt's file for a speaker (relative to the project). */ export const referenceRelOf = (speaker) => `${AUDITION_DIR}/ref-${slug(speaker)}.wav`; /** * The project's REFERENCE for a character: the speakers.json voice it goes by (cast.mjs speakerFor: its `speakers`, * its name, its id, its handles), or null. */ export async function referenceFor(project, character) { const { readSpeakers } = await import("./speakerCheck.mjs"); const speakers = await readSpeakers(project.dir).catch(() => []); return speakerFor(character, speakers); } /** * SCORE THE CANDIDATES against the character's real voice in the project: one run of the speaker check's scorer * (common/lib/montage/speakerCheck.mjs runSpeakerCheck: TitaNet-small, local; the test kit's fake embedder under * VOICE_MATCH_*) with the candidates as the clips to check and the one reference voice, and an excerpt of that voice * kept to listen to. Returns `{ speaker, rows: { key: { score, ... } }, reference: rel | null, why? }`. */ export async function scoreAuditions(project, character, plan, { engineOpts = {}, emit = () => {} } = {}) { const speaker = await referenceFor(project, character); if (!speaker) return { speaker: null, rows: {}, reference: null, why: `no reference voice for ${character?.name ?? character?.id ?? "it"} in ${project.id}'s speakers.json (umtool speaker-check ${project.id} --set 'Name=,/')` }; const { readManifest, channelsDirFor, hasShadowChannels } = await import("../projects/report.mjs"); const { planSpeakerCheck } = await import("./speakerCheck.mjs"); const { runSpeakerCheck } = await import("yt-dlp-transcript-common/lib/montage/speakerCheck.mjs"); const { DEFAULT_THRESHOLDS, resolveEngine } = await import("yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"); const { REPO_ROOT } = await import("../paths.mjs"); const manifest = await readManifest(project.dir); if (!manifest) throw new AuditionError(`${project.id} has no manifest`); const channelsDir = channelsDirFor(project.dir, manifest, { shadowExists: await hasShadowChannels(project.dir) }); const ref = await planSpeakerCheck(project.dir, manifest, { clipIds: [], channelsDir, speakers: [speaker] }); const voice = ref.voices[0]; // The excerpt to listen to: the first piece of the reference set. const firstClip = voice?.clipKeys?.map((k) => ref.clips.find((c) => c.key === k)).find((c) => c?.file) ?? null; const firstItem = voice?.items?.[0] ?? null; const src = firstClip ? { file: firstClip.file, start: firstClip.start, dur: firstClip.dur } : firstItem ? { file: firstItem.file, start: firstItem.start, dur: firstItem.dur } : null; let reference = null; if (src) { const rel = referenceRelOf(speaker.name); const abs = path.join(project.dir, ...rel.split("/")); await mkdir(path.dirname(abs), { recursive: true }); try { await levelTo(src.file, abs, { start: Math.max(0, src.start), seconds: Math.min(REFERENCE_SECONDS, Math.max(1, src.dur)) }); reference = rel; } catch (err) { emit("note", { message: `the reference excerpt was not made: ${err instanceof Error ? err.message : err}` }); } } const made = plan.filter((c) => c.cached && c.meta?.seconds > 0); if (!made.length) return { speaker: speaker.name, rows: {}, reference, why: "no candidate to score (synthesize them first)" }; let settings = null; try { settings = JSON.parse(await readFile(process.env.SETTINGS_FILE ?? path.join(/* turbopackIgnore: true */ REPO_ROOT, "settings.json"), "utf8")); } catch { settings = null; } const engine = resolveEngine({ repoRoot: REPO_ROOT, settings, ...engineOpts }); emit("audition", { phase: "score", n: made.length, speaker: speaker.name }); const clips = [ ...ref.clips.map((c) => (c.file ? { key: c.key, id: c.id, file: c.file, start: c.start, dur: c.dur, fallback: c.fallback ?? null } : { key: c.key, id: c.id, file: null, start: 0, dur: 0, missing: c.missing })), ...made.map((c) => ({ key: `audition:${c.key}`, id: null, file: c.file, start: 0, dur: c.meta.seconds })), ]; const doc = await runSpeakerCheck({ clips, check: made.map((c) => `audition:${c.key}`), speakers: ref.voices, engine, scratch: path.join(/* turbopackIgnore: true */ project.dir, ".cast-audition-work"), thresholds: DEFAULT_THRESHOLDS, }); const scores = await readAuditionScores(project.dir); const rows = {}; const at = new Date().toISOString(); for (const c of made) { const row = /** @type {any} */ (doc.clips[`audition:${c.key}`]); const s = row?.scores?.[0]; rows[c.key] = s ? { score: r3(s.score), speaker: speaker.name, at, model: doc.model } : { score: null, speaker: speaker.name, at, why: row?.why ?? "not scored" }; scores.rows[`${c.key}|${speaker.name}`] = rows[c.key]; } const file = path.join(project.dir, ...AUDITION_SCORES.split("/")); await mkdir(path.dirname(file), { recursive: true }); const tmp = tmpPathFor(file); await writeFile(tmp, `${JSON.stringify({ version: 1, rows: scores.rows }, null, 1)}\n`); await rename(tmp, file); return { speaker: speaker.name, rows, reference, pieces: doc.speakers?.[0]?.kept ?? null }; } /** * WHAT AN AUDITION HOLDS NOW, for the panel (nothing asked, nothing written): the character, the line, each candidate * `{ spec, engine, voice, weight, key, rel, cached, seconds, lufs, score }`, the real voice it is scored against and * the reference excerpt (when made). * @param {{ id: string, dir: string }} project * @param {any} cast * @param {string} who * @param {{ voices?: string[], text?: string | null, item?: string | null, line?: string | null }} [o] */ export async function auditionView(project, cast, who, { voices = [], text = null, item = null, line = null } = {}) { const { readManifest } = await import("../projects/report.mjs"); const manifest = await readManifest(project.dir); const character = await auditionCharacter(cast, who, { project, manifest }); const said = await auditionLine(project, manifest, character, { text, item, line }); const plan = await auditionPlan(auditionDirOf(project), voices.length ? candidatesOf(voices) : [], said.text); const speaker = (await referenceFor(project, character))?.name ?? null; const scores = await readAuditionScores(project.dir); const reference = speaker && (await fileThere(path.join(project.dir, ...referenceRelOf(speaker).split("/")))) ? referenceRelOf(speaker) : null; return { character: { id: character.id, name: character.name, handles: character.handles ?? [], voice: character.voice ?? null }, text: said.text, from: said.from, speaker, reference, candidates: plan.map((c) => ({ spec: c.spec, engine: c.engine, voice: c.voice, weight: c.weight, key: c.key, rel: c.rel, cached: c.cached, seconds: c.meta?.seconds ?? null, lufs: c.meta?.lufs ?? null, score: speaker ? scores.rows[`${c.key}|${speaker}`]?.score ?? null : null, })), }; } /** What an audition's scoring declares to the heavy slot (speaker-check's: TitaNet-small on a few seconds each). */ export const AUDITION_SCORE_ESTIMATE_MB = 800; /** * THE PANEL's AUDITION AS A JOB (lib/jobs.ts): step 1 asks the editor for the candidates not kept (its tts queue * arbitrates the GPU and the heavy slot -- this step takes no slot of its own, or an Orpheus job behind it would * wait on it); step 2, when the project has the character's real voice, scores them through the machine's heavy * slot with its estimate (after a render the operator is waiting for), nice'd. * @param {{ id: string }} project * @param {{ who: string, voices: string[], text?: string | null, item?: string | null, score?: boolean, umtoolDir: string, queueLock?: string | null }} o */ export function auditionSteps(project, { who, voices, text = null, item = null, score = true, umtoolDir, queueLock = null }) { const cli = path.join(/* turbopackIgnore: true */ umtoolDir, "bin", "umtool.mjs"); const base = ["cast", "audition", who, "--project", project.id, "--voices", voices.join(","), ...(text ? ["--text", text] : item ? ["--item", item] : [])]; const cwd = path.join(/* turbopackIgnore: true */ umtoolDir, ".."); const steps = [{ label: `synthesize ${voices.length} candidate voice(s) (the editor's tts)`, argv: [process.execPath, cli, ...base, "--no-score", "--progress", "ndjson"], cwd, env: {}, ndjson: /** @type {const} */ (true), timeoutMs: 45 * 60 * 1000, }]; if (score) { const cmd = ["nice", "-n", "10", process.execPath, cli, ...base, "--score-only", "--progress", "ndjson"]; steps.push({ label: "score each against the real voice (TitaNet, local)", argv: queueLock ? [process.execPath, queueLock, "--heavy", "--estimate", String(AUDITION_SCORE_ESTIMATE_MB), "--", ...cmd] : cmd, cwd, env: {}, ndjson: /** @type {const} */ (true), timeoutMs: 20 * 60 * 1000, }); } return { kind: `cast-audition ${project.id}`, steps }; }