// THE VOICE ENGINE REGISTRY (release 39) — lib/ttsApps.ts's twin for the // other thing a narration needs: running an engine over a SPEECH RECORDING // (operator, 2 Nov: "pure AI voice, record voice, and run AI on recorded voice // — and re-run or re-record"). Two ops: // // enhance denoise / de-reverb / level a read: the words, the timing and // the voice are the input's; the room and the noise go. // convert keep the PERFORMANCE (timing, pitch contour, emphasis) and swap // the TIMBRE for a stock synthetic voice's. // // Each engine owns: what it is (label, the model identity, its licence), which // op it serves, how it is installed (`setup`, read by `archilyzer voice setup` // and the install check), its knobs (`params`, each a number or a boolean in a // range — anything else is refused), and the argv it gives the dual-use // wrapper `scripts/voice.mjs` (paths.voiceBin), which always leaves a 48 kHz // mono 16-bit WAV exactly as long as the input. // // NO CLONING. A convert TARGET is a stock voice of one of OUR text-to-speech // engines, named `:` ("orpheus:zac", "kokoro: // am_michael") — the reference clip a converter is prompted with is that // voice reading a fixed public-domain passage (VOICE_REFERENCE_TEXT, Aesop's // "The North Wind and the Sun"), synthesized once through the `tts` op and // cached. A path, a URL, an uploaded or recorded clip is REFUSED, whatever it // holds: these engines are zero-shot, so a few seconds of anyone's voice would // make them speak as that person. The tts op's own rule (ttsApps.ts: "a voice // is a name from the registry, never a path") and the operator's, extended to // the voice ops — the only voices that can come OUT of them are voices no // person owns. Licences agree: Kokoro and Orpheus's stock speakers are offered // for synthesis; nobody's likeness is. // // Pure definitions: no I/O. import path from "node:path"; import { getTtsEngine, ttsEngineIds, type TtsModelFile } from "./ttsApps"; export type VoiceOp = "enhance" | "convert"; export const VOICE_OPS: readonly VoiceOp[] = ["enhance", "convert"]; export type VoiceSetup = // Nothing to install: ffmpeg and a model file shipped in the repo. | { kind: "bundled"; hint: string } // Files downloaded once into the install dir (a static binary and its kin). | { kind: "files"; files: readonly VoiceModelFile[] } // A python venv at `/venv` with pinned packages, a pinned // checkout of the engine's code at `/code`, and model files. | { kind: "python-venv"; python: string; // `pip install` arguments, pinned; `indexUrl` for torch's CPU wheels. packages: readonly string[]; indexUrl?: string; // The module whose import proves the venv (`--check`). importName: string; code: { repo: string; commit: string }; files: readonly VoiceModelFile[]; // Files the engine runs without, in named groups: fetched only when // setup is asked for the group (`--with `), never counted against // "installed" — an install made before a group existed keeps working. optional?: readonly VoiceFileGroup[]; }; export type VoiceFileGroup = { id: string; // What the group is for, as setup says it. label: string; files: readonly VoiceModelFile[]; }; // A downloaded file, verified by size and sha256 like a TTS model file. `name` // may hold a subdirectory (`whisper-small/model.safetensors`). export type VoiceModelFile = TtsModelFile & { executable?: boolean }; export type VoiceParamSpec = | { kind: "number"; min: number; max: number; default: number; doc: string } | { kind: "boolean"; default: boolean; doc: string }; // THE PITCH A CONVERSION LANDS ON (operator, 11 Nov: both converters threw the // read's intonation away — inputs with a median f0 of 128 to 237 Hz all came // out at 196-199 Hz, a 152-321 Hz range as 165-240 Hz). // target the stock voice's own pitch: the converter is given none of the // input's (every engine; what there was before). // source the input's f0 as it was read: raise the voice and the output // rises with it. // contour the input's f0 curve moved as a whole so its median sits on the // stock voice's: every rise and fall kept, the register the target's. // `semitones` then moves a followed curve (source, contour) up or down. export type VoicePitch = "target" | "source" | "contour"; export const VOICE_PITCH_MODES: readonly VoicePitch[] = ["target", "source", "contour"]; export const VOICE_SEMITONES_MAX = 12; export type VoicePitchChoice = { pitch: VoicePitch; semitones: number }; export const DEFAULT_VOICE_PITCH: VoicePitchChoice = { pitch: "target", semitones: 0 }; export type VoiceBuildInput = { input: string; output: string; // More files run the same way in the same run (a parted take's parts). more?: { input: string; output: string }[]; installDir: string; params: Record; threads: number; // The stock target's reference clip and openvoice's embedding cache (convert). targetRef?: string; targetSe?: string; // A followed pitch (an engine with `pitch`); absent = target. pitch?: VoicePitchChoice; bins: { ffmpegBin: string; voiceModelsDir: string }; }; export type VoiceEngine = { id: string; op: VoiceOp; label: string; model: string; license: string; // Upstream's home, for the record and the docs. home: string; device: "cpu"; setup: VoiceSetup; params: Readonly>; // The memory the job declares to the heavy slot when the setting is blank: // the measured peak (2026-11-03 bake-off: the run's process group, resident // plus swapped — rnnoise 112 MB, deepfilternet 111 MB, openvoice 1625 MB, // seed-vc 2865 MB; no GPU memory, they are CPU engines) plus a margin. defaultEstimateMB: number; // A convert engine that can FOLLOW the input's pitch (source, contour): the // optional file group that mode runs on, and the memory ITS run declares // (another, bigger model) — kept in settings.voice.heavyEstimateMB under // `estimateKey`. An engine without it has one pitch: the target's. pitch?: { group: string; estimateKey: string; defaultEstimateMB: number }; // Args to paths.voiceBin (scripts/voice.mjs). build: (input: VoiceBuildInput) => string[]; }; /** The venv's interpreter under an engine's install dir. */ export function voiceVenvPython(installDir: string): string { return path.join(installDir, "venv", "bin", "python"); } /** The pinned checkout of an engine's code. */ export function voiceCodeDir(installDir: string): string { return path.join(installDir, "code"); } const common = (op: VoiceOp, kind: string, i: VoiceBuildInput) => [ "--op", op, "--engine-kind", kind, "--input", i.input, "--output", i.output, "--params", JSON.stringify(i.params), ...(i.more?.length ? ["--more", JSON.stringify(i.more)] : []), "--threads", String(i.threads), "--ffmpeg", i.bins.ffmpegBin, ]; const LEVEL_PARAMS = { lufs: { kind: "number", min: -36, max: -10, default: -20, doc: "the level the result is set to, in LUFS, by ONE static gain (capped at -1 dBTP)" }, highpass: { kind: "number", min: 0, max: 200, default: 70, doc: "a high-pass at this many Hz before the engine (0 = none)" }, } as const satisfies Record; // --- enhance ----------------------------------------------------------------- // RNNoise through ffmpeg's `arnndn`, with Gregor Richards's "somnolent-hogwash" // model (recording noise, speech signal) from the arnndn-models set ffmpeg's // docs point to — shipped in the repo (scripts/voice-models/sh.rnnn, ~300 KB; // its author: "none of this work is creative and thus none of it is subject to // copyright"). The zero-install fallback: light, real-time, cruder. const rnnoise: VoiceEngine = { id: "rnnoise", op: "enhance", label: "RNNoise (ffmpeg arnndn)", model: "rnnoise-nu sh.rnnn (richardpl/arnndn-models@0fda24c)", license: "BSD-3-Clause (RNNoise) · model not subject to copyright", home: "https://github.com/GregorR/rnnoise-models", device: "cpu", setup: { kind: "bundled", hint: "ffmpeg with the arnndn filter (every build since 4.3)" }, params: { ...LEVEL_PARAMS, mix: { kind: "number", min: 0, max: 1, default: 1, doc: "how much of the denoised signal is kept (1 = all of it, 0 = the input)" }, }, defaultEstimateMB: 300, build: (i) => [...common("enhance", "rnnoise", i), "--model", path.join(i.bins.voiceModelsDir, "sh.rnnn")], }; // DeepFilterNet 3 through the project's own static binary (its release // v0.5.6, the model embedded): CPU, faster than real time, 48 kHz. Noise // suppression first; it softens a small room's reverb but is no dedicated // de-reverb. export const DEEPFILTERNET_FILES: readonly VoiceModelFile[] = [ { name: "deep-filter", url: "https://github.com/Rikorose/DeepFilterNet/releases/download/v0.5.6/deep-filter-0.5.6-x86_64-unknown-linux-musl", bytes: 36_417_296, sha256: "70775e251eee44c0f2451a1e833326cf8bcbbe304d3e7cd12851e6fce72ef7da", executable: true, }, ]; const deepfilternet: VoiceEngine = { id: "deepfilternet", op: "enhance", label: "DeepFilterNet 3", model: "DeepFilterNet3 (deep-filter 0.5.6, x86_64 musl)", license: "MIT OR Apache-2.0", home: "https://github.com/Rikorose/DeepFilterNet", device: "cpu", setup: { kind: "files", files: DEEPFILTERNET_FILES }, params: { ...LEVEL_PARAMS, attenLimDb: { kind: "number", min: 0, max: 100, default: 100, doc: "the most the noise is turned down, in dB (100 = no limit; 20-30 keeps a little room)" }, postFilter: { kind: "boolean", default: false, doc: "DeepFilterNet's post-filter: stronger attenuation in the gaps" }, }, defaultEstimateMB: 400, build: (i) => [...common("enhance", "deepfilternet", i), "--install", i.installDir], }; // --- convert ----------------------------------------------------------------- // Torch on the CPU, pinned: the CPU wheels index, Python 3.12. const TORCH_CPU_INDEX = "https://download.pytorch.org/whl/cpu"; export const OPENVOICE_FILES: readonly VoiceModelFile[] = [ { name: "converter/checkpoint.pth", url: "https://huggingface.co/myshell-ai/OpenVoiceV2/resolve/f36e7edfe1684461a8343844af60babc2efbb727/converter/checkpoint.pth", bytes: 131_320_490, sha256: "9652c27e92b6b2a91632590ac9962ef7ae2b712e5c5b7f4c34ec55ee2b37ab9e", }, { name: "converter/config.json", url: "https://huggingface.co/myshell-ai/OpenVoiceV2/resolve/f36e7edfe1684461a8343844af60babc2efbb727/converter/config.json", bytes: 838, sha256: "9dfff60350b8c63f2c664efd92a61b2516efb22671466960f0e5dfebd881fa47", }, ]; // OpenVoice v2's tone-colour converter only (no base TTS, no watermarker: // scripts/voice_openvoice.py imports the converter's own modules). Light. const openvoice: VoiceEngine = { id: "openvoice", op: "convert", label: "OpenVoice v2 (tone-colour converter)", model: "OpenVoiceV2 converter (myshell-ai/OpenVoiceV2@f36e7ed)", license: "MIT", home: "https://github.com/myshell-ai/OpenVoice", device: "cpu", setup: { kind: "python-venv", python: "3.12", indexUrl: TORCH_CPU_INDEX, packages: ["torch==2.4.0+cpu", "torchaudio==2.4.0+cpu", "numpy==1.26.4", "librosa==0.10.2", "soundfile==0.12.1"], importName: "torch", code: { repo: "https://github.com/myshell-ai/OpenVoice", commit: "74a1d147b17a8c3092dd5430504bd83ef6c7eb23" }, files: OPENVOICE_FILES, }, params: { tau: { kind: "number", min: 0, max: 1, default: 0.3, doc: "the converter's temperature (upstream's 0.3; lower holds closer to the input)" }, }, defaultEstimateMB: 2000, build: (i) => [ ...common("convert", "openvoice", i), "--python", voiceVenvPython(i.installDir), "--code", voiceCodeDir(i.installDir), "--install", i.installDir, "--target-ref", i.targetRef ?? "", ...(i.targetSe ? ["--target-se", i.targetSe] : []), ], }; // The f0 model's run, declared to the heavy slot: its peak measured 2026-11-11 // (RSS plus swap of the wrapper and python, sampled twice a second) — 3706 MB // over 6.9 s reads, 5781 MB over a 34 s one, whose first window is a full one // (30 s less the reference: the 44.1 kHz vocoder's activations grow with the // window, and no take makes a longer one) — plus a margin. const SEEDVC_F0_ESTIMATE_MB = 6500; const SEEDVC_HF = "https://huggingface.co/Plachta/Seed-VC/resolve/257283f9f41585055e8f858fba4fd044e5caed6e"; const WHISPER_HF = "https://huggingface.co/openai/whisper-small/resolve/973afd24965f72e36ca33b3055d56a652f456b4d"; const BIGVGAN_HF = "https://huggingface.co/nvidia/bigvgan_v2_22khz_80band_256x/resolve/633ff708ed5b74903e86ff1298cf4a98e921c513"; const CAMPPLUS_HF = "https://huggingface.co/funasr/campplus/resolve/e4b6ede7ce16997aff4ae69fbca1f0175e2afede"; export const SEEDVC_FILES: readonly VoiceModelFile[] = [ { name: "DiT_seed_v2_uvit_whisper_small_wavenet_bigvgan_pruned.pth", url: `${SEEDVC_HF}/DiT_seed_v2_uvit_whisper_small_wavenet_bigvgan_pruned.pth`, bytes: 440_312_082, sha256: "8ec8841b20bb46df9f7e8e570a6946a4b87b940133c7f0e778487ff33841f720", }, { name: "config_dit_mel_seed_uvit_whisper_small_wavenet.yml", url: `${SEEDVC_HF}/config_dit_mel_seed_uvit_whisper_small_wavenet.yml`, bytes: 2_289, sha256: "27a91ac41bdb41d0b6951c63642d791b4a70d60b9fc5550eb645f9ddcb3c94da", }, { name: "whisper-small/model.safetensors", url: `${WHISPER_HF}/model.safetensors`, bytes: 966_995_080, sha256: "1d7734884874f1a1513ed9aa760a4f8e97aaa02fd6d93a3a85d27b2ae9ca596b", }, { name: "whisper-small/config.json", url: `${WHISPER_HF}/config.json`, bytes: 1_967, sha256: "e6a2b489da1b5aed65a8eb8d1e7466fa867ad5643a8bc138ba708bd56b2875c4", }, { name: "whisper-small/preprocessor_config.json", url: `${WHISPER_HF}/preprocessor_config.json`, bytes: 184_990, sha256: "9b5cd03a36fbb8a627c64d98a5b5b126ead95a77720723944487311f0110b666", }, { name: "bigvgan/bigvgan_generator.pt", url: `${BIGVGAN_HF}/bigvgan_generator.pt`, bytes: 449_228_171, sha256: "e95ba25972d3de0628d99cd156e9315a9c018899bf739988959ebe3544080ced", }, { name: "bigvgan/config.json", url: `${BIGVGAN_HF}/config.json`, bytes: 1_405, sha256: "88a1f47acf747db0b21e97a389d838566147f7a5464583ff5c8d819d870f03ee", }, { name: "campplus_cn_common.bin", url: `${CAMPPLUS_HF}/campplus_cn_common.bin`, bytes: 28_036_335, sha256: "3388cf5fd3493c9ac9c69851d8e7a8badcfb4f3dc631020c4961371646d5ada8", }, ]; // The f0-conditioned model (upstream's `inference.py --f0-condition`): a 44.1 // kHz DiT, its 128-band BigVGAN, and RMVPE, the pitch tracker whose curve // conditions it. Optional (`voice setup --engine seed-vc --with f0`, 1.49 GB): // `pitch: source | contour` runs on these, `target` never touches them. const RMVPE_HF = "https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/e6d0c1a17da07c33557852f9dfa2bd44cc75737d"; const BIGVGAN_44K_HF = "https://huggingface.co/nvidia/bigvgan_v2_44khz_128band_512x/resolve/95a9d1dcb12906c03edd938d77b9333d6ded7dfb"; export const SEEDVC_F0_FILES: readonly VoiceModelFile[] = [ { name: "DiT_seed_v2_uvit_whisper_base_f0_44k_bigvgan_pruned_ft_ema_v2.pth", url: `${SEEDVC_HF}/DiT_seed_v2_uvit_whisper_base_f0_44k_bigvgan_pruned_ft_ema_v2.pth`, bytes: 820_865_494, sha256: "42aef93ffe65857c840d270252fa040f7ba04514945ec460f3ac1ac2a96de684", }, { name: "config_dit_mel_seed_uvit_whisper_base_f0_44k.yml", url: `${SEEDVC_HF}/config_dit_mel_seed_uvit_whisper_base_f0_44k.yml`, bytes: 2_408, sha256: "ff86f343b08c2def405f075022eeb10dafba23c4eda36d151010f4ca6d7a1a0a", }, { name: "rmvpe.pt", url: `${RMVPE_HF}/rmvpe.pt`, bytes: 181_184_272, sha256: "6d62215f4306e3ca278246188607209f09af3dc77ed4232efdd069798c4ec193", }, { name: "bigvgan-44k/bigvgan_generator.pt", url: `${BIGVGAN_44K_HF}/bigvgan_generator.pt`, bytes: 489_041_291, sha256: "d9fe7ec6bd0b44ed9d66973d5012d8181c1570b01e5c72df51973e241dccd357", }, { name: "bigvgan-44k/config.json", url: `${BIGVGAN_44K_HF}/config.json`, bytes: 1_403, sha256: "65b7f487bfaf15256056a75f6667ef5f640214c981922a111927873705ea4ddb", }, ]; export const SEEDVC_F0_GROUP: VoiceFileGroup = { id: "f0", label: "the f0-conditioned 44.1 kHz model, for a conversion that follows the input's pitch (pitch: source | contour)", files: SEEDVC_F0_FILES, }; // Seed-VC v1, its 22 kHz speech model (Whisper-small content features, a // diffusion transformer, BigVGAN v2): zero-shot, the stronger timbre match, // several times slower than OpenVoice on the CPU. GPL-3.0 code, run as a // separate program (never linked into ours). const seedVc: VoiceEngine = { id: "seed-vc", op: "convert", label: "Seed-VC (v1, 22 kHz speech)", model: "seed-uvit-whisper-small-wavenet (Plachta/Seed-VC@257283f) + whisper-small + bigvgan_v2_22khz_80band_256x + campplus", license: "GPL-3.0 (code, model) · Apache-2.0 (Whisper, CAM++) · MIT (BigVGAN)", home: "https://github.com/Plachtaa/seed-vc", device: "cpu", setup: { kind: "python-venv", python: "3.12", indexUrl: TORCH_CPU_INDEX, packages: [ "torch==2.4.0+cpu", "torchaudio==2.4.0+cpu", "numpy==1.26.4", "scipy==1.13.1", "librosa==0.10.2", "soundfile==0.12.1", "munch==4.0.0", "einops==0.8.0", "transformers==4.46.3", "huggingface-hub==0.26.5", "pyyaml==6.0.2", "matplotlib==3.9.4", "tqdm==4.67.1", ], importName: "transformers", code: { repo: "https://github.com/Plachtaa/seed-vc", commit: "51383efd921027683c89e5348211d93ff12ac2a8" }, files: SEEDVC_FILES, optional: [SEEDVC_F0_GROUP], }, params: { steps: { kind: "number", min: 1, max: 100, default: 10, doc: "diffusion steps: each is one pass of the model over every window, so the time grows with them (upstream: 4-10 fast, 25-30 cleaner; 10 by the 2026-11-03 bake-off)" }, cfgRate: { kind: "number", min: 0, max: 1, default: 0.7, doc: "classifier-free guidance (upstream's 0.7)" }, refSeconds: { kind: "number", min: 3, max: 25, default: 10, doc: "seconds of the reference the model is prompted with (each window is 30 s less this: less is faster)" }, }, defaultEstimateMB: 3500, pitch: { group: SEEDVC_F0_GROUP.id, estimateKey: "seed-vc-f0", defaultEstimateMB: SEEDVC_F0_ESTIMATE_MB }, build: (i) => [ ...common("convert", "seed-vc", i), "--python", voiceVenvPython(i.installDir), "--code", voiceCodeDir(i.installDir), "--install", i.installDir, "--target-ref", i.targetRef ?? "", ...(i.pitch && i.pitch.pitch !== "target" ? ["--pitch", i.pitch.pitch, "--semitones", String(i.pitch.semitones)] : []), ], }; export const VOICE_ENGINES: Record = { [deepfilternet.id]: deepfilternet, [rnnoise.id]: rnnoise, [openvoice.id]: openvoice, [seedVc.id]: seedVc, }; export const DEFAULT_VOICE_ENGINE: Record = { enhance: "deepfilternet", convert: "openvoice" }; export const DEFAULT_VOICE_TARGET = "orpheus:zac"; export function voiceEngineIds(op?: VoiceOp): string[] { return Object.values(VOICE_ENGINES).filter((e) => !op || e.op === op).map((e) => e.id); } /** The engine with this id, or undefined (never a silent fallback). */ export function getVoiceEngine(id: string | undefined): VoiceEngine | undefined { return id ? VOICE_ENGINES[id] : undefined; } /** `/`: where an engine is installed. */ export function voiceInstallDir(home: string, engine: Pick): string { return path.join(home, engine.id); } type Check = { ok: true; value: T } | { ok: false; error: string }; /** * The pitch a conversion lands on: the request's `pitch` / `semitones` over the * defaults (settings.voice.convert). An engine with one pitch refuses a request * for another (the defaults are not a request: they are for the engines that * can); `semitones` asked of the target's own pitch is refused, since nothing * is followed to move. A request that names a followed `pitch` and no * `semitones` takes the DEFAULT semitones (settings.voice.convert.semitones), * whichever pitch the settings name — say `"semitones": 0` for none. Pure. */ export function resolveVoicePitch( engine: Pick, given: { pitch?: unknown; semitones?: unknown }, defaults: VoicePitchChoice = DEFAULT_VOICE_PITCH, ): Check { if (given.pitch !== undefined && !VOICE_PITCH_MODES.includes(given.pitch as VoicePitch)) { return { ok: false, error: `"pitch" is one of ${VOICE_PITCH_MODES.join(", ")} (got ${JSON.stringify(given.pitch)})` }; } if (given.semitones !== undefined) { const n = given.semitones; if (typeof n !== "number" || !Number.isFinite(n) || Math.abs(n) > VOICE_SEMITONES_MAX) { return { ok: false, error: `"semitones" is a number from -${VOICE_SEMITONES_MAX} to ${VOICE_SEMITONES_MAX} (got ${JSON.stringify(n)})` }; } } const askedPitch = given.pitch as VoicePitch | undefined; const askedSemitones = given.semitones as number | undefined; if (!engine.pitch) { if ((askedPitch && askedPitch !== "target") || askedSemitones) { const can = Object.values(VOICE_ENGINES).filter((e) => e.pitch).map((e) => e.id); return { ok: false, error: `${engine.label} has no pitch control — it lands every read on the target's own pitch; "pitch" and "semitones" are ${can.join(", ")}'s (engine: "${can[0]}")`, }; } return { ok: true, value: { pitch: "target", semitones: 0 } }; } const pitch = askedPitch ?? defaults.pitch; if (pitch === "target") { if (askedSemitones) { return { ok: false, error: `"semitones" moves a followed pitch — give "pitch": "source" or "contour" with it (pitch is "target": the stock voice's own)` }; } return { ok: true, value: { pitch, semitones: 0 } }; } return { ok: true, value: { pitch, semitones: askedSemitones ?? defaults.semitones } }; } /** How a result, a take or a page says a pitch choice: "contour +2 st", "source", "" for the target's own. */ export function describeVoicePitch(p: Partial | undefined): string { if (!p?.pitch || p.pitch === "target") return ""; const n = p.semitones ?? 0; return n ? `${p.pitch} ${n > 0 ? "+" : "−"}${Math.abs(n)} st` : p.pitch; } /** * An engine's knobs from a body's `params`: each key one the engine has, each * value of its kind and in its range; the rest from the defaults. Pure. */ export function resolveVoiceParams(engine: VoiceEngine, given: unknown): Check> { if (given !== undefined && (typeof given !== "object" || given === null || Array.isArray(given))) { return { ok: false, error: '"params" must be an object' }; } const g = (given ?? {}) as Record; const known = Object.keys(engine.params); const unknown = Object.keys(g).filter((k) => !known.includes(k)); if (unknown.length) { return { ok: false, error: `${engine.id} has no param(s) ${unknown.join(", ")} — its params: ${known.join(", ") || "none"}` }; } const out: Record = {}; for (const [k, spec] of Object.entries(engine.params)) { const v = g[k]; if (v === undefined) { out[k] = spec.default; } else if (spec.kind === "boolean") { if (typeof v !== "boolean") return { ok: false, error: `params.${k} must be true or false` }; out[k] = v; } else { if (typeof v !== "number" || !Number.isFinite(v)) return { ok: false, error: `params.${k} must be a number` }; if (v < spec.min || v > spec.max) return { ok: false, error: `params.${k} must be between ${spec.min} and ${spec.max} (got ${v})` }; out[k] = v; } } return { ok: true, value: out }; } // --- the stock targets --------------------------------------------------------- // What a stock target's reference clip reads: Aesop's "The North Wind and the // Sun" (public domain; the passage phoneticians record), ~25 s of speech. IN // the reference's identity: a new text is a new reference. export const VOICE_REFERENCE_TEXT = "The North Wind and the Sun were disputing which was the stronger, when a traveler came along wrapped in a warm cloak. " + "They agreed that the one who first succeeded in making the traveler take his cloak off should be considered stronger than the other. " + "Then the North Wind blew as hard as he could, but the more he blew the more closely did the traveler fold his cloak around him; " + "and at last the North Wind gave up the attempt. Then the Sun shined out warmly, and immediately the traveler took off his cloak. " + "And so the North Wind was obliged to confess that the Sun was the stronger of the two."; export type StockTarget = { id: string; ttsEngine: string; voice: string }; // A target that LOOKS like a recording: a path, a URL, a file name. const RECORDING_LIKE = /[/\\]|^~|^[a-z]+:\/\/|\.(wav|mp3|flac|ogg|opus|m4a|aac|webm|mp4|mkv|mov|pt|npy)$/i; export const NO_CLONING = "a convert target is a STOCK synthetic voice, `:` (e.g. orpheus:zac, kokoro:am_michael) — " + "never a recording or a file: these engines would make anyone's voice from a few seconds of it, so no real person's " + "voice is ever a target"; /** * A convert target, parsed against the TTS registry; a path or a recording is * refused. `:`, or a bare stock voice name that exactly one * engine has (`zac` is orpheus:zac — the shape umtool records a take's voice * in). Pure. */ export function parseStockTarget(raw: unknown): Check { if (typeof raw !== "string" || !raw.trim()) return { ok: false, error: `the target must be a string: ${NO_CLONING}` }; const s = raw.trim(); if (RECORDING_LIKE.test(s)) return { ok: false, error: `"${s}" is refused: ${NO_CLONING}` }; if (/^[A-Za-z0-9_-]+$/.test(s)) { const owners = ttsEngineIds().filter((id) => getTtsEngine(id)!.voices.includes(s)); if (owners.length === 1) return { ok: true, value: { id: `${owners[0]}:${s}`, ttsEngine: owners[0], voice: s } }; if (owners.length > 1) return { ok: false, error: `"${s}" is a stock voice of ${owners.join(" and ")} — name one: ${owners.map((o) => `${o}:${s}`).join(" or ")}` }; return { ok: false, error: `"${s}" is not a stock voice: ${NO_CLONING}` }; } const m = /^([a-z0-9-]+):([A-Za-z0-9_-]+)$/.exec(s); if (!m) return { ok: false, error: `"${s}" is not a stock voice: ${NO_CLONING}` }; const engine = getTtsEngine(m[1]); if (!engine) return { ok: false, error: `"${s}": no text-to-speech engine "${m[1]}" — known: ${ttsEngineIds().join(", ")}` }; if (!engine.voices.includes(m[2])) { return { ok: false, error: `"${s}": ${engine.id} has no stock voice "${m[2]}" — its voices: ${engine.voices.join(", ")}` }; } return { ok: true, value: { id: `${engine.id}:${m[2]}`, ttsEngine: engine.id, voice: m[2] } }; } /** Where a stock target's reference clip is kept: `/targets/-.wav` (+ `.json`). */ export function stockTargetPaths(home: string, t: Pick): { wav: string; json: string } { const base = path.join(home, "targets", `${t.ttsEngine}-${t.voice}`); return { wav: `${base}.wav`, json: `${base}.json` }; } /** The disclosure line a converted take carries. */ export function voiceConvertDisclosure(engine: Pick, target: Pick): string { return `Narration: voice converted to a synthetic voice (${engine.label} · ${target.id})`; } // A client-safe view (no functions). export type VoiceEngineDescriptor = { id: string; op: VoiceOp; label: string; license: string; params: Record; pitch: boolean }; export function listVoiceEngines(): VoiceEngineDescriptor[] { return Object.values(VOICE_ENGINES).map((e) => ({ id: e.id, op: e.op, label: e.label, license: e.license, params: { ...e.params }, pitch: Boolean(e.pitch) })); }