// IS A VOICE ENGINE INSTALLED? (release 39) — lib/ttsInstall.ts's twin. // // One answer, read by two callers: controller/voiceFile.ts refuses an op for // an engine that is not (a 400 naming `archilyzer voice setup`, before any job // exists — and umtool reads "not installed" in it), and `archilyzer voice // setup --check` lists what is missing. Presence only: the venv's interpreter, // the pinned checkout's marker, each file at its pinned size (an executable // one executable); setup's `--check` goes further and imports the package and // reads the checkout's commit. Read-only: never creates anything. // // An engine's OPTIONAL file groups (seed-vc's `f0`: the model a followed pitch // runs on) are reported beside, never counted: `installed` is the required // files alone, so an install made before a group existed is still installed. import fs from "node:fs"; import path from "node:path"; import { voiceCodeDir, voiceInstallDir, voiceVenvPython, type VoiceEngine, type VoiceModelFile } from "./voiceApps"; export type VoiceInstallState = { engine: string; dir: string; installed: boolean; missing: string[]; // Each optional group: there whole, or what of it is missing. optional: VoiceGroupState[]; }; export type VoiceGroupState = { id: string; label: string; installed: boolean; missing: string[] }; function missingFiles(dir: string, files: readonly VoiceModelFile[]): string[] { const missing: string[] = []; for (const f of files) { const p = path.join(dir, f.name); let st: fs.Stats | null = null; try { st = fs.statSync(p); } catch { st = null; } if (!st) missing.push(f.name); else if (st.size !== f.bytes) missing.push(`${f.name} (${st.size} bytes, expected ${f.bytes})`); else if (f.executable && (st.mode & 0o111) === 0) missing.push(`${f.name} (not executable)`); } return missing; } /** One optional group of an engine's install, or undefined when the engine has none by that id. */ export function voiceGroupState(engine: VoiceEngine, group: string, opts: { home: string }): VoiceGroupState | undefined { const g = engine.setup.kind === "python-venv" ? engine.setup.optional?.find((x) => x.id === group) : undefined; if (!g) return undefined; const missing = missingFiles(voiceInstallDir(opts.home, engine), g.files); return { id: g.id, label: g.label, installed: missing.length === 0, missing }; } // The file a finished checkout leaves: the commit it is at. export const VOICE_CODE_MARKER = ".archilyzer-commit"; export function voiceInstallState( engine: VoiceEngine, opts: { home: string; voiceModelsDir: string }, ): VoiceInstallState { const setup = engine.setup; if (setup.kind === "bundled") { const model = path.join(opts.voiceModelsDir, "sh.rnnn"); const ok = fs.existsSync(model); return { engine: engine.id, dir: opts.voiceModelsDir, installed: ok, missing: ok ? [] : [`${model} (shipped in the repo)`], optional: [] }; } const dir = voiceInstallDir(opts.home, engine); const missing: string[] = []; if (setup.kind === "python-venv") { const python = voiceVenvPython(dir); if (!fs.existsSync(python)) missing.push(`the python venv (${python})`); let at: string | null = null; try { at = fs.readFileSync(path.join(voiceCodeDir(dir), VOICE_CODE_MARKER), "utf8").trim(); } catch { at = null; } if (at !== setup.code.commit) { missing.push(at ? `the checkout of ${setup.code.repo} is at ${at.slice(0, 10)}, pinned ${setup.code.commit.slice(0, 10)}` : `the checkout of ${setup.code.repo} (${voiceCodeDir(dir)})`); } } missing.push(...missingFiles(dir, setup.files)); const optional = (setup.kind === "python-venv" ? setup.optional ?? [] : []).map((g) => voiceGroupState(engine, g.id, opts)!); return { engine: engine.id, dir, installed: missing.length === 0, missing, optional }; }