// DRIFT TRACKS SPEED (cast.mjs voiceDrift, castProject.mjs resolverFor) -- where a take SAYS where its speed came // from (`speedAsked` "preset" / "item"): a picked read synthesized at another speed than its character's preset asks // now is stale, as one in another voice is -- a single take by its `speed`, a thread read by each part's; the item's // own speed and a thread read's own --speed answer before the preset; Orpheus (no speed) and a converted recording // never drift by speed. A take that says nothing (made before the lane: unknown) is never speed drift, and a re-read // of it asks its own speed again. import assert from "node:assert/strict"; import { test } from "node:test"; import { projectCharacters, rereadPlan } from "./castProject.mjs"; const cast = (speed) => ({ format: "umtool-cast", version: 2, characters: [ { id: "host", name: "Host", handles: ["host"], synthetic: { voice: "kokoro:am_michael", ...(speed ? { speed } : {}) } }, { id: "guest", name: "Guest", handles: ["guest"], synthetic: { voice: "kokoro:bf_emma", speed: 0.9 } }, { id: "orph", name: "Orph", handles: ["orph"], synthetic: { voice: "orpheus:zac" } }, ], }); const single = (o = {}) => ({ file: "narration/posts/1/take-1.kokoro.wav", engine: "kokoro", voice: "am_michael", seconds: 2, script: "Hi.", speedAsked: "preset", ...o }); const post = (id, handle, narration, o = {}) => ({ type: "post", id, handle, author: handle, text: "words", narration, ...o }); const m = (...timeline) => ({ render: { postNarration: { engine: "kokoro", voice: "af_heart" } }, timeline }); const driftOf = (manifest, c) => projectCharacters(manifest, { cast: c }).characters.flatMap((x) => x.drift); test("a single take at another speed than the preset now is drift; at the same, or 1 against none, it is not", () => { const at11 = m(post("p1", "host", { takes: [single({ speed: 1.1 })], pick: 0 })); assert.deepEqual(driftOf(at11, cast(1.1)), []); const rows = driftOf(at11, cast(1.3)); assert.deepEqual(rows.map((r) => [r.id, r.role, r.reads, r.want, r.from]), [["p1", "post", "kokoro:am_michael ×1.1", "kokoro:am_michael ×1.3", "cast"]]); // A take with no speed against a preset that has one now: stale. None and 1 are one. assert.equal(driftOf(m(post("p1", "host", { takes: [single()], pick: 0 })), cast(1.2)).length, 1); assert.deepEqual(driftOf(m(post("p1", "host", { takes: [single({ speed: 1 })], pick: 0 })), cast(null)), []); // A changed voice reads as before (no speed said where none is). assert.deepEqual(driftOf(m(post("p1", "host", { takes: [single({ voice: "am_adam" })], pick: 0 })), cast(null)).map((r) => [r.reads, r.want]), [["kokoro:am_adam", "kokoro:am_michael"]]); // The item's own speed answers before the preset (as a new take would be asked). assert.deepEqual(driftOf(m(post("p1", "host", { speed: 1.1, takes: [single({ speed: 1.1 })], pick: 0 })), cast(1.3)), []); // The re-read it asks for. const plan = rereadPlan("p", at11, rows, ["host"]); assert.deepEqual(plan.items.map((x) => x.argv), [["posts", "narrate", "p", "p1", "--take"]]); }); test("a thread read's parts: each at its preset's speed now; the read's own --speed kept as asked; Orpheus never by speed", () => { const parts = (hostSpeed, guestSpeed) => [ { n: 1, role: "parent:0", voice: "bf_emma", engine: "kokoro", ...(guestSpeed ? { speed: guestSpeed } : {}), text: "q", file: "narration/parts-cache/a.wav", start: 0, seconds: 1 }, { n: 2, role: "post", voice: "am_michael", engine: "kokoro", ...(hostSpeed ? { speed: hostSpeed } : {}), text: "a", file: "narration/parts-cache/b.wav", start: 1.8, seconds: 1 }, ]; const thread = (p, read = { kind: "thread", parents: "0" }) => ({ file: "narration/posts/1/take-2.kokoro-thread.wav", engine: "kokoro", voice: "bf_emma+am_michael", seconds: 3, script: "q\n\na", parts: p, read, speedAsked: read.speed ? true : "preset" }); const e = (t) => post("p1", "host", { takes: [t], pick: 0 }, { parents: [{ id: "9", handle: "guest", author: "Guest", text: "q" }] }); assert.deepEqual(driftOf(m(e(thread(parts(1.1, 0.9)))), cast(1.1)), []); const rows = driftOf(m(e(thread(parts(1.1, 0.9)))), cast(1.25)); assert.deepEqual(rows.map((r) => [r.role, r.reads, r.want, r.thread]), [["post", "kokoro:am_michael ×1.1", "kokoro:am_michael ×1.25", true]]); // A read made with --speed 1.4: that is how it was asked, kept -- no drift while its parts are at it. assert.deepEqual(driftOf(m(e(thread(parts(1.4, 1.4), { kind: "thread", parents: "0", speed: 1.4 }))), cast(1.25)), []); // Orpheus has no speed: never drift by one. const orph = post("p2", "orph", { takes: [{ file: "narration/posts/2/take-1.orpheus.wav", engine: "orpheus", voice: "zac", seconds: 2, script: "x" }], pick: 0 }); assert.deepEqual(driftOf(m(orph), cast(null)), []); }); test("a PRE-LANE take (no speedAsked): never speed drift -- unknown is no claim -- and a re-read asks its own speed again", () => { const old = { file: "narration/posts/1/take-1.kokoro.wav", engine: "kokoro", voice: "am_michael", seconds: 2, script: "Hi.", speed: 1.2 }; const m1 = m(post("p1", "host", { takes: [old], pick: 0 })); assert.deepEqual(driftOf(m1, cast(null)), [], "a --speed 1.2 read with no preset"); assert.deepEqual(driftOf(m1, cast(1.1)), [], "a preset that differs: no claim either"); assert.deepEqual(driftOf(m(post("p1", "host", { takes: [{ ...old, speed: undefined }], pick: 0 })), cast(1.1)), []); // Drift by its VOICE: the re-read keeps the speed it was read at. const castB = { ...cast(null), characters: [{ id: "host", name: "Host", handles: ["host"], synthetic: { voice: "kokoro:am_adam" } }] }; const rows = driftOf(m1, castB); assert.equal(rows.length, 1); assert.deepEqual(rereadPlan("p", m1, rows, ["host"]).items[0].argv, ["posts", "narrate", "p", "p1", "--take", "--speed", "1.2"]); // A preset take whose preset changed: re-read at the new preset (no --speed kept). const p1 = m(post("p1", "host", { takes: [{ ...old, speed: 1.1, speedAsked: "preset" }], pick: 0 })); const prow = driftOf(p1, cast(1.3)); assert.equal(prow.length, 1); assert.deepEqual(rereadPlan("p", p1, prow, ["host"]).items[0].argv, ["posts", "narrate", "p", "p1", "--take"]); });