// settings.tts — local text-to-speech (release 25 T1). // // Pure: the type, its defaults, the sanitizer settingsSchema.ts runs it // through, the per-field docs SETTINGS.md renders, and the two resolvers that // turn a blank `home`/`dir` into the defaults on Paths. The engines are // lib/ttsApps.ts; a synthesis is controller/ttsFile.ts (`pnpm ops tts`). import os from "node:os"; import path from "node:path"; import type { FieldDocs } from "./fieldDocs"; import type { Paths } from "./paths"; import { DEFAULT_TTS_ENGINE_ID, DEFAULT_TTS_VOICE, getTtsEngine } from "./ttsApps"; // Orpheus 3B (release 25 T1b): the local llama-server it runs on and how many // takes a chunk gets. The server's binary and its two library paths default to // Ollama's bundled build on Vulkan — settings, never hard-coded. export type OrpheusTtsSettings = { serverBin: string; libraryPath: string; ggmlBackendPath: string; port: number; gpuLayers: number; contextSize: number; startTimeoutSeconds: number; idleStopSeconds: number; heavyEstimateMB: number; takes: number; tagCheck: boolean; }; export type TtsSettings = { engine: string; voice: string; speed: number; home: string; dir: string; orpheus: OrpheusTtsSettings; }; export const DEFAULT_ORPHEUS_TTS_SETTINGS: OrpheusTtsSettings = { serverBin: "/usr/lib/ollama/llama-server", libraryPath: "/usr/lib/ollama", ggmlBackendPath: "/usr/lib/ollama/vulkan/libggml-vulkan.so", port: 8799, gpuLayers: 99, contextSize: 8192, startTimeoutSeconds: 150, idleStopSeconds: 5, heavyEstimateMB: 4000, takes: 3, tagCheck: false, }; export const ORPHEUS_TTS_SETTINGS_FIELD_DOCS: FieldDocs = { serverBin: "The llama.cpp server Orpheus runs on (`llama-server`). Default: Ollama's bundled build. " + "Started for a batch of syntheses on the `tts` queue and stopped (SIGTERM, then SIGKILL " + "after 15 s) once the queue has been idle `idleStopSeconds`, so its VRAM is freed.", libraryPath: "`LD_LIBRARY_PATH` for the server (Ollama's bundled libraries). Blank = not set.", ggmlBackendPath: "`GGML_BACKEND_PATH` for the server: the ggml backend it loads — Vulkan by default. Blank = not set.", port: "The port the server listens on, on 127.0.0.1. A port something else already answers on is refused, never shared.", gpuLayers: "`-ngl`: layers on the GPU. 99 = all of them; 0 runs on the CPU (about 9× slower).", contextSize: "`-c`, the context in tokens; also the whole window the repeat penalty could see.", startTimeoutSeconds: "How long the server may take to answer `/health` once it is running (it took 2.5–14 s in the " + "tuning round). The wait for the machine's heavy slot before it starts is not counted.", idleStopSeconds: "How long the server is kept after the last synthesis before it is stopped, so the next one in the queue reuses it.", heavyEstimateMB: "The memory the server is admitted to the heavy slot with (`queue-lock --heavy --estimate`): it " + "starts only when that much is free above the floor, beside other estimated jobs, never beside a build.", takes: "Takes per chunk, at most: the first that passes the checks (end token reached, no malformed frame, " + "not truncated, words a second in band, no long silence) is kept. 1–6.", tagCheck: "The tag-length check: a chunk with expressive tags must run at least 0.4 s a tag longer than the " + "same voice reading it without them (one extra take of the stripped text per tagged chunk), else the " + "take is taken to have skipped its tag. OFF by default. (The tuning round's UTMOS scorer is not " + "offered: it needs torch.)", }; export const DEFAULT_TTS_SETTINGS: TtsSettings = { engine: DEFAULT_TTS_ENGINE_ID, voice: DEFAULT_TTS_VOICE, speed: 1, home: "", dir: "", orpheus: DEFAULT_ORPHEUS_TTS_SETTINGS, }; export const TTS_SETTINGS_FIELD_DOCS: FieldDocs = { engine: "The engine a synthesis uses when the request names none: `kokoro` (Kokoro-82M, " + "Apache-2.0, CPU; installed by `archilyzer tts setup`), `orpheus` (Orpheus 3B, " + "Llama 3.2 Community License + Apache-2.0, \"Built with Llama\"; GPU, on a local " + "llama-server — `tts.orpheus`; `archilyzer tts setup --engine orpheus`) or " + "`espeak-ng` (the zero-install fallback). An unknown id falls back to `kokoro`.", voice: "The engine's stock voice when the request names none (stock voices only: no " + "cloning, no reference audio). For Kokoro, `a*` voices are American English and " + "`b*` British; `af_heart` was picked by ear in the release 25 bake-off. Orpheus: " + "tara leah jess leo dan mia zac zoe — `zac` its default, `leah` the female option. A voice the " + "engine does not have falls back to the engine's default.", speed: "Speaking pace, 1 = the engine's natural pace (Kokoro speaks briskly; 0.9 slows it). " + "Clamped to the engine's range: [0.5, 2] for Kokoro and espeak-ng; Orpheus has none (1). " + "In the cache key: a new speed is a new synthesis.", home: "Where `archilyzer tts setup` installs engines, one directory per engine " + "(`/kokoro`: its python venv and model files). Blank = " + "`~/.local/share/archilyzer/tts`. Absolute, or `~/`-relative.", dir: "The synthesis cache: `.wav` (48 kHz mono 16-bit) and a `.json` " + "sidecar (engine, model, licence, voice, seconds, disclosure) per distinct (engine, " + "model, voice, speed, normalized text) — a re-ask is free. Never inside the corpus " + "(refused). Blank = `/.tts/cache` (gitignored). Absolute, or `~/`-relative.", orpheus: "Orpheus 3B's server and takes. See OrpheusTtsSettings (`tts.orpheus` below).", }; // "" (the default), an absolute path, or a `~/` one; anything else is "". function dirSetting(value: unknown): string { if (typeof value !== "string") return ""; const s = value.trim(); if (s === "" || path.isAbsolute(s) || s.startsWith("~/")) return s; return ""; } export function sanitizeTts(value: unknown): TtsSettings { const d = DEFAULT_TTS_SETTINGS; const r = value && typeof value === "object" ? (value as Record) : {}; const engine = getTtsEngine(typeof r.engine === "string" ? r.engine.trim() : undefined) ?? getTtsEngine(d.engine)!; const voice = typeof r.voice === "string" && engine.voices.includes(r.voice.trim()) ? r.voice.trim() : engine.defaultVoice; // Within the engine's range (Orpheus has no speed control: always 1). const [lo, hi] = engine.speedRange; const speed = Math.min( hi, Math.max(lo, typeof r.speed === "number" && Number.isFinite(r.speed) ? Math.round(r.speed * 100) / 100 : d.speed), ); return { engine: engine.id, voice, speed, home: dirSetting(r.home), dir: dirSetting(r.dir), orpheus: sanitizeOrpheus(r.orpheus), }; } function int(value: unknown, fallback: number, min: number, max: number): number { const n = typeof value === "number" && Number.isFinite(value) ? Math.round(value) : fallback; return Math.min(max, Math.max(min, n)); } // An absolute path, or "" where blank is allowed; anything else is the default. function absPath(value: unknown, fallback: string, blankOk: boolean): string { if (typeof value !== "string") return fallback; const s = value.trim(); if (s === "") return blankOk ? "" : fallback; return path.isAbsolute(s) ? s : fallback; } export function sanitizeOrpheus(value: unknown): OrpheusTtsSettings { const d = DEFAULT_ORPHEUS_TTS_SETTINGS; const r = value && typeof value === "object" ? (value as Record) : {}; return { serverBin: absPath(r.serverBin, d.serverBin, false), libraryPath: absPath(r.libraryPath, d.libraryPath, true), ggmlBackendPath: absPath(r.ggmlBackendPath, d.ggmlBackendPath, true), port: int(r.port, d.port, 1024, 65535), gpuLayers: int(r.gpuLayers, d.gpuLayers, 0, 999), contextSize: int(r.contextSize, d.contextSize, 2048, 131072), startTimeoutSeconds: int(r.startTimeoutSeconds, d.startTimeoutSeconds, 5, 3600), idleStopSeconds: int(r.idleStopSeconds, d.idleStopSeconds, 0, 3600), heavyEstimateMB: int(r.heavyEstimateMB, d.heavyEstimateMB, 0, 65536), takes: int(r.takes, d.takes, 1, 6), tagCheck: r.tagCheck === true, }; } function expand(p: string): string { return p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : path.resolve(p); } /** Where engines are installed: settings.tts.home, else paths.ttsHome. */ export function resolveTtsHome(tts: Pick, paths: Pick): string { return tts.home ? expand(tts.home) : paths.ttsHome; } /** The synthesis cache: settings.tts.dir, else paths.ttsCacheDir. */ export function resolveTtsCacheDir(tts: Pick, paths: Pick): string { return tts.dir ? expand(tts.dir) : paths.ttsCacheDir; }