// The cast across projects (castStore.mjs, castCli.mjs, castProject.mjs, castAudition.mjs): its one writer (a token, // undo points, a broken file never overwritten), the CLI, a project's characters and their drift, `use` (the // project's map or the cast) and the re-reads it asks for, every read agreeing (a single take and a thread read // through the cast, a cast voice of another engine synthesized by it), an audition (cached, levelled, scored for // closeness to the real voice with the test kit's fake embedder), a recording made a character's read, and the // lint's guard. No editor: the tts and voice ops are stubs; every project is a temp dir. import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises"; import { existsSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { after, test } from "node:test"; import { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"; import { VOICE_A, VOICE_B, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"; import { CastError, castFile, castWrite, readCast, readCastFile, undoCast } from "./castStore.mjs"; import { castCommand } from "./castCli.mjs"; import { rereadPlan, threadArgvOf } from "./castProject.mjs"; import { auditionKey, candidatesOf, characterLines, STOCK_LINE } from "./castAudition.mjs"; import { makeTake, importRecording } from "./postNarrationCli.mjs"; import { threadReadPlan, threadTake } from "./postThreadRead.mjs"; import { castProblems } from "./lintCli.mjs"; import { castVoiceMap } from "umtool-report-to-video/cast"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-cast-")); after(() => rm(ROOT, { recursive: true, force: true })); const FAKE_EMBED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "common", "testing", "audio", "fakeSpeakerEmbed.mjs"); process.env.VOICE_MATCH_PYTHON = process.execPath; process.env.VOICE_MATCH_SCRIPT = FAKE_EMBED; process.env.VOICE_MATCH_MODEL = "fake.onnx"; // ffmpeg with no stdin and a time limit, killed outright (a looping ffmpeg ignores SIGTERM, and execFileSync then waits // for it for good): a hang is a failure, not a stuck suite. const ff = (args) => execFileSync("ffmpeg", ["-nostdin", "-v", "error", "-y", ...args], { stdio: ["ignore", "pipe", "pipe"], timeout: 60_000, killSignal: "SIGKILL" }); const wavOf = async (file, voice, seconds = 2.5, { before = 0.3, after = 0.3 } = {}) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...voice, seconds }), { before, after }))); }; const io = () => { const lines = []; return { lines, opts: { reportsRoot: ROOT, log: (s) => lines.push(s), err: (s) => lines.push(s) }, text: () => lines.join("\n"), json: () => JSON.parse(lines.join("\n")) }; }; const cast = async (args, extra = {}) => { const o = io(); const code = await castCommand(args, { ...o.opts, ...extra }); return { code, ...o }; }; /** A tts stub: `out` written as VOICE_A for am_michael and zac, VOICE_B for any other. */ const stubAsk = (asked) => async (body) => { asked.push(body); await wavOf(body.out, ["am_michael", "zac"].includes(body.voice) ? VOICE_A : VOICE_B, 1.5); return { jobId: `job-${asked.length}`, result: { wav: body.out, engine: body.engine, voice: body.voice, disclosure: `Narration: synthetic voice (${body.engine} · ${body.voice})` } }; }; // THE PROJECT: two clips of "Host" (VOICE_A, the real voice), post items by @hostman (two, one a thread answering // @guest), and the guest's own item. const DIR = path.join(ROOT, "voices"); const CH = path.join(ROOT, "channels"); { const timeline = []; for (const id of ["k01", "k02"]) { const d = path.join(CH, "chan", "data", `v${id}`); await mkdir(path.join(d, "clips"), { recursive: true }); await writeFile(path.join(d, "transcript.cues.json"), JSON.stringify({ id: `v${id}`, cues: [{ start: 102.5, end: 104, text: "slow news day" }] })); // The window's audio: 2 s more silence before (adelay 2000) and 3.5 s more after (apad) than a plain voice, // written into the wav itself so the encode needs no filter chain. await wavOf(path.join(d, "clips", "x.wav"), VOICE_A, 2.5, { before: 2.3, after: 3.8 }); // At 48 kHz and a stated bitrate: ffmpeg 9.1's own AAC encoder (its default coder, no bitrate given) never // finishes on this 16 kHz mono synthetic voice (it wrote a 44-byte file and looped for days, 21-25 Nov 2026). ff(["-i", path.join(d, "clips", "x.wav"), "-ar", "48000", "-c:a", "aac", "-b:a", "128k", path.join(d, "clips", "100.00-108.00.mp4")]); await rm(path.join(d, "clips", "x.wav")); timeline.push({ type: "clip", id, channel: "chan", video: `v${id}`, start: 100, end: 108, cutStart: 102.5, cutEnd: 104, cite: 102.5, quote: "slow news day" }); } const post = (id, handle, o = {}) => ({ type: "post", id: `p-${id}`, post: `hostx/${id}`, platform: "x", author: handle === "hostman" ? "Host Man" : "The Guest", handle, date: `2026-10-30T1${id}:00:00.000Z`, text: `words of ${id} from ${handle}.`, ...o }); timeline.push( post("1", "hostman", { narration: { script: "Host's first line, read aloud.", takes: [{ file: "narration/posts/1/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 1.5, script: "Host's first line, read aloud." }], pick: 0 } }), post("2", "hostman", { parents: [{ id: "20", handle: "guest", author: "The Guest", date: "2026-10-30T09:00:00.000Z", text: "the guest asks a question" }], narration: { script: "Host answers the guest." } }), post("3", "guest", { narration: { script: "The guest's own line." } }), ); await mkdir(DIR, { recursive: true }); await writeFile(path.join(DIR, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: "voices", title: "Voices", provenance: { channelsDir: "../channels", channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30, palette: { bg: "#000000", fg: "#ffffff", muted: "#888888", accent: "#c8752a" } }, timeline, }, null, 2)); await wavOf(path.join(DIR, "narration", "posts", "1", "take-1.orpheus-zac.wav"), VOICE_A, 1.5); await writeFile(path.join(DIR, "speakers.json"), JSON.stringify({ speakers: [{ name: "Host", clips: ["k01", "k02"] }] })); } const project = { id: "voices", dir: DIR }; const manifest = async () => JSON.parse(await readFile(path.join(DIR, "video.manifest.json"), "utf8")); test("the store: one writer, a stale token refused, undo points, a broken file never overwritten", async () => { const file = path.join(ROOT, "store", ".umtool", "cast.json"); const r0 = await readCastFile(file); assert.equal(r0.exists, false); const a = await castWrite(file, (chars) => chars.push({ id: "a", name: "A", handles: ["a"], voice: "kokoro:am_adam" }), { what: "add a" }); await assert.rejects(castWrite(file, (chars) => chars.push({ id: "b", name: "B", handles: [], voice: "kokoro:am_echo" }), { token: "stale" }), (e) => e instanceof CastError && e.status === 409); await castWrite(file, (chars) => { chars[0].voice = "orpheus:zac"; }, { token: a.token, what: "a reads zac" }); await assert.rejects(castWrite(file, (chars) => { chars[0].voice = "/tmp/me.wav"; }), /STOCK voice/); assert.equal((await readCastFile(file)).cast.characters[0].voice, "orpheus:zac"); const u = await undoCast(file); assert.equal(u.undone, "a reads zac"); assert.equal((await readCastFile(file)).cast.characters[0].voice, "kokoro:am_adam"); await undoCast(file); assert.deepEqual((await readCastFile(file)).cast.characters, []); await assert.rejects(undoCast(file), /nothing to undo/); await writeFile(file, "{ not json"); const broken = await readCastFile(file); assert.match(broken.error, /not JSON/); await assert.rejects(castWrite(file, () => {}), /fix the file first/); assert.equal(await readFile(file, "utf8"), "{ not json"); }); test("umtool cast ls/add/set/rm/undo: the characters across projects", async () => { let r = await cast(["add", "hostman", "--name", "Host Man", "--voice", "orpheus:zac", "--handles", "@HostMan", "--speakers", "Host", "--json"]); assert.equal(r.code, 0, r.text()); // A character as the CLI says it: version 2's presets, and the `voice` (and `convert`) they answer to. assert.deepEqual(r.json().character, { id: "hostman", name: "Host Man", handles: ["hostman"], synthetic: { voice: "orpheus:zac" }, speakers: ["Host"], voice: "orpheus:zac" }); r = await cast(["add", "hostman", "--name", "Again", "--voice", "orpheus:zac"]); assert.equal(r.code, 1); assert.match(r.text(), /in the cast already/); r = await cast(["add", "me", "--name", "Me", "--voice", "seedvc:/home/me.wav"]); assert.equal(r.code, 1); assert.match(r.text(), /STOCK voice/); r = await cast(["add", "me", "--name", "Me", "--voice", "kokoro:bm_george", "--narrator", "--convert-engine", "seed-vc"]); assert.equal(r.code, 0, r.text()); r = await cast(["set", "me", "--note", "the operator", "--add-handle", "operator"]); assert.equal(r.code, 0, r.text()); r = await cast(["ls", "--json"]); assert.deepEqual(r.json().characters.map((c) => [c.id, c.voice, c.handles.join(",")]), [["hostman", "orpheus:zac", "hostman"], ["me", "kokoro:bm_george", "operator"]]); assert.equal(r.json().characters[1].narrator, true); // The pitch a converted read lands on: laid over the convert entry, what makes no sense refused. r = await cast(["set", "me", "--convert-pitch", "contour", "--convert-semitones", "2", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual(r.json().character.convert, { engine: "seed-vc", pitch: "contour", semitones: 2 }); r = await cast(["set", "me", "--convert-voice", "kokoro:af_bella", "--json"]); assert.deepEqual(r.json().character.convert, { engine: "seed-vc", pitch: "contour", semitones: 2, voice: "kokoro:af_bella" }, "the other keys kept"); r = await cast(["ls"]); assert.match(r.text(), /convert: seed-vc -> kokoro:af_bella, pitch contour \+2 st/); r = await cast(["set", "me", "--convert-pitch", "target", "--json"]); assert.deepEqual(r.json().character.convert, { engine: "seed-vc", pitch: "target", voice: "kokoro:af_bella" }, "the target's own pitch drops the semitones"); for (const [args, re] of [ [["--convert-pitch", "high"], /--convert-pitch is one of target, source, contour/], [["--convert-semitones", "13"], /--convert-semitones is a number from -12 to 12/], [["--convert-semitones", "2"], /semitones moves a followed pitch/], [["--convert-engine", "openvoice", "--convert-pitch", "source"], /pitch "source" is seed-vc's: openvoice lands every read on the target's own pitch/], ]) { r = await cast(["set", "me", ...args]); assert.equal(r.code, 1, args.join(" ")); assert.match(r.text(), re); } assert.deepEqual((await readCast(ROOT)).cast.characters[1].convert, { engine: "seed-vc", pitch: "target", voice: "kokoro:af_bella" }, "a refusal writes nothing"); r = await cast(["set", "me", "--no-convert"]); r = await cast(["set", "me", "--convert-engine", "seed-vc"]); assert.equal(r.code, 0, r.text()); r = await cast(["rm", "me"]); assert.equal(r.code, 0); r = await cast(["undo"]); assert.match(r.text(), /undone: rm me/); assert.equal((await readCast(ROOT)).cast.characters.length, 2); assert.equal(castFile(ROOT), path.join(ROOT, ".umtool", "cast.json")); }); test("every read agrees: a single take and a thread read ask the same layers -- a cast voice of another engine is that engine's", async () => { const m = await manifest(); const asked = []; // The cast says hostman reads zac (orpheus); the project's map nothing: his single take is zac. const e1 = m.timeline.find((e) => e.id === "p-1"); const t1 = await makeTake(project, e1, { render: m.render, ask: stubAsk(asked), redaction: null }); assert.deepEqual([t1.take.engine, t1.take.voice], ["orpheus", "zac"]); // The cast moves him to Kokoro: the next single take, and his piece of a thread read, are Kokoro's. await castWrite(castFile(ROOT), (chars) => { chars.find((c) => c.id === "hostman").voice = "kokoro:am_michael"; }); const e1b = (await manifest()).timeline.find((e) => e.id === "p-1"); const t2 = await makeTake(project, e1b, { render: m.render, ask: stubAsk(asked), redaction: null }); assert.deepEqual([t2.take.engine, t2.take.voice], ["kokoro", "am_michael"]); assert.match(t2.take.file, /take-\d+\.kokoro-am_michael\.wav$/); const e2 = m.timeline.find((e) => e.id === "p-2"); const castMap = castVoiceMap((await readCast(ROOT)).cast); const plan = threadReadPlan(m, e2, { cast: castMap, map: { guest: "tara" } }); assert.deepEqual(plan.pieces.map((p) => [p.role, p.engine, p.voice, p.from]), [["parent:0", "orpheus", "tara", "project"], ["post", "kokoro", "am_michael", "cast"]]); assert.equal(plan.engine, "kokoro", "the read's engine is his piece's"); asked.length = 0; const r = await threadTake(project, e2, { manifest: m, red: null, map: { guest: "tara" }, ask: stubAsk(asked), lanes: null }); assert.deepEqual(asked.map((b) => [b.engine, b.voice]), [["orpheus", "tara"], ["kokoro", "am_michael"]], "each part asked of its own engine"); assert.deepEqual(r.take.parts.map((p) => [p.role, p.engine, p.voice]), [["parent:0", "orpheus", "tara"], ["post", "kokoro", "am_michael"]]); const { postNarrationDisclosure } = await import("umtool-report-to-video/post-narration"); const after = (await manifest()).timeline.find((e) => e.id === "p-2"); assert.equal(postNarrationDisclosure(after), "Narration: synthetic voices (Orpheus · tara; Kokoro-82M · am_michael)"); // Up to date: the same read again asks nothing. const again = await threadTake(project, after, { red: null, map: { guest: "tara" }, ask: stubAsk(asked), lanes: null }); assert.equal(again.upToDate, true); }); test("cast project: each character's voice now and where it comes from, its drift, its reference; use and reread", async () => { // p-1's picked take is the latest (kokoro am_michael); pick the first (orpheus zac) again: drift. const { updatePostNarration, manifestToken } = await import("./manifest.mjs"); await updatePostNarration(DIR, "p-1", { pick: 0 }, { token: await manifestToken(DIR) }); let r = await cast(["project", "voices", "--json"]); assert.equal(r.code, 0, r.text()); const v = r.json(); const host = v.characters.find((c) => c.key === "hostman"); assert.equal(host.voice.spec, "kokoro:am_michael"); assert.equal(host.voice.from, "cast"); assert.equal(host.speaker, "Host"); assert.deepEqual([host.items, host.context], [2, 0]); assert.deepEqual(host.drift.map((d) => [d.id, d.reads, d.want]), [["p-1", "orpheus:zac", "kokoro:am_michael"]]); assert.ok(host.lines.some((l) => l.text === "Host's first line, read aloud.")); const guest = v.characters.find((c) => c.key === "@guest"); assert.deepEqual([guest.items, guest.context, guest.voice.from], [1, 1, "narrator"]); assert.equal(guest.contextVoice.spec, "orpheus:leo"); // The lint's guard: the drift a warning, nothing overridden yet. let g = await castProblems(await manifest(), project, ROOT); assert.equal(g.warnings.length, 1); assert.match(g.warnings[0], /@hostman \(hostman\) reads in orpheus:zac -- now kokoro:am_michael \(the cast\): umtool cast reread voices hostman/); // use, for this project: the map; the re-reads it asks for. r = await cast(["use", "voices", "@guest", "orpheus:leah", "--json"]); assert.equal(r.code, 0, r.text()); assert.equal(r.json().scope, "project"); assert.deepEqual(JSON.parse(await readFile(path.join(DIR, "narration", "voices.json"), "utf8")), { guest: "orpheus:leah" }); assert.deepEqual(r.json().reread.map((x) => x.id), ["p-2"], "the thread read says the guest in tara"); assert.deepEqual(r.json().reread[0].argv, ["posts", "narrate", "voices", "p-2", "--take", "--thread"]); // A project override of a cast voice is a note, not a warning. r = await cast(["use", "voices", "hostman", "kokoro:am_onyx", "--json"]); g = await castProblems(await manifest(), project, ROOT); assert.equal(g.notes.length, 1); assert.match(g.notes[0], /@hostman \(hostman\) reads in kokoro:am_onyx in this project -- the cast says kokoro:am_michael \(an override on purpose/); // --everywhere: the cast, and the project's own override goes. r = await cast(["use", "voices", "hostman", "kokoro:am_michael", "--everywhere", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual(r.json().removed, ["hostman"]); assert.deepEqual(JSON.parse(await readFile(path.join(DIR, "narration", "voices.json"), "utf8")), { guest: "orpheus:leah" }); assert.deepEqual(r.json().reread.map((x) => x.id), ["p-1"]); // --everywhere for an author the cast does not know: a new character from the handle. r = await cast(["use", "voices", "@guest", "kokoro:af_heart", "--everywhere", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual((await readCast(ROOT)).cast.characters.find((c) => c.id === "guest"), { id: "guest", name: "The Guest", handles: ["guest"], synthetic: { voice: "kokoro:af_heart" }, voice: "kokoro:af_heart" }); // reread --dry-run lists; reread makes them (the stub editor is not here: the plan alone). r = await cast(["reread", "voices", "hostman", "--dry-run", "--json"]); assert.deepEqual(r.json().items.map((x) => x.argv.join(" ")), ["posts narrate voices p-1 --take"]); }); test("rereadPlan: a thread read's own options kept, the changed author's overrides dropped; a conversion is skipped", () => { assert.deepEqual(threadArgvOf({ kind: "thread", parents: "all", skip: ["5"], quoted: false, voiceFor: { guest: "dan", other: "leo" }, voice: "zac" }, { handles: ["guest"], author: "hostman" }), ["--parents", "all", "--skip-parent", "5", "--no-quoted", "--voice-for", "other=leo", "--voice", "zac"]); assert.deepEqual(threadArgvOf({ kind: "thread", voice: "zac" }, { handles: ["hostman"], author: "HostMan" }), []); const m = { timeline: [{ type: "post", id: "p-9", handle: "x", narration: { takes: [{ file: "a.wav", read: { kind: "thread", parents: "1" } }], pick: 0 } }] }; const plan = rereadPlan("p", m, [{ id: "p-9", handle: "x", role: "post", reads: "orpheus:zac", want: "kokoro:am_michael", kind: "tts", thread: true }, { id: "p-8", handle: "x", role: "post", kind: "converted", thread: false }], ["x"]); assert.deepEqual(plan.items[0].argv, ["posts", "narrate", "p", "p-9", "--take", "--thread", "--parents", "1"]); assert.equal(plan.skipped[0].id, "p-8"); }); test("rereadPlan: a single take's own tuning and reading are asked again (lane orpheus-tuning) -- its recorded takes always (lane line-rerun: the settings' default may not be 3); thread reads add nothing", () => { const made = (o) => ({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3, ...o }); const m = { timeline: [ { type: "post", id: "p-1", handle: "x", narration: { takes: [{ file: "a.wav", engine: "orpheus", voice: "zac", tuning: made({ temperature: 0.7 }), reading: 2 }], pick: 0 } }, { type: "post", id: "p-2", handle: "x", narration: { takes: [{ file: "b.wav", engine: "orpheus", voice: "zac", tuning: made({}), reading: 0 }], pick: 0 } }, { type: "post", id: "p-3", handle: "x", narration: { takes: [{ file: "c.wav", engine: "orpheus", voice: "zac", speed: 1.2, speedAsked: true, tuning: made({ top_k: 40, takes: 5 }), reading: 0 }], pick: 0 } }, { type: "post", id: "p-4", handle: "x", narration: { takes: [{ file: "d.wav", engine: "orpheus", voice: "zac", tuning: made({ temperature: 0.9 }), reading: 3, read: { kind: "thread" } }], pick: 0 } }, ] }; const drift = (id, thread = false) => ({ id, handle: "x", role: "post", reads: "orpheus:zac", want: "orpheus:leah", kind: "tts", thread }); const plan = rereadPlan("p", m, [drift("p-1"), drift("p-2"), drift("p-3"), drift("p-4", true)], ["x"]); assert.deepEqual(plan.items.map((x) => x.argv.slice(4)), [ ["--take", "--reading", "2", "--temperature", "0.7", "--chunk-takes", "3"], ["--take", "--chunk-takes", "3"], ["--take", "--speed", "1.2", "--top-k", "40", "--chunk-takes", "5"], ["--take", "--thread"], ]); }); test("an audition: candidates checked, synthesized once, levelled, scored for closeness to the real voice", async () => { assert.throws(() => candidatesOf(["/home/me/voice.wav"]), /never a candidate/); assert.throws(() => candidatesOf(["a", "b", "c", "d", "e", "f", "g"].map((v) => `kokoro:${v}`)), /at most 6/); assert.deepEqual(candidatesOf(["kokoro:am_michael,orpheus:zac", "am_onyx"]).map((c) => [c.spec, c.weight]), [["kokoro:am_michael", "fast"], ["orpheus:zac", "heavy"], ["kokoro:am_onyx", "fast"]]); assert.deepEqual(characterLines(await manifest(), ["hostman"]).map((l) => l.item), ["p-1", "p-2"]); const asked = []; let r = await cast(["audition", "hostman", "--project", "voices", "--voices", "kokoro:am_michael,kokoro:bm_george", "--json"], { ask: stubAsk(asked), lanes: null }); assert.equal(r.code, 0, r.text()); const a = r.json(); assert.equal(a.text, "Host's first line, read aloud."); assert.equal(a.from, "item:p-1"); assert.equal(a.speaker, "Host"); assert.equal(a.reference, "narration/auditions/ref-host.wav"); assert.ok(existsSync(path.join(DIR, "narration", "auditions", "ref-host.wav"))); const [mich, geo] = a.candidates; assert.equal(mich.key, auditionKey("kokoro", "am_michael", a.text)); assert.ok(mich.score > geo.score, `the candidate in the host's voice is closer (${mich.score} vs ${geo.score})`); for (const c of a.candidates) { assert.ok(existsSync(path.join(DIR, c.rel))); assert.ok(Math.abs(c.lufs - -20) < 2.5, `levelled to -20 LUFS (${c.lufs})`); } assert.equal(asked.length, 2); // Again: nothing asked, the scores kept. r = await cast(["audition", "hostman", "--project", "voices", "--voices", "kokoro:am_michael,kokoro:bm_george", "--no-score", "--json"], { ask: stubAsk(asked), lanes: null }); assert.equal(asked.length, 2, "a re-audition is a cache hit"); assert.equal(r.json().candidates[0].score, mich.score); // A stock line for a character with no line; an author not in the cast by @handle; nothing to score against. r = await cast(["audition", "@guest", "--project", "voices", "--voices", "kokoro:af_heart", "--text", "Hello there.", "--json"], { ask: stubAsk(asked), lanes: null }); assert.equal(r.code, 0, r.text()); assert.match(r.json().why, /no reference voice/); assert.equal(STOCK_LINE.length > 20, true); const files = await readdir(path.join(DIR, "narration", "auditions")); assert.ok(!files.some((f) => f.endsWith(".raw.wav")), "no raw file left behind"); }); test("a recording made a character's read: kept, cleaned (when the editor can), converted to its stock voice", async () => { const rec = path.join(ROOT, "my-read.wav"); await wavOf(rec, VOICE_B, 2); const askOp = async (route, body) => { if (route.endsWith("voice-enhance")) { const e = new Error("the editor has no engine for /api/ops/voice-enhance yet (not installed: DeepFilterNet)"); e.name = "OpNotInstalled"; throw e; } await wavOf(body.out, VOICE_A, 2); return { jobId: "conv-1", result: { engine: body.engine ?? "openvoice", voice: body.voice } }; }; const e = (await manifest()).timeline.find((x) => x.id === "p-3"); const r = await importRecording(project, e, rec, { ask: askOp }); assert.equal(r.character.id, "guest", "the post's author in the cast"); assert.deepEqual(r.takes.map((t) => t.step), ["recorded", "converted to kokoro:af_heart"]); assert.match(r.notes[0], /not cleaned: .*not installed/); const after = (await manifest()).timeline.find((x) => x.id === "p-3"); const picked = after.narration.takes[after.narration.pick]; assert.equal(picked.file, r.picked); assert.equal(picked.voice, "af_heart"); assert.deepEqual(picked.steps[0], { ...picked.steps[0], op: "convert", voice: "kokoro:af_heart" }); assert.equal(after.narration.takes[0].engine, "recorded", "the original kept"); assert.equal(r.disclosure, "Narration: voice converted to a synthetic voice (openvoice · kokoro:af_heart)"); await assert.rejects(importRecording(project, e, rec, { as: "nobody", ask: askOp }), /no such character/); assert.equal("pitch" in picked.steps[0], false, "no pitch asked, none recorded"); // THE PITCH: the character's own (its convert entry) goes to the editor, a flag for this read beats it, and the // step keeps what the editor says it ran. const bodies = []; const askPitch = async (route, body) => { if (route.endsWith("voice-enhance")) return askOp(route, body); bodies.push(body); await wavOf(body.out, VOICE_A, 2); return { jobId: `conv-${bodies.length + 1}`, result: { engine: body.engine ?? "openvoice", voice: body.voice, pitch: body.pitch ?? "target", ...(body.pitch && body.pitch !== "target" ? { semitones: body.semitones ?? 0 } : {}) } }; }; await castWrite(castFile(ROOT), (chars) => { const g = chars.find((c) => c.id === "guest"); g.convert = { ...(g.convert ?? {}), engine: "seed-vc", pitch: "contour", semitones: 2 }; return { changed: "updated" }; }, { what: "set guest's convert pitch" }); const own = await importRecording(project, (await manifest()).timeline.find((x) => x.id === "p-3"), rec, { ask: askPitch }); assert.deepEqual([bodies[0].engine, bodies[0].pitch, bodies[0].semitones], ["seed-vc", "contour", 2]); assert.equal(own.takes.at(-1).step, "converted to kokoro:af_heart (pitch: contour +2 st)"); let now = (await manifest()).timeline.find((x) => x.id === "p-3"); let step = now.narration.takes[now.narration.pick].steps[0]; assert.deepEqual([step.pitch, step.semitones], ["contour", 2]); await importRecording(project, now, rec, { pitch: "source", semitones: -1, ask: askPitch }); assert.deepEqual([bodies[1].pitch, bodies[1].semitones], ["source", -1]); // This read at the stock voice's own pitch: the character's semitones go with its pitch. const flat = await importRecording(project, (await manifest()).timeline.find((x) => x.id === "p-3"), rec, { pitch: "target", ask: askPitch }); assert.equal(bodies[2].pitch, "target"); assert.equal("semitones" in bodies[2], false); assert.equal(flat.takes.at(-1).step, "converted to kokoro:af_heart"); now = (await manifest()).timeline.find((x) => x.id === "p-3"); step = now.narration.takes[now.narration.pick].steps[0]; assert.equal("pitch" in step, false); assert.equal(own.disclosure, "Narration: voice converted to a synthetic voice (seed-vc · kokoro:af_heart)", "the disclosure line is what it was"); });