// IS A TEXT-TO-SPEECH ENGINE INSTALLED? (release 25 T1) // // One answer, read by three callers: controller/ttsFile.ts refuses a synthesis // for an engine that is not (a 400 naming `archilyzer tts setup`, before any // job exists), `archilyzer doctor` reports it, and `archilyzer tts setup // --check` lists what is missing. Presence only — the venv's interpreter and // each model file at its pinned size; setup's `--check` goes further and // imports the package. Read-only: never creates anything. import fs from "node:fs"; import path from "node:path"; import type { Paths } from "./paths"; import { ttsInstallDir, ttsVenvPython, type TtsEngine } from "./ttsApps"; import type { TtsSettings } from "./ttsSettings"; export type TtsInstallState = { engine: string; // `/`, or the system binary for a `system` engine. dir: string; installed: boolean; // One line per missing piece, in words. missing: string[]; }; // A binary named without a slash, looked up on PATH; with one, as a path. export function findOnPath(bin: string, envPath: string | undefined = process.env.PATH): string | null { const isExec = (p: string) => { try { const st = fs.statSync(p); if (!st.isFile()) return false; fs.accessSync(p, fs.constants.X_OK); return true; } catch { return false; } }; if (bin.includes("/")) return isExec(bin) ? bin : null; for (const dir of (envPath ?? "").split(path.delimiter)) { if (!dir) continue; const p = path.join(dir, bin); if (isExec(p)) return p; } return null; } export function ttsInstallState( engine: TtsEngine, opts: { home: string; paths: Pick; envPath?: string; tts?: TtsSettings }, ): TtsInstallState { const setup = engine.setup; if (setup.kind === "system") { const bin = opts.paths[setup.bin]; const found = findOnPath(bin, opts.envPath ?? process.env.PATH); return { engine: engine.id, dir: found ?? bin, installed: found !== null, missing: found ? [] : [`${bin} is not on PATH — ${setup.hint}`], }; } const dir = ttsInstallDir(opts.home, engine); const missing: string[] = []; const python = ttsVenvPython(dir); if (!fs.existsSync(python)) missing.push(`the python venv (${python})`); for (const f of setup.files) { const p = path.join(dir, f.name); let size: number | null = null; try { size = fs.statSync(p).size; } catch { size = null; } if (size === null) missing.push(`${f.name}`); else if (size !== f.bytes) missing.push(`${f.name} (${size} bytes, expected ${f.bytes})`); } // Binaries outside the install dir (Orpheus's llama-server, from settings). if (engine.requires && opts.tts) { for (const r of engine.requires(opts.tts)) { if (!findOnPath(r.path, opts.envPath ?? process.env.PATH)) missing.push(`${r.what}: ${r.path}`); } } return { engine: engine.id, dir, installed: missing.length === 0, missing }; }