// postRevoice.mjs + audioSplice.mjs: ONE PHRASE OF AN APPROVED READ RE-VOICED -- // the ask parsed, the span found (#n, a target's words), the cut at the quietest // 10 ms near each boundary, the splice's length exact and its joins equal-power, // the loudness match, the new words timed from the piece's speech, everything // after moved on, the refusals; the take written (TTS stubbed: the parts cache or // a fake editor) and picked in ONE write, undoable; the CLI. import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { validatePostItem } from "umtool-report-to-video/post-item"; import { wordZoomTimes } from "umtool-report-to-video/word-zoom"; import { decodePcm, joinStepDb, matchGainDb, quietestCut, speechIslands, spliceEqualPower, wordsByValleys, writeWav16 } from "./audioSplice.mjs"; import { PauseError } from "./postPause.mjs"; import { RereadError } from "./postReread.mjs"; import { RevoiceError, parseRevoice, pieceWordTimes, replaceNth, revoiceFinish, revoicePlan, revoiceTake } from "./postRevoice.mjs"; import { PARTS_CACHE } from "./postThreadRead.mjs"; import { postsCommand } from "./postsCli.mjs"; import { undoStructural } from "./manifest.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-revoice-")); after(() => rm(ROOT, { recursive: true, force: true })); const REPORTS = path.join(ROOT, "reports"); const RATE = 24000; // "I'll give you 45 seconds. 20, 10, 4, 0. Alright." (part 1, zac) then "Who are you? 4 more." (part 2, leo). const TEXT = "I'll give you 45 seconds. 20, 10, 4, 0. Alright.\n\nWho are you? 4 more."; const words = () => [ { w: "I'll", start: 0.1, end: 0.3 }, { w: "give", start: 0.35, end: 0.55 }, { w: "you", start: 0.6, end: 0.7 }, { w: "45", start: 0.75, end: 1.2 }, { w: "seconds.", start: 1.25, end: 1.7 }, { w: "20,", start: 2.0, end: 2.3 }, { w: "10,", start: 2.4, end: 2.6 }, { w: "4,", start: 2.62, end: 2.8 }, { w: "0.", start: 3.1, end: 3.4 }, { w: "Alright.", start: 3.6, end: 4.0 }, { w: "Who", start: 4.6, end: 4.8 }, { w: "are", start: 4.85, end: 5.0 }, { w: "you?", start: 5.05, end: 5.3 }, { w: "4", start: 5.5, end: 5.7 }, { w: "more.", start: 5.75, end: 6.1 }, ]; const parts = () => [ { n: 1, para: 0, text: "I'll give you 45 seconds. 20, 10, 4, 0. Alright.", start: 0, seconds: 4.2, file: "narration/parts-cache/a.wav", role: "post", voice: "zac" }, { n: 2, para: 1, text: "Who are you? 4 more.", start: 4.5, seconds: 1.8, role: "post", voice: "leo" }, ]; const item = (o = {}) => ({ type: "post", id: "p-1", post: "subj-x/1", platform: "x", author: "THE SUBJECT", handle: "Subject", date: "2026-10-30T10:00:00.000Z", text: TEXT, narration: { script: TEXT, takes: [{ file: "narration/posts/1/take-2.orpheus-thread.wav", engine: "orpheus", voice: "leo+zac", seconds: 6.4, slurs: "said", script: TEXT, words: words(), parts: parts() }], pick: 0 }, ...o, }); const ASK = { match: "20 10 4 0", occurrence: 1, say: "20... 10... 4... 0..." }; /** A tone (amplitude `amp`) inside each span, near-silence elsewhere: a read whose words are where the timings say. */ function tones(seconds, spans, { amp = 0.2, freq = 220 } = {}) { const x = new Float32Array(Math.round(seconds * RATE)); for (let i = 0; i < x.length; i += 1) { const t = i / RATE; const on = spans.some(([a, b]) => t >= a && t < b); x[i] = (on ? amp : 0.0005) * Math.sin((2 * Math.PI * freq * i) / RATE); } return x; } test("a re-voice is asked at the speed its part was synthesized at (a character's preset's, the read's --speed); Orpheus has none", async () => { const { partKey } = await import("./postThreadRead.mjs"); const fast = (engine) => { const e = item(); const t = e.narration.takes[0]; t.engine = engine; t.parts[0].speed = 1.2; return e; }; const p = revoicePlan(fast("kokoro"), ASK); assert.equal(p.speed, 1.2); assert.equal(p.key, partKey("kokoro", p.voice, p.said, 1.2), "another speed is another cached part"); assert.notEqual(p.key, partKey("kokoro", p.voice, p.said)); // The second part has no speed of its own: asked as before. const q = revoicePlan(fast("kokoro"), { match: "4", occurrence: 2, say: "four" }); assert.equal(q.speed, undefined); assert.equal(q.key, partKey("kokoro", q.voice, q.said)); assert.equal(revoicePlan(fast("orpheus"), ASK).speed, undefined); }); test("THE ASK: the phrase and #n, --say, --voice (auto: the piece's own), --xfade 0-0.2 (default 0.03); the refusals are usage errors", () => { assert.deepEqual(parseRevoice({ phrase: "20 10 4 0", say: " 20... 10... " }), { match: "20 10 4 0", occurrence: 1, say: "20... 10...", voice: null, xfade: 0.03, cut: null }); assert.deepEqual(parseRevoice({ phrase: "4#2", say: "four", voice: "auto", xfade: "0.05" }), { match: "4", occurrence: 2, say: "four", voice: null, xfade: 0.05, cut: null }); // --splice: the cuts set by hand (either side), the take's seconds. assert.deepEqual(parseRevoice({ phrase: "4", say: "four", cut: "65.03-66" }).cut, { from: 65.03, to: 66 }); assert.deepEqual(parseRevoice({ phrase: "4", say: "four", cut: "-66.2" }).cut, { from: null, to: 66.2 }); for (const bad of ["x", "-", "3-2"]) assert.throws(() => parseRevoice({ phrase: "4", say: "four", cut: bad }), RereadError, bad); assert.equal(parseRevoice({ phrase: "4", say: "four", voice: "tara" }).voice, "tara"); for (const bad of [{ phrase: "", say: "x" }, { phrase: "20", say: "" }, { phrase: "20", say: "..." }, { phrase: "20#0", say: "x" }, { phrase: "20", say: "x", xfade: "0.5" }, { phrase: "20", say: "x", voice: "a/b" }, { phrase: "20", say: "x".repeat(401) }]) { assert.throws(() => parseRevoice(bad), RereadError, JSON.stringify(bad)); } }); test("THE SPAN: found as a pause finds a word (#n, a target's words); the boundaries in the quiet between words, each with a ±40 ms window; the voice the part was read in, the root take's engine", () => { const p = revoicePlan(item(), ASK); assert.deepEqual([p.first, p.last, p.phrase, p.part, p.voice, p.engine], [5, 8, "20, 10, 4, 0.", 0, "zac", "orpheus"]); assert.deepEqual(p.nominal, { from: 1.9, to: 3.5 }); assert.deepEqual(p.windows, { from: { lo: 1.86, hi: 1.94 }, to: { lo: 3.46, hi: 3.54 } }); // The wide windows (no quiet within 40 ms): 0.15 s, never inside the phrase as timed nor past the words about it. assert.deepEqual(p.wide, { from: { lo: 1.75, hi: 2 }, to: { lo: 3.4, hi: 3.65 } }); assert.match(p.key, /^[0-9a-f]{40}$/); assert.equal(revoicePlan(item(), { ...ASK, voice: "tara" }).voice, "tara"); assert.equal(revoicePlan(item(), { match: "4", occurrence: 2, say: "four" }).first, 13); // Run together (no quiet between): the boundary is the word's edge, the window never past either word's middle. const e = item(); e.narration.takes[0].words[7] = { w: "4,", start: 2.6, end: 2.8 }; assert.deepEqual(revoicePlan(e, { match: "4", say: "four" }).windows.from, { lo: 2.56, hi: 2.64 }); // A lexicon (the redaction's `say`): what the voice says, and its key. const red = { say: [{ word: "seconds", say: "secs" }] }; const q = revoicePlan(item(), { match: "45 seconds", say: "45 seconds", red }); assert.equal(q.said, "45 secs"); assert.notEqual(q.key, revoicePlan(item(), { match: "45 seconds", say: "45 seconds" }).key); }); test("THE REFUSALS (exit 1): no word timings names posts narrate --words; the phrase not read; across two parts; a recorded read", () => { const nw = item(); delete nw.narration.takes[0].words; assert.throws(() => revoicePlan(nw, ASK), (err) => err instanceof RevoiceError && /no word timings.*umtool posts narrate

p-1 --words/.test(err.message)); assert.throws(() => revoicePlan(item(), { ...ASK, match: "twenty" }), (err) => err instanceof PauseError && /--revoice "twenty": no such word/.test(err.message)); assert.throws(() => revoicePlan(item(), { ...ASK, match: "alright who" }), /runs across two parts/); const rec = item(); rec.narration.takes[0].engine = "recorded"; assert.throws(() => revoicePlan(rec, ASK), /RECORDED read/); assert.throws(() => revoicePlan(item(), { ...ASK, target: "quoted" }), /reads no quoted/); }); test("THE QUIET CUT on a synthetic signal: the lowest-energy 10 ms in the window, kept at the timing when nothing is clearly quieter", () => { // Speech 0-1 s, a 20 ms dip at 1.015-1.035, speech on. const x = tones(2, [[0, 1.015], [1.035, 2]]); const q = quietestCut(x, RATE, { lo: 0.96, hi: 1.04, nominal: 1 }); assert.equal(q.moved, true); assert.ok(Math.abs(q.at - 1.025) <= 0.006, `at ${q.at}`); assert.ok(q.rmsDb < q.nominalDb - 20, `${q.rmsDb} vs ${q.nominalDb}`); // A steady tone: no window clearly quieter -- the timing's own. assert.deepEqual([quietestCut(tones(2, [[0, 2]]), RATE, { lo: 0.96, hi: 1.04, nominal: 1 }).at, quietestCut(tones(2, [[0, 2]]), RATE, { lo: 0.96, hi: 1.04, nominal: 1 }).moved], [1, false]); }); test("TIMINGS OFF (the alignment late, the words run together): no quiet within 40 ms -- the cut found in the quiet up to 0.15 s off, never in a gap inside the phrase; still in speech, a warning naming --splice; --splice sets a cut", async () => { // The read's words sound 0.2 s EARLIER than timed; "0." runs on into "Alright." with no quiet. const e = item(); const p = await project("off", [e]); const shift = (w) => [w.start - 0.2, w.end - 0.2]; const spans = words().map(shift); spans[8] = [2.9, 3.6]; // "0." run into "Alright." await writeWav16(path.join(p.dir, "narration", "posts", "1", "take-2.orpheus-thread.wav"), tones(6.4, spans), RATE, 1); const r = await revoiceTake(p, e, { match: "20 10 4", say: "twenty ten four", red: null, dryRun: true }); // The start: the quiet before "20," (1.5-1.8 as sounded), not the gap between "20," and "10," (2.1-2.2, inside the phrase). assert.equal(r.cuts.how.from, "wide"); assert.ok(r.cuts.from >= 1.75 && r.cuts.from <= 1.8, `start ${r.cuts.from}`); assert.deepEqual(r.cuts.warnings, []); // The end: in the quiet between "4," (to 2.6) and "0." (from 2.9). assert.ok(r.cuts.to >= 2.6 && r.cuts.to <= 2.9, `end ${r.cuts.to} (${r.cuts.how.to})`); // "0." to "Alright." run together: the end in speech -- warned. const q = await revoiceTake(p, e, { match: "0", say: "zero", red: null, dryRun: true }); assert.equal(q.cuts.warnings.length, 1, JSON.stringify(q.cuts)); assert.match(q.cuts.warnings[0], /the cut at the end .* is in speech.*--splice -/); const set = await revoiceTake(p, e, { match: "0", say: "zero", red: null, dryRun: true, cut: { from: 2.95, to: 3.2 } }); assert.deepEqual([set.cuts.from, set.cuts.to, set.cuts.how.from, set.cuts.how.to, set.cuts.warnings.length], [2.95, 3.2, "set", "set", 0]); }); test("THE SPLICE: its length the source's - the span + the piece, exactly; equal-power joins (cos/sin), the source untouched outside them; the gain clamped to ±6 dB", () => { const src = new Float32Array(1000).fill(0.5); const piece = new Float32Array(300).fill(-0.5); const out = spliceEqualPower(src, piece, 1, 400, 600, 40); assert.equal(out.length, 1000 - 200 + 300); assert.equal(out[379], 0.5, "before the first join: the source"); assert.ok(Math.abs(out[400] - (0.5 * Math.cos(Math.PI / 4) - 0.5 * Math.sin(Math.PI / 4))) < 1e-6, "the join's middle: half power each"); assert.equal(out[500], -0.5, "the piece"); assert.equal(out[720], 0.5, "after the second join: the source from `to` on"); // Stereo: frames, not samples. assert.equal(spliceEqualPower(new Float32Array(2000), new Float32Array(600), 2, 400, 600, 40).length, (1000 - 200 + 300) * 2); assert.equal(matchGainDb(0.1, 0.05), 6); assert.equal(matchGainDb(0.01, 0.5), -6); assert.equal(matchGainDb(0.1, 0.1), 0); assert.equal(matchGainDb(null, 0.1), 0); }); test("THE NEW WORDS: one speech island a word when they count the same, else split at the piece's deepest valleys, else shared out by length; marked estimated", () => { const isl = speechIslands(tones(2, [[0.1, 0.3], [0.6, 0.8], [1.1, 1.3], [1.6, 1.8]]), RATE); assert.equal(isl.length, 4); assert.ok(Math.abs(isl[1].start - 0.6) <= 0.011 && Math.abs(isl[1].end - 0.8) <= 0.011, JSON.stringify(isl[1])); assert.deepEqual(pieceWordTimes(["a", "b"], 2, [{ start: 0.1, end: 0.5 }, { start: 1, end: 1.5 }]), [{ start: 0.1, end: 0.5 }, { start: 1, end: 1.5 }]); // A voice that draws its words out: two islands for four words -- split at the deepest valleys. const drawn = tones(2.4, [[0.1, 0.5], [0.6, 1.2], [1.4, 2.3]]); for (let i = Math.round(1.8 * RATE); i < Math.round(1.84 * RATE); i += 1) drawn[i] *= 0.05; const v = wordsByValleys(drawn, RATE, 4); assert.equal(v.length, 4); assert.deepEqual(v.map((x) => Math.round(x.end * 10) / 10), [0.5, 1.2, 1.8, 2.3]); assert.deepEqual(wordsByValleys(drawn, RATE, 1), [{ start: 0.1, end: 2.3 }], "one word: the speech's extent"); assert.equal(wordsByValleys(new Float32Array(RATE), RATE, 2), null, "no speech"); const spread = pieceWordTimes(["ab", "abcd"], 3, []); assert.deepEqual(spread.map((x) => [x.start, x.end]), [[0, 1], [1, 3]]); }); test("WHAT MOVES: the words after by the length change, the part holding it grows (its file dropped, its text and the script saying --say), later parts moved; a zoom stays on its word", () => { const e = item({ fx: [{ kind: "word-zoom", match: "Who" }] }); const p = revoicePlan(e, ASK); const f = revoiceFinish(p, { from: 1.9, to: 3.5, seconds: 2.4, islands: [{ start: 0.03, end: 0.3 }, { start: 0.7, end: 0.95 }, { start: 1.3, end: 1.5 }, { start: 1.9, end: 2.35 }], gain: 1.5 }); assert.equal(f.delta, 0.8); assert.equal(f.seconds, 7.2); assert.equal(f.words.length, 15); assert.deepEqual(f.words.slice(4, 10).map((w) => [w.w, w.start, w.end, w.estimated ?? false]), [["seconds.", 1.25, 1.7, false], ["20...", 1.93, 2.2, true], ["10...", 2.6, 2.85, true], ["4...", 3.2, 3.4, true], ["0...", 3.8, 4.25, true], ["Alright.", 4.4, 4.8, false]]); assert.deepEqual(f.parts.map((x) => [x.start, x.seconds, x.file ?? null, x.text]), [[0, 5, null, "I'll give you 45 seconds. 20... 10... 4... 0... Alright."], [5.3, 1.8, null, "Who are you? 4 more."]]); assert.equal(f.script, "I'll give you 45 seconds. 20... 10... 4... 0... Alright.\n\nWho are you? 4 more."); assert.equal(f.steps[0].op, "revoice"); assert.deepEqual(Object.keys(f.steps[0].revoice).sort(), ["count", "engine", "from", "gain", "key", "phrase", "said", "say", "seconds", "to", "voice", "word", "words", "xfade"]); const t = { file: "narration/posts/1/take-3.revoice-orpheus.wav", engine: "derived", voice: f.takeVoice, seconds: f.seconds, source: { kind: "take", from: "take-2.orpheus-thread" }, steps: f.steps, words: f.words, parts: f.parts, script: f.script }; const e2 = { ...e, narration: { ...e.narration, takes: [...e.narration.takes, t], pick: 1 } }; assert.deepEqual(validatePostItem(e2), []); assert.ok(Math.abs(wordZoomTimes(e2)[0].t - wordZoomTimes(e)[0].t - 0.8) < 0.01, "the zoom on Who moved with its word"); // The validator: a bad re-voice record, a word's estimated not true. const bad = { ...e2, narration: { ...e2.narration, takes: [e2.narration.takes[0], { ...t, steps: [{ op: "revoice", revoice: { word: 1, count: 0, from: 2, to: 1, seconds: 1, say: "x", voice: "zac" } }], words: [{ w: "a", start: 0, end: 1, estimated: false }] }] } }; const errs = validatePostItem(bad); assert.equal(errs.filter((x) => /revoice must be/.test(x)).length, 1, errs.join("\n")); assert.equal(errs.filter((x) => /words\[0\]/.test(x)).length, 1, errs.join("\n")); }); async function project(name, timeline) { const dir = path.join(REPORTS, name); await mkdir(path.join(dir, "narration", "posts", "1"), { recursive: true }); // The read: a tone in each word's span, near-silence between. await writeWav16(path.join(dir, "narration", "posts", "1", "take-2.orpheus-thread.wav"), tones(6.4, words().map((w) => [w.start, w.end])), RATE, 1); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "" }, render: { width: 1920, height: 1080, fps: 30 }, timeline }, null, 2)); return { id: name, dir }; } const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); /** The fake editor's voice: four bursts, 0.2 s of silence before them, quieter than the read (the gain brings it up). */ const fakeVoice = () => tones(2, [[0.2, 0.4], [0.7, 0.9], [1.2, 1.4], [1.7, 1.9]], { amp: 0.1, freq: 262 }); test("RE-VOICED: the editor asked for --say only (the part's voice, the engine), the piece cached, trimmed and gained; the take's length old - cut + piece, a derived take picked in ONE write, undoable", async () => { const p = await project("revoice", [item()]); const e = (await manifest(p)).timeline[0]; const asked = []; const ask = async (body) => { asked.push(body); await writeWav16(body.out, fakeVoice(), 48000 / 2, 1); return { jobId: "stub-1", result: { wav: body.out } }; }; const dry = await revoiceTake(p, e, { ...ASK, dryRun: true, ask, red: null }); assert.equal(asked.length, 0, "a dry run asks nothing"); assert.equal(dry.cached, false); assert.deepEqual([dry.cuts.from, dry.cuts.to], [1.9, 3.5]); const r = await revoiceTake(p, e, { ...ASK, ask, red: null }); assert.deepEqual(asked.map((b) => [b.text, b.engine, b.voice, path.relative(p.dir, b.out)]), [["20... 10... 4... 0...", "orpheus", "zac", `${PARTS_CACHE}/${r.plan.key}.wav`]]); assert.match(r.take.file, /^narration\/posts\/1\/take-3\.revoice-orpheus\.wav$/); // The piece trimmed to its speech (0.2-1.9 s) + 30 ms either side; gained up (the read is twice as loud), at most +6 dB. assert.ok(Math.abs(r.piece.seconds - 1.76) <= 0.02, `piece ${r.piece.seconds}`); assert.ok(r.piece.gain > 5 && r.piece.gain <= 6, `gain ${r.piece.gain}`); const pcm = await decodePcm(path.join(p.dir, r.take.file), { rate: RATE, channels: 1 }); const expect = Math.round(6.4 * RATE) - (Math.round(3.5 * RATE) - Math.round(1.9 * RATE)) + Math.round(r.piece.seconds * RATE); assert.ok(Math.abs(pcm.length - expect) <= 2, `${pcm.length} samples, want ${expect}`); // The joins land in quiet: no step there. assert.ok(joinStepDb(pcm, RATE, 1.9) < 3 && joinStepDb(pcm, RATE, 1.9 + r.piece.seconds) < 3); const now = (await manifest(p)).timeline[0]; assert.equal(now.narration.pick, 1); const t = now.narration.takes[1]; assert.deepEqual([t.engine, t.source, t.steps[0].op, t.slurs, t.voice], ["derived", { kind: "take", from: "take-2.orpheus-thread" }, "revoice", "said", "leo+zac"]); assert.deepEqual(t.words.slice(5, 9).map((w) => w.w), ["20...", "10...", "4...", "0..."]); assert.ok(t.words.slice(5, 9).every((w) => w.estimated === true)); assert.deepEqual(validatePostItem(now), []); // Asked again (the same words in the same voice): the parts cache has it -- the dry run knows its length, nothing asked. const again = await revoiceTake(p, e, { ...ASK, ask, red: null, dryRun: true }); assert.deepEqual([again.cached, asked.length, again.finish.delta], [true, 1, r.finish.delta]); await undoStructural(p.dir); assert.equal((await manifest(p)).timeline[0].narration.takes.length, 1, "undone"); }); test("A RE-VOICE AGAIN of the words a re-voice put in is cut from the take before it (one splice)", async () => { const p = await project("again", [item()]); const ask = async (body) => { await writeWav16(body.out, fakeVoice(), RATE, 1); return { jobId: "stub" }; }; await revoiceTake(p, (await manifest(p)).timeline[0], { ...ASK, ask, red: null }); const e = (await manifest(p)).timeline[0]; const r = await revoiceTake(p, e, { match: "20 10 4 0", say: "20, 10, 4, 0", ask, red: null, dryRun: true }); assert.equal(r.plan.recut, true); assert.equal(r.plan.take.file, "narration/posts/1/take-2.orpheus-thread.wav"); assert.deepEqual([r.plan.first, r.plan.last], [5, 8]); }); test("THE CLI: posts reread --revoice --say --dry-run writes nothing (no TTS), --json the plan; a piece in the parts cache is applied with no ask; the refusals' exits", async () => { const p = await project("cli", [item()]); const cli = async (args) => { const lines = []; const errs = []; const code = await postsCommand(args, { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); return { code, out: lines.join("\n"), err: errs.join("\n") }; }; const dry = await cli(["reread", "cli", "p-1", "--revoice", "20 10 4 0", "--say", "20... 10... 4... 0...", "--dry-run"]); assert.equal(dry.code, 0, dry.err); assert.match(dry.out, /would re-voice p-1's take \(take-2\.orpheus-thread\): "20, 10, 4, 0\." -- words 6-9, 2\.00-3\.40 s/); assert.match(dry.out, /cut 1\.900-3\.500 s/); assert.match(dry.out, /says "20\.\.\. 10\.\.\. 4\.\.\. 0\.\.\." in zac \(orpheus\), 0\.03 s equal-power crossfades/); assert.match(dry.out, /not synthesized yet/); assert.equal((await manifest(p)).timeline[0].narration.takes.length, 1, "a dry run writes nothing"); const js = JSON.parse((await cli(["reread", "cli", "p-1", "--revoice", "20 10 4 0", "--say", "20... 10... 4... 0...", "--dry-run", "--json"])).out); assert.deepEqual([js.ok, js.dryRun, js.span.first, js.span.last, js.voice, js.cached, js.change, js.take], [true, true, 5, 8, "zac", false, null, null]); // The piece put in the parts cache by hand (a read made it before): applied, nothing asked of an editor. await mkdir(path.join(p.dir, PARTS_CACHE), { recursive: true }); await writeWav16(path.join(p.dir, PARTS_CACHE, `${js.key}.wav`), fakeVoice(), RATE, 1); const dry2 = await cli(["reread", "cli", "p-1", "--revoice", "20 10 4 0", "--say", "20... 10... 4... 0...", "--dry-run"]); assert.match(dry2.out, /the new piece: 1\.7\d s, gain \+\d\.\d dB -- the take 6\.\d\d s \(was 6\.40 s, \+0\.1\d\d s\)/); const go = await cli(["reread", "cli", "p-1", "--revoice", "20 10 4 0", "--say", "20... 10... 4... 0..."]); assert.equal(go.code, 0, go.err); assert.match(go.out, /take-3\.revoice-orpheus\.wav -- picked/); assert.equal((await manifest(p)).timeline[0].narration.pick, 1); assert.equal((await cli(["reread", "cli", "p-1", "--revoice", "twenty", "--say", "x"])).code, 1, "not read: exit 1"); assert.equal((await cli(["reread", "cli", "p-1", "--revoice", "20"])).code, 2, "no --say: usage"); assert.equal((await cli(["reread", "cli", "p-1", "--say", "x"])).code, 2, "--say alone: usage"); assert.equal((await cli(["reread", "cli", "p-1", "--revoice", "20", "--say", "x", "--pause", "20=0.4"])).code, 2, "a re-voice goes alone"); assert.equal((await cli(["reread", "cli", "p-1", "--pause", "20=0.4", "--xfade", "0.1"])).code, 2, "--xfade goes with --revoice"); });