// THE TEXT-TO-SPEECH ENGINE REGISTRY (release 25 T1) — transcriptionApps.ts's // twin for the other direction. // // Each engine owns: what it is (label, the model identity that goes into the // cache key, its licence, any attribution line its licence asks for), which // voices it has (a fixed list of the engine's STOCK voices — ruled: no voice // cloning, no reference audio, so a voice is never a path), its text pre-pass // (`normalize`, built from the shared lib/ttsText.ts), how it is installed // (`setup`, read by `archilyzer tts setup` and the doctor), and the argv/env // it gives the dual-use wrapper `scripts/tts.mjs` (paths.ttsBin), which runs // the engine and leaves a 48 kHz mono 16-bit WAV at `--output`. // // Pure definitions: no I/O. Both the controller (controller/ttsFile.ts) and the // CLI (bin/tts-setup.ts) import it. // // THE THREE ENGINES: Kokoro-82M (the default; CPU), espeak-ng (zero-install) // and Orpheus 3B (release 25 T1b; GPU). What Orpheus added, and any engine like // it uses: // - `device: "gpu"`: ttsFile.ts's runTtsSynthesis waits while a // transcription runs on a non-CPU worker before it starts one. // - `runtime: "server"` + `serverCommand`: a local server // (controller/ttsServer.ts) started for a batch of syntheses behind the // heavy slot and stopped (SIGTERM, SIGKILL after 15 s) once the `tts` // queue has been idle, so its VRAM is freed; `build` gets its URL. // - `prepareInput`: what the wrapper's text file holds when it is not the // spoken text (Orpheus: the chunks of lib/ttsChunk.ts, each with its token // budget, the sampler, the takes), and `keyExtra`: the settings that change // the output, in the cache key. // - `normalize`: one shared normalizer (lib/ttsText.ts), options per engine. // - `attribution`: a sentence its licence requires beside the disclosure // (Llama 3.2: "Built with Llama"); ttsDisclosure appends it. // - `requires`: binaries outside the install dir (the server), checked with // the install. import path from "node:path"; import { normalizeTtsText } from "./ttsText"; import { chunkTtsText, nPredictFor } from "./ttsChunk"; import type { TtsSettings } from "./ttsSettings"; import { normalizeTtsTuning, ttsReadingSeedBase, type TtsTuning } from "./ttsTuning.mjs"; export type TtsDevice = "cpu" | "gpu"; // What one synthesis asks beyond its words and voice (lib/ttsTuning.mjs): a // tuning and a reading, both already range-checked. Only an engine with // `tuned` takes them; for the rest they are ignored, and the result says so. export type TtsAsk = { tuning?: TtsTuning; reading?: number }; // The tuning a synthesis was made with, EFFECTIVE (every field, defaults // included), its reading and the seed base it gave: in the result and the // sidecar, so a reading can be made again exactly. export type TtsTunedReport = { tuning: Required; reading: number; seedBase: number }; // A file `archilyzer tts setup` downloads once, verified by size and sha256. export type TtsModelFile = { name: string; url: string; bytes: number; sha256: string; }; export type TtsSetup = // A python venv at `//venv` with pinned packages, plus model // files beside it. `python` is the interpreter version the venv is made with // when `uv` is available (else the `--python` given, else python3). | { kind: "python-venv"; python: string; packages: readonly string[]; // The module whose import proves the install (`--check`). importName: string; files: readonly TtsModelFile[]; } // A system binary (paths.), nothing to install. | { kind: "system"; bin: "espeakNgBin"; hint: string }; export type TtsBuildInput = { textFile: string; outWav: string; voice: string; speed: number; // The engine's install dir: `/`. installDir: string; bins: { ffmpegBin: string; espeakNgBin: string }; // A `runtime: "server"` engine's base URL. Undefined for the rest. server?: string; }; // A `runtime: "server"` engine's server: how to start it, from settings. export type TtsServerCommand = { bin: string; args: string[]; env: Record; host: string; port: number; // The memory it is admitted to the heavy slot with (scripts/queue-lock.mjs). estimateMB: number; startTimeoutMs: number; idleStopMs: number; }; // A binary the engine needs that is not in its install dir (the server). export type TtsRequirement = { what: string; path: string }; export type TtsBuild = { // Args to paths.ttsBin (scripts/tts.mjs). argv: string[]; env?: Record; }; export type TtsEngine = { id: string; label: string; // The weights' identity, IN THE CACHE KEY: a new model is a new key. model: string; license: string; // A sentence the engine's licence asks to be shown with the disclosure. attribution?: string; device: TtsDevice; runtime: "process" | "server"; voices: readonly string[]; defaultVoice: string; // Lowest/highest speed the engine accepts (1 = its natural pace). speedRange: readonly [number, number]; normalize: (text: string) => string; setup: TtsSetup; build: (input: TtsBuildInput) => TtsBuild; // What the text file the wrapper reads holds, when it is not the spoken text // itself (Orpheus: its chunks, budgets, sampler and takes, as JSON). `ask`: // the tuning and reading, for an engine with `tuned`. prepareInput?: (spoken: string, voice: string, tts: TtsSettings, ask?: TtsAsk) => string; // Settings that change the output, beside the model: in the cache key. A // tuning or reading only when it is not the default, so an ask without one // keys as it always did. keyExtra?: (tts: TtsSettings, ask?: TtsAsk) => unknown; // An engine that takes a tuning and a reading (Orpheus): what one ask comes // to, every value filled in. Absent: the engine ignores them. tuned?: (tts: TtsSettings, ask?: TtsAsk) => TtsTunedReport; // A `runtime: "server"` engine's server. serverCommand?: (installDir: string, tts: TtsSettings) => TtsServerCommand; // Binaries outside the install dir it needs (checked with the install). requires?: (tts: TtsSettings) => TtsRequirement[]; }; // The wrapper always writes this. export const TTS_SAMPLE_RATE = 48_000; // --- kokoro ------------------------------------------------------------------ // Kokoro-82M v1.0's English stock voices: `a*` American (en-us), `b*` British // (en-gb). The voices file holds other languages too; the pre-pass and the // phonemizer here are English, so those are not offered. export const KOKORO_VOICES = [ "af_alloy", "af_aoede", "af_bella", "af_heart", "af_jessica", "af_kore", "af_nicole", "af_nova", "af_river", "af_sarah", "af_sky", "am_adam", "am_echo", "am_eric", "am_fenrir", "am_liam", "am_michael", "am_onyx", "am_puck", "am_santa", "bf_alice", "bf_emma", "bf_isabella", "bf_lily", "bm_daniel", "bm_fable", "bm_george", "bm_lewis", ] as const; const KOKORO_RELEASE = "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0"; export const KOKORO_FILES: readonly TtsModelFile[] = [ { name: "kokoro-v1.0.onnx", url: `${KOKORO_RELEASE}/kokoro-v1.0.onnx`, bytes: 325_532_387, sha256: "7d5df8ecf7d4b1878015a32686053fd0eebe2bc377234608764cc0ef3636a6c5", }, { name: "voices-v1.0.bin", url: `${KOKORO_RELEASE}/voices-v1.0.bin`, bytes: 28_214_398, sha256: "bca610b8308e8d99f32e6fe4197e7ec01679264efed0cac9140fe9c29f1fbf7d", }, ]; /** The venv's interpreter under an engine's install dir. */ export function ttsVenvPython(installDir: string): string { return path.join(installDir, "venv", "bin", "python"); } const kokoro: TtsEngine = { id: "kokoro", label: "Kokoro-82M", model: "kokoro-v1.0 (fp32 onnx, kokoro-onnx 0.6.1)", license: "Apache-2.0", device: "cpu", runtime: "process", voices: KOKORO_VOICES, defaultVoice: "af_heart", speedRange: [0.5, 2], normalize: (text) => normalizeTtsText(text, { tags: "strip", years: "plain", paragraphs: "join" }), setup: { kind: "python-venv", python: "3.12", packages: ["kokoro-onnx==0.6.1"], importName: "kokoro_onnx", files: KOKORO_FILES, }, build: ({ textFile, outWav, voice, speed, installDir, bins }) => ({ argv: [ "--engine-kind", "kokoro", "--python", ttsVenvPython(installDir), "--model", path.join(installDir, KOKORO_FILES[0].name), "--voices", path.join(installDir, KOKORO_FILES[1].name), "--voice", voice, "--speed", String(speed), "--ffmpeg", bins.ffmpegBin, "--output", outWav, textFile, ], }), }; // --- orpheus ------------------------------------------------------------------ // Orpheus 3B 0.1-ft (Q8_0 GGUF) on llama.cpp's server, its SNAC 24 kHz codes // decoded by the ONNX decoder on the CPU — the tuned round of 2026-10-11. GPU // (Vulkan) by default, behind the machine's heavy slot. Its eight stock // speakers; zac the default (the operator's pick by ear, 2026-10-12, on a commentary script), leah the female option. Tags are performed, so they // are kept; numbers, years and the rest are spoken by the shared normalizer // with the guarded year rule ("1950 people" is a count). No speed control. export const ORPHEUS_VOICES = ["tara", "leah", "jess", "leo", "dan", "mia", "zac", "zoe"] as const; // The sampler the operator picked by ear on a commentary script (2026-10-12, // ~/reports/tts-audition-quartering, variant D3): cooler than the tuned round's // 0.7/0.9 (less over-acting), and a repeat penalty of 1.2 (Orpheus reads quicker // and looser as it rises: less over-enunciation). The penalty's 64-token window // stays — `repeat_last_n` 0 would DISABLE it in llama.cpp, and -1 is refused by // the bundled build. export const ORPHEUS_SAMPLER = { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, repeat_last_n: 64, presence_penalty: 0, frequency_penalty: 0, } as const; export const ORPHEUS_SEED_BASE = 1234; // The sampler knobs a tuning may set are lib/ttsTuning.mjs's (its // ORPHEUS_TUNING_DEFAULTS are these values; a test holds them equal); // repeat_last_n and the presence / frequency penalties stay as above. // // NOTE: a change to a value above changes Orpheus's output WITHOUT changing an // untuned ask's cache key (the key holds only what differs from the defaults): // bump CACHE_KEY_VERSION (controller/ttsFile.ts) with it. /** * An Orpheus ask with every value that EQUALS its default left out (quantised * first, lib/ttsTuning.mjs: the sampler's against its defaults, takes against * settings.tts.orpheus.takes) and reading 0 dropped: `{}` is "no tuning". What * the cache key holds. */ export function normalizeOrpheusAsk(tts: TtsSettings, ask: TtsAsk = {}): TtsAsk { const tuning: TtsTuning = normalizeTtsTuning(ask.tuning, { takes: tts.orpheus.takes }); return { ...(Object.keys(tuning).length ? { tuning } : {}), ...(ask.reading ? { reading: ask.reading } : {}), }; } /** What an Orpheus ask comes to: the sampler sent, the takes, the reading and its seed base. */ export function orpheusEffective(tts: TtsSettings, ask: TtsAsk = {}) { const n = normalizeOrpheusAsk(tts, ask); const { takes, ...samplerDiff } = n.tuning ?? {}; // Spread over the constant: its keys keep their order, so no ask serializes as it always did. const sampler = { ...ORPHEUS_SAMPLER, ...samplerDiff }; const reading = n.reading ?? 0; return { sampler, takes: takes ?? tts.orpheus.takes, reading, seedBase: ttsReadingSeedBase(ORPHEUS_SEED_BASE, reading), }; } export const ORPHEUS_FILES: readonly TtsModelFile[] = [ { name: "orpheus-3b-0.1-ft-Q8_0.gguf", url: "https://huggingface.co/unsloth/orpheus-3b-0.1-ft-GGUF/resolve/main/orpheus-3b-0.1-ft-Q8_0.gguf", bytes: 3_516_431_616, sha256: "9a01ea76b66dd66d08a0952ed72932f0ecce59db3d5c9b1a33621ff7200ba531", }, { name: "snac_decoder.onnx", url: "https://huggingface.co/onnx-community/snac_24khz-ONNX/resolve/main/onnx/decoder_model.onnx", bytes: 52_600_822, sha256: "9e2991fce96c3b49c508304e656052f4f6b860fe8432164fcd976eee195fd4f0", }, { name: "snac_config.json", url: "https://huggingface.co/onnx-community/snac_24khz-ONNX/resolve/main/config.json", bytes: 301, sha256: "47a469c3b6ac9a9c940338d82f7a1ad05b92254d9aa05249cb6b81b7938f69bb", }, ]; const orpheus: TtsEngine = { id: "orpheus", label: "Orpheus 3B", model: "orpheus-3b-0.1-ft Q8_0 + snac_24khz decoder (tuned 2026-10-12)", license: "Llama 3.2 Community License + Apache-2.0", attribution: "Built with Llama", device: "gpu", runtime: "server", voices: ORPHEUS_VOICES, defaultVoice: "zac", speedRange: [1, 1], normalize: (text) => normalizeTtsText(text, { tags: "keep", years: "guarded", paragraphs: "keep" }), setup: { kind: "python-venv", python: "3.12", packages: ["onnxruntime==1.31.0", "numpy==2.5.4"], importName: "onnxruntime", files: ORPHEUS_FILES, }, prepareInput: (spoken, voice, tts, ask) => { const e = orpheusEffective(tts, ask); return JSON.stringify({ version: 1, voice, sampler: e.sampler, seedBase: e.seedBase, takes: e.takes, tagCheck: tts.orpheus.tagCheck, chunks: chunkTtsText(spoken).map((c) => ({ ...c, nPredict: nPredictFor(c.text) })), }); }, // No tuning and no reading: `{takes, tagCheck}`, the key it always had. keyExtra: (tts, ask) => { const n = normalizeOrpheusAsk(tts, ask); const { takes, ...sampler } = n.tuning ?? {}; return { takes: takes ?? tts.orpheus.takes, tagCheck: tts.orpheus.tagCheck, ...(Object.keys(sampler).length ? { sampler } : {}), ...(n.reading ? { reading: n.reading } : {}), }; }, tuned: (tts, ask) => { const e = orpheusEffective(tts, ask); return { tuning: { temperature: e.sampler.temperature, top_p: e.sampler.top_p, top_k: e.sampler.top_k, min_p: e.sampler.min_p, repeat_penalty: e.sampler.repeat_penalty, takes: e.takes, }, reading: e.reading, seedBase: e.seedBase, }; }, serverCommand: (installDir, tts) => { const o = tts.orpheus; const env: Record = {}; if (o.libraryPath) env.LD_LIBRARY_PATH = o.libraryPath; if (o.ggmlBackendPath) env.GGML_BACKEND_PATH = o.ggmlBackendPath; return { bin: o.serverBin, args: [ "-m", path.join(installDir, ORPHEUS_FILES[0].name), "--host", "127.0.0.1", "--port", String(o.port), "-ngl", String(o.gpuLayers), "-c", String(o.contextSize), "-np", "1", "--no-webui", ], env, host: "127.0.0.1", port: o.port, estimateMB: o.heavyEstimateMB, startTimeoutMs: o.startTimeoutSeconds * 1000, idleStopMs: o.idleStopSeconds * 1000, }; }, requires: (tts) => [{ what: "llama-server (settings.tts.orpheus.serverBin)", path: tts.orpheus.serverBin }], build: ({ textFile, outWav, installDir, bins, server }) => ({ argv: [ "--engine-kind", "orpheus", "--python", ttsVenvPython(installDir), "--snac", path.join(installDir, ORPHEUS_FILES[1].name), "--server", server ?? "", "--ffmpeg", bins.ffmpegBin, "--output", outWav, textFile, ], }), }; // --- espeak-ng --------------------------------------------------------------- // The zero-install fallback: a formant synthesizer every Linux has, robotic // and unmistakably synthetic. What the tests run, and what a machine without // `tts setup` can still use. const espeakNg: TtsEngine = { id: "espeak-ng", label: "eSpeak NG", model: "espeak-ng (formant)", license: "GPL-3.0-or-later", device: "cpu", runtime: "process", voices: ["en-us", "en-gb", "en"], defaultVoice: "en-us", speedRange: [0.5, 2], normalize: (text) => normalizeTtsText(text, { tags: "strip", years: "plain", paragraphs: "join" }), setup: { kind: "system", bin: "espeakNgBin", hint: "install espeak-ng from the system's packages" }, build: ({ textFile, outWav, voice, speed, bins }) => ({ argv: [ "--engine-kind", "espeak-ng", "--espeak", bins.espeakNgBin, "--voice", voice, "--speed", String(speed), "--ffmpeg", bins.ffmpegBin, "--output", outWav, textFile, ], }), }; export const TTS_ENGINES: Record = { [kokoro.id]: kokoro, [espeakNg.id]: espeakNg, [orpheus.id]: orpheus, }; export const DEFAULT_TTS_ENGINE_ID = "kokoro"; export const DEFAULT_TTS_VOICE = "af_heart"; export function ttsEngineIds(): string[] { return Object.keys(TTS_ENGINES); } /** The engine with this id, or undefined (never a silent fallback: a typo is refused). */ export function getTtsEngine(id: string | undefined): TtsEngine | undefined { return id ? TTS_ENGINES[id] : undefined; } /** `/`: where an engine is installed. */ export function ttsInstallDir(home: string, engine: Pick): string { return path.join(home, engine.id); } /** The disclosure line a narrated export carries for a synthesis. */ export function ttsDisclosure(engine: Pick, voice: string): string { const line = `Narration: synthetic voice (${engine.label} · ${voice})`; return engine.attribution ? `${line}. ${engine.attribution}` : line; } // A client-safe view (no functions). export type TtsEngineDescriptor = { id: string; label: string; license: string; device: TtsDevice; voices: readonly string[]; defaultVoice: string; }; export function listTtsEngines(): TtsEngineDescriptor[] { return Object.values(TTS_ENGINES).map((e) => ({ id: e.id, label: e.label, license: e.license, device: e.device, voices: e.voices, defaultVoice: e.defaultVoice, })); }