// scripts/tts_orpheus.py — the Orpheus helper's own checks, run through its // `selftest` (numpy only: the take checks, the rate floor for multi-sentence // chunks, the frame bands and SNAC levels, the first-pass early stop, the // fallback when nothing passes, the tag-length check, the joins). // // Run with: node --test scripts/tts_orpheus.test.mjs (part of `pnpm run test:scripts`) // // Needs a python with numpy: `python3` when it has one. Skipped otherwise — the // real model is never run here. import { test } from "node:test"; import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import path from "node:path"; const HELPER = path.join(import.meta.dirname, "tts_orpheus.py"); const probe = spawnSync("python3", ["-c", "import numpy"], { encoding: "utf8" }); const skip = probe.status !== 0 && "python3 with numpy absent"; test("the Orpheus helper's selftest passes", { skip }, () => { const r = spawnSync("python3", [HELPER, "selftest"], { encoding: "utf8" }); assert.equal(r.status, 0, r.stdout + r.stderr); assert.match(r.stdout, /SELFTEST PASS/); assert.doesNotMatch(r.stdout, /^FAIL/m); // The cases it holds, by name: a missing one is a dropped check. for (const name of [ "a slow three-sentence read (1.8 words/s) passes", "a take with no end of speech fails as truncated", "early stop: take 2 passes, take 3 is never asked", "a reading's seed base moves every take's seed", "every take truncated or malformed: none", "with the tag check, takes barely longer than the plain read fail", "SNAC levels: c0 | c1 c4 | c2 c3 c5 c6", ]) { assert.ok(r.stdout.includes(`ok ${name}`), name); } }); test("the helper refuses a voice that is not a stock one, before anything runs", { skip }, () => { const r = spawnSync( "python3", ["-B", "-c", `import sys; sys.path.insert(0, ${JSON.stringify(path.dirname(HELPER))}); import tts_orpheus as t try: t.render({"voice": "someone", "sampler": {}, "chunks": [{"text": "x", "nPredict": 7, "pauseAfter": 0}]}, "http://127.0.0.1:1", None) except SystemExit as e: print(e)`], { encoding: "utf8" }, ); assert.match(r.stdout, /not a stock voice: 'someone'/); });