commit 0a4ea8288d3eeac8d50d96960c07012d52873720
parent ce47ea7627d3afdfb7bffcff8fc38fedbd39ce4f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 00:50:02 -0400
tts: `archilyzer tts setup` and the doctor's engine check
`archilyzer tts setup` installs Kokoro under settings.tts.home/kokoro: a venv
(uv venv --python 3.12 when uv is on PATH, else --python <py> -m venv) with
kokoro-onnx==0.6.1, and the two model files downloaded once from the
kokoro-onnx model-files-v1.0 release — one stream each, no retries, verified
by size and sha256 before they are moved into place. --from <dir> takes
already-downloaded files (hard links, else copies, verified the same way);
--check lists what is missing and installs nothing. The doctor reports the
configured engine and voice: installed (ok) or not (a note, never a failure).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 466 insertions(+), 0 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -68,6 +68,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer docs files` | `[--check]` | write SITE.md + CHANNEL.md + REPORT.md + CITATIONS.md from the file schemas |
| `archilyzer docs cli` | `[--check]` | write COMMANDS.md from this command table and `pnpm ops --help` |
| `archilyzer settings example` | `[--check]` | write settings.json.example + SETTINGS.md from the schema |
+| `archilyzer tts setup` | `[--engine kokoro\|espeak-ng] [--from <dir>] [--python <py>] [--check]` | install a text-to-speech engine under settings.tts.home/<engine> (default ~/.local/share/archilyzer/tts/kokoro): a python venv with the pinned kokoro-onnx (uv venv --python 3.12 when uv is on PATH, else --python <py> -m venv) and the two model files, downloaded once from the kokoro-onnx project's model-files-v1.0 release (one stream, no retries) and verified by size and sha256; --from <dir> takes already-downloaded model files from <dir> instead (hard links where it can, else copies; verified the same way); --check installs nothing, lists what is missing and exits 1 when anything is |
| `archilyzer doctor` | `[--json]` | read-only report: node, the checkout, the corpus, settings, every tool, the port block; exit 1 on a failure |
| `archilyzer release show` | `[editor\|export]` | latest release, its date, how many bullets wait under \[Unreleased\] |
| `archilyzer release cut` | `<editor\|export\|all> <X.Y.Z\|next\|next-minor> [--commit] [--date YYYY-MM-DD]` | \[Unreleased\] -> a dated heading; all = both, one version, two commits |
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -710,6 +710,20 @@ export const COMMANDS: Command[] = [
run: async ({ flags }) =>
(await import("./settings-example")).main({ check: flags.check === true }),
},
+ // Text-to-speech (release 25): install an engine for `pnpm ops tts`.
+ {
+ path: ["tts", "setup"],
+ usage:
+ "[--engine kokoro|espeak-ng] [--from <dir>] [--python <py>] [--check] install a text-to-speech engine under settings.tts.home/<engine> (default ~/.local/share/archilyzer/tts/kokoro): a python venv with the pinned kokoro-onnx (uv venv --python 3.12 when uv is on PATH, else --python <py> -m venv) and the two model files, downloaded once from the kokoro-onnx project's model-files-v1.0 release (one stream, no retries) and verified by size and sha256; --from <dir> takes already-downloaded model files from <dir> instead (hard links where it can, else copies; verified the same way); --check installs nothing, lists what is missing and exits 1 when anything is",
+ flags: { engine: "string", from: "string", python: "string", check: "boolean" },
+ run: async ({ flags }) =>
+ (await import("./tts-setup")).main({
+ ...(typeof flags.engine === "string" ? { engine: flags.engine } : {}),
+ ...(typeof flags.from === "string" ? { from: flags.from } : {}),
+ ...(typeof flags.python === "string" ? { python: flags.python } : {}),
+ check: flags.check === true,
+ }),
+ },
{
path: ["doctor"],
usage:
diff --git a/common/bin/doctor.test.ts b/common/bin/doctor.test.ts
@@ -997,3 +997,26 @@ test("seeder: the same egress as the host fails; a different one is ok; an unans
assert.equal(find(down, "seeder", "egress")?.status, "warn");
assert.match(find(down, "seeder", "egress")!.detail, /No such container.*profile up/);
});
+
+// ── release 25: text-to-speech ──────────────────────────────────────────────
+
+test("tts: not installed is a note naming the setup; installed is ok; never a failure", async () => {
+ const c = checkout();
+ const home = path.join(c.root, "tts-home");
+ writeFileSync(c.paths.settingsFile, JSON.stringify({ tts: { home } }));
+ const before = tree(c.root);
+ const none = await run(c, {});
+ const row = find(none, "tts", "engine");
+ assert.equal(row?.status, "info");
+ assert.match(row!.detail, /kokoro · af_heart not installed \(.*tts-home\/kokoro: missing the python venv .*kokoro-v1\.0\.onnx; voices-v1\.0\.bin\) — `archilyzer tts setup` installs it/);
+ assert.deepEqual(tree(c.root), before, "the probe stats, never creates");
+ const ok = await run(c, {}, {
+ ttsState: async () => ({ engine: "kokoro", voice: "bm_george", voiceOk: true, dir: "/h/kokoro", installed: true, missing: [] }),
+ });
+ assert.equal(find(ok, "tts", "engine")?.status, "ok");
+ assert.match(find(ok, "tts", "engine")!.detail, /kokoro · bm_george installed \(\/h\/kokoro\)/);
+ const badVoice = await run(c, {}, {
+ ttsState: async () => ({ engine: "kokoro", voice: "x", voiceOk: false, dir: "/h/kokoro", installed: true, missing: [] }),
+ });
+ assert.equal(find(badVoice, "tts", "engine")?.status, "warn");
+});
diff --git a/common/bin/doctor.ts b/common/bin/doctor.ts
@@ -105,6 +105,18 @@ export type DoctorDeps = {
// The host's egress IP and the seeder container's, asked only when the
// seeder is configured. Default: probeSeederEgress.
seederEgress?: () => Promise<SeederEgressProbe>;
+ // The configured text-to-speech engine's install state. Default: settings.tts
+ // through lib/ttsInstall.ts (stats only).
+ ttsState?: () => Promise<TtsDoctorState>;
+};
+
+export type TtsDoctorState = {
+ engine: string;
+ voice: string;
+ voiceOk: boolean;
+ dir: string;
+ installed: boolean;
+ missing: string[];
};
// What `archilyzer doctor` learned of the seeder's way out: each egress IP, or
@@ -801,6 +813,44 @@ export async function collectDoctorReport(deps: DoctorDeps): Promise<DoctorRepor
}
}
+ // ── text-to-speech (release 25) ──────────────────────────────────────────
+ // The configured engine and voice (settings.tts): installed or not. Never a
+ // failure — narration is asked for, never run on its own, and a clone with no
+ // engine is a complete archive — so "not installed" is a note naming
+ // `archilyzer tts setup`. Presence only (lib/ttsInstall.ts): the venv and
+ // each model file at its pinned size; `tts setup --check` imports the package.
+ const TS = "tts";
+ if (settings) {
+ try {
+ const state = await (deps.ttsState ?? (async () => {
+ const { getTtsEngine } = await import("../lib/ttsApps");
+ const { ttsInstallState } = await import("../lib/ttsInstall");
+ const { resolveTtsHome } = await import("../lib/ttsSettings");
+ const engine = getTtsEngine(settings!.tts.engine)!;
+ const home = resolveTtsHome(settings!.tts, {
+ ttsHome: paths.ttsHome ?? path.join(os.homedir(), ".local", "share", "archilyzer", "tts"),
+ });
+ const voiceOk = engine.voices.includes(settings!.tts.voice);
+ return {
+ ...ttsInstallState(engine, { home, paths: { espeakNgBin: paths.espeakNgBin ?? "espeak-ng" }, envPath: env.PATH }),
+ voice: settings!.tts.voice,
+ voiceOk,
+ };
+ }))();
+ const what = `${state.engine} · ${state.voice}`;
+ if (!state.voiceOk) {
+ add(TS, "engine", "warn", `${what}: ${state.engine} has no such stock voice`);
+ } else if (state.installed) {
+ add(TS, "engine", "ok", `${what} installed (${state.dir})`);
+ } else {
+ add(TS, "engine", "info",
+ `${what} not installed (${state.dir}: missing ${state.missing.join("; ")}) — \`archilyzer tts setup\` installs it; narration only`);
+ }
+ } catch (e) {
+ add(TS, "engine", "info", `could not be checked: ${(e as Error).message}`);
+ }
+ }
+
// ── ports ────────────────────────────────────────────────────────────────
const P = "ports";
const block = await (deps.portBlock ?? (() => worktreePortBlock(root)))();
diff --git a/common/bin/tts-setup.test.ts b/common/bin/tts-setup.test.ts
@@ -0,0 +1,115 @@
+import { test, after } from "node:test";
+import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
+import { mkdtemp, mkdir, readdir, rm, stat, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+import { adoptModelFile, downloadModelFile, main, verifyModelFile } from "./tts-setup";
+import type { TtsModelFile } from "../lib/ttsApps";
+
+// Run with:
+// pnpm --filter yt-dlp-transcript-common exec tsx --test bin/tts-setup.test.ts
+//
+// `archilyzer tts setup`'s pieces over a tiny synthetic "model": verification
+// by size and sha256, the one-stream download (a fake fetch — nothing here
+// touches the network), `--from` adoption, and `--check` over an empty home.
+// The real install (a venv, kokoro-onnx, 350 MB of model) is run by hand.
+
+const ROOT = await mkdtemp(path.join(os.tmpdir(), "tts-setup-"));
+after(() => rm(ROOT, { recursive: true, force: true }));
+
+const BYTES = Buffer.from("not a real model, ".repeat(64));
+const SPEC: TtsModelFile = {
+ name: "tiny.onnx",
+ url: "https://example.invalid/tiny.onnx",
+ bytes: BYTES.length,
+ sha256: createHash("sha256").update(BYTES).digest("hex"),
+};
+
+function fakeFetch(body: Buffer, status = 200): typeof fetch {
+ const calls: string[] = [];
+ const f = (async (url: string | URL | Request) => {
+ calls.push(String(url));
+ return new Response(status === 200 ? new Uint8Array(body) : null, { status });
+ }) as unknown as typeof fetch;
+ return Object.assign(f, { calls });
+}
+
+test("a file verifies by size, then sha256", async () => {
+ const dir = await mkdtemp(path.join(ROOT, "verify-"));
+ const f = path.join(dir, SPEC.name);
+ assert.equal(await verifyModelFile(f, SPEC), "absent");
+ await writeFile(f, BYTES.subarray(1));
+ assert.match(await verifyModelFile(f, SPEC), /bytes, expected/);
+ const bad = Buffer.from(BYTES);
+ bad[0] ^= 1;
+ await writeFile(f, bad);
+ assert.match(await verifyModelFile(f, SPEC), /^sha256 .* expected/);
+ await writeFile(f, BYTES);
+ assert.equal(await verifyModelFile(f, SPEC), "ok");
+});
+
+test("a download is one stream, verified before it is moved into place", async () => {
+ const dir = await mkdtemp(path.join(ROOT, "dl-"));
+ const target = path.join(dir, SPEC.name);
+ const lines: string[] = [];
+ const ok = fakeFetch(BYTES);
+ await downloadModelFile(SPEC, target, (l) => lines.push(l), ok);
+ assert.equal(await verifyModelFile(target, SPEC), "ok");
+ assert.deepEqual((ok as unknown as { calls: string[] }).calls, [SPEC.url]);
+ assert.deepEqual(await readdir(dir), [SPEC.name]);
+ assert.ok(lines.some((l) => /100%/.test(l)), lines.join("\n"));
+
+ // A body that does not verify is not kept, and is not retried.
+ const corrupt = Buffer.from(BYTES);
+ corrupt[3] ^= 1;
+ const other = path.join(dir, "other.onnx");
+ const bad = fakeFetch(corrupt);
+ await assert.rejects(downloadModelFile(SPEC, other, () => {}, bad), /does not verify/);
+ assert.equal((bad as unknown as { calls: string[] }).calls.length, 1);
+ assert.deepEqual(await readdir(dir), [SPEC.name]);
+ // A server error is an error, once.
+ await assert.rejects(downloadModelFile(SPEC, other, () => {}, fakeFetch(BYTES, 503)), /answered 503/);
+});
+
+test("--from adopts a verified file (a hard link), and refuses one that is not", async () => {
+ const src = await mkdtemp(path.join(ROOT, "from-"));
+ const dst = await mkdtemp(path.join(ROOT, "to-"));
+ await writeFile(path.join(src, SPEC.name), BYTES);
+ const lines: string[] = [];
+ assert.equal(await adoptModelFile(path.join(src, SPEC.name), path.join(dst, SPEC.name), SPEC, (l) => lines.push(l)), true);
+ const a = await stat(path.join(src, SPEC.name));
+ const b = await stat(path.join(dst, SPEC.name));
+ assert.equal(a.ino, b.ino, "a hard link on the same filesystem");
+ assert.match(lines.join("\n"), /linked tiny\.onnx/);
+ await writeFile(path.join(src, "short.onnx"), BYTES.subarray(2));
+ assert.equal(
+ await adoptModelFile(path.join(src, "short.onnx"), path.join(dst, "short.onnx"), SPEC, () => {}),
+ false,
+ );
+ assert.deepEqual(await readdir(dst), [SPEC.name]);
+});
+
+test("--check over an empty home lists what is missing, installs nothing, exits 1", async () => {
+ const home = path.join(ROOT, "empty-home");
+ await mkdir(home);
+ const lines: string[] = [];
+ const code = await main({ check: true, home, log: (l) => lines.push(l) });
+ assert.equal(code, 1);
+ const text = lines.join("\n");
+ assert.match(text, /Kokoro-82M at .*empty-home\/kokoro — missing:/);
+ assert.match(text, /- the python venv/);
+ assert.match(text, /- kokoro-v1\.0\.onnx/);
+ assert.match(text, /- voices-v1\.0\.bin/);
+ assert.match(text, /Run `archilyzer tts setup`/);
+ assert.deepEqual(await readdir(home), []);
+});
+
+test("an unknown engine is refused; espeak-ng has nothing to install", async () => {
+ const lines: string[] = [];
+ assert.equal(await main({ engine: "piper", log: (l) => lines.push(l) }), 2);
+ assert.match(lines[0], /no engine "piper" — known: kokoro, espeak-ng/);
+ const missing: string[] = [];
+ assert.equal(await main({ engine: "espeak-ng", envPath: path.join(ROOT, "no-bin"), log: (l) => missing.push(l) }), 1);
+ assert.match(missing[0], /espeak-ng is not on PATH — install espeak-ng/);
+});
diff --git a/common/bin/tts-setup.ts b/common/bin/tts-setup.ts
@@ -0,0 +1,263 @@
+// `archilyzer tts setup` — install a text-to-speech engine (release 25 T1).
+//
+// For Kokoro (a `python-venv` engine, lib/ttsApps.ts) it builds, under
+// `<settings.tts.home>/kokoro` (default ~/.local/share/archilyzer/tts/kokoro):
+// venv/ a python venv with the pinned package
+// (kokoro-onnx==0.6.1) — made by `uv venv --python
+// 3.12` when uv is on PATH, else `<--python> -m venv`
+// kokoro-v1.0.onnx the model files, downloaded ONCE from the
+// voices-v1.0.bin kokoro-onnx project's `model-files-v1.0` release
+// install.json what was installed, and when
+//
+// POLITE: one download at a time, one stream each, no retry loop — a failed
+// download is reported and the next run resumes nothing (it starts the file
+// again). Every file is verified by size and sha256 before it is moved into
+// place; a file already there and verified is never fetched again. `--from
+// <dir>` takes the files from a directory that already holds them (hard
+// links where the filesystem allows, else copies), verified the same way —
+// for a machine that downloaded them once already.
+//
+// `--check` installs nothing: it lists what is missing (the venv, the package
+// at its pinned version — by importing it — each model file at its size) and
+// exits 1 when anything is.
+//
+// espeak-ng (a `system` engine) has nothing to install: setup says whether it
+// is on PATH.
+//
+// Scratch (pip's build dirs) goes to `<install dir>/.tmp`, never the OS temp
+// dir: it may be a small RAM tmpfs.
+
+import { createHash } from "node:crypto";
+import { createReadStream, createWriteStream } from "node:fs";
+import { copyFile, link, mkdir, rename, rm, stat } from "node:fs/promises";
+import path from "node:path";
+import { Readable } from "node:stream";
+import { pipeline } from "node:stream/promises";
+import { execa } from "execa";
+import { getPaths } from "../lib/paths";
+import { getSettings } from "../lib/settings";
+import {
+ DEFAULT_TTS_ENGINE_ID,
+ getTtsEngine,
+ ttsEngineIds,
+ ttsInstallDir,
+ ttsVenvPython,
+ type TtsModelFile,
+} from "../lib/ttsApps";
+import { findOnPath, ttsInstallState } from "../lib/ttsInstall";
+import { resolveTtsHome } from "../lib/ttsSettings";
+import { writeJsonAtomic } from "../lib/jsonFile-server";
+
+export type TtsSetupOptions = {
+ engine?: string;
+ from?: string;
+ python?: string;
+ check?: boolean;
+ // Injected by tests.
+ home?: string;
+ log?: (line: string) => void;
+ fetch?: typeof fetch;
+ envPath?: string;
+};
+
+async function sha256File(file: string): Promise<string> {
+ const h = createHash("sha256");
+ await pipeline(createReadStream(file), h);
+ return h.digest("hex");
+}
+
+// "ok" when `file` is the pinned file (size, then sha256), else why not.
+export async function verifyModelFile(file: string, spec: TtsModelFile): Promise<"ok" | string> {
+ const st = await stat(file).catch(() => null);
+ if (!st?.isFile()) return "absent";
+ if (st.size !== spec.bytes) return `${st.size} bytes, expected ${spec.bytes}`;
+ const sha = await sha256File(file);
+ return sha === spec.sha256 ? "ok" : `sha256 ${sha.slice(0, 12)}…, expected ${spec.sha256.slice(0, 12)}…`;
+}
+
+function mb(n: number): string {
+ return `${(n / 1_000_000).toFixed(1)} MB`;
+}
+
+// One stream to `<target>.part`, verified, then renamed. No retries.
+export async function downloadModelFile(
+ spec: TtsModelFile,
+ target: string,
+ log: (l: string) => void,
+ doFetch: typeof fetch,
+): Promise<void> {
+ const part = `${target}.part`;
+ log(` downloading ${spec.url} (${mb(spec.bytes)})…`);
+ const res = await doFetch(spec.url, { redirect: "follow" });
+ if (!res.ok || !res.body) throw new Error(`${spec.url} answered ${res.status}`);
+ let got = 0;
+ let nextReport = 0.25;
+ const counted = Readable.fromWeb(res.body as import("node:stream/web").ReadableStream).on("data", (c: Buffer) => {
+ got += c.length;
+ if (got / spec.bytes >= nextReport) {
+ log(` ${Math.round((got / spec.bytes) * 100)}%`);
+ nextReport += 0.25;
+ }
+ });
+ try {
+ await pipeline(counted, createWriteStream(part));
+ const v = await verifyModelFile(part, spec);
+ if (v !== "ok") throw new Error(`${spec.name} downloaded but does not verify (${v})`);
+ await rename(part, target);
+ } catch (e) {
+ await rm(part, { force: true }).catch(() => {});
+ throw e;
+ }
+}
+
+// From `--from`: a hard link when the filesystem allows, else a copy.
+export async function adoptModelFile(src: string, target: string, spec: TtsModelFile, log: (l: string) => void): Promise<boolean> {
+ const v = await verifyModelFile(src, spec);
+ if (v !== "ok") {
+ log(` ${src}: ${v} — not used`);
+ return false;
+ }
+ await rm(target, { force: true });
+ try {
+ await link(src, target);
+ log(` linked ${spec.name} from ${path.dirname(src)}`);
+ } catch {
+ const part = `${target}.part`;
+ await copyFile(src, part);
+ await rename(part, target);
+ log(` copied ${spec.name} from ${path.dirname(src)}`);
+ }
+ return true;
+}
+
+// The pinned package's installed version, or null when it does not import.
+async function installedVersion(python: string, importName: string, dist: string): Promise<string | null> {
+ try {
+ const { stdout } = await execa(python, [
+ "-c",
+ `import ${importName}, importlib.metadata as m; print(m.version(${JSON.stringify(dist)}))`,
+ ]);
+ return stdout.trim() || null;
+ } catch {
+ return null;
+ }
+}
+
+export async function main(opts: TtsSetupOptions = {}): Promise<number> {
+ const log = opts.log ?? ((l: string) => console.log(l));
+ const engineId = opts.engine ?? DEFAULT_TTS_ENGINE_ID;
+ const engine = getTtsEngine(engineId);
+ if (!engine) {
+ log(`tts setup: no engine "${engineId}" — known: ${ttsEngineIds().join(", ")}`);
+ return 2;
+ }
+ const paths = getPaths();
+ const envPath = opts.envPath ?? process.env.PATH;
+ const setup = engine.setup;
+
+ if (setup.kind === "system") {
+ const found = findOnPath(paths[setup.bin], envPath);
+ log(found ? `${engine.label}: ${found} — nothing to install` : `${engine.label}: ${paths[setup.bin]} is not on PATH — ${setup.hint}`);
+ return found ? 0 : 1;
+ }
+
+ const home = opts.home ?? resolveTtsHome(getSettings().tts, paths);
+ const dir = ttsInstallDir(home, engine);
+ const python = ttsVenvPython(dir);
+ const [dist, pinned] = setup.packages[0].split("==");
+
+ if (opts.check) {
+ const state = ttsInstallState(engine, { home, paths, envPath });
+ const missing = [...state.missing];
+ if (!missing.some((m) => m.startsWith("the python venv"))) {
+ const v = await installedVersion(python, setup.importName, dist);
+ if (v !== pinned) missing.push(v ? `${dist} ${v} (pinned ${pinned})` : `${dist} does not import in the venv`);
+ }
+ if (missing.length === 0) {
+ log(`${engine.label}: installed at ${dir} (${dist} ${pinned}, ${setup.files.map((f) => f.name).join(", ")})`);
+ return 0;
+ }
+ log(`${engine.label} at ${dir} — missing:`);
+ for (const m of missing) log(` - ${m}`);
+ log("Run `archilyzer tts setup` to install it.");
+ return 1;
+ }
+
+ log(`Installing ${engine.label} at ${dir}`);
+ const scratch = path.join(dir, ".tmp");
+ await mkdir(scratch, { recursive: true });
+ const env = { TMPDIR: scratch, PIP_DISABLE_PIP_VERSION_CHECK: "1", NO_COLOR: "1" };
+ const uv = findOnPath("uv", envPath);
+ const run = async (cmd: string, args: string[]) => {
+ log(` $ ${[cmd, ...args].join(" ")}`);
+ const child = execa(cmd, args, { env, all: true, buffer: false });
+ let pending = "";
+ child.all?.on("data", (c: Buffer) => {
+ pending += c.toString("utf8");
+ const lines = pending.split("\n");
+ pending = lines.pop() ?? "";
+ for (const l of lines) if (l.trim()) log(` ${l.trimEnd()}`);
+ });
+ await child;
+ if (pending.trim()) log(` ${pending.trimEnd()}`);
+ };
+
+ try {
+ // 1. The venv.
+ if ((await stat(python).catch(() => null)) === null) {
+ const venv = path.join(dir, "venv");
+ if (opts.python) await run(opts.python, ["-m", "venv", venv]);
+ else if (uv) await run(uv, ["venv", "--python", setup.python, venv]);
+ else await run("python3", ["-m", "venv", venv]);
+ } else {
+ log(` venv present (${python})`);
+ }
+
+ // 2. The pinned package.
+ const have = await installedVersion(python, setup.importName, dist);
+ if (have === pinned) {
+ log(` ${dist} ${pinned} present`);
+ } else if (uv && !opts.python) {
+ await run(uv, ["pip", "install", "--python", python, ...setup.packages]);
+ } else {
+ await run(python, ["-m", "pip", "install", ...setup.packages]);
+ }
+
+ // 3. The model files, one at a time.
+ for (const spec of setup.files) {
+ const target = path.join(dir, spec.name);
+ if ((await verifyModelFile(target, spec)) === "ok") {
+ log(` ${spec.name} present and verified`);
+ continue;
+ }
+ if (opts.from && (await adoptModelFile(path.join(path.resolve(opts.from), spec.name), target, spec, log))) continue;
+ await downloadModelFile(spec, target, log, opts.fetch ?? fetch);
+ log(` ${spec.name} downloaded and verified`);
+ }
+ } catch (e) {
+ log(`tts setup failed: ${(e as Error).message}`);
+ return 1;
+ } finally {
+ await rm(scratch, { recursive: true, force: true }).catch(() => {});
+ }
+
+ const version = await installedVersion(python, setup.importName, dist);
+ if (version !== pinned) {
+ log(`tts setup: ${dist} does not import at ${pinned} in ${python} (got ${version ?? "nothing"})`);
+ return 1;
+ }
+ await writeJsonAtomic(
+ path.join(dir, "install.json"),
+ {
+ engine: engine.id,
+ model: engine.model,
+ license: engine.license,
+ packages: setup.packages,
+ files: setup.files.map((f) => ({ name: f.name, bytes: f.bytes, sha256: f.sha256, url: f.url })),
+ installedAt: new Date().toISOString(),
+ },
+ { indent: 2 },
+ );
+ log(`${engine.label} installed: ${dir}`);
+ return 0;
+}