commit 4e33b2f59622dec5e7c4ff912091dd900034a982
parent f889ac4c1ae93a0139eef397b74222994d720a2c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 00:38:18 -0400
settings: settings.tts, the TTS paths and their env vars
settings.tts: engine (kokoro), voice (af_heart), speed (1), home (blank =
~/.local/share/archilyzer/tts, one directory per engine) and dir (blank =
<repo>/.tts/cache, gitignored). Paths gains ttsBin (TTS_BIN, the wrapper),
espeakNgBin (ESPEAK_NG_BIN) and the two defaults. SETTINGS.md,
settings.json.example and ENVIRONMENT.md regenerated.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
11 files changed, 201 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
@@ -166,6 +166,10 @@ yarn-error.log*
/settings.json
/chart-templates.json
+# Text-to-speech synthesis cache (settings.tts.dir's default, release 25):
+# <sha256>.wav + .json per distinct synthesis. Rebuildable; never committed.
+/.tts/
+
# Diarization runtime: the uv-managed python 3.13 venv + the sherpa-onnx models.
# Machine-specific (~148 MB) and rebuildable from .diarize/README.md, which IS
# tracked. sherpa-onnx ships wheels only to cp313 and this box's system python is
diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md
@@ -33,6 +33,8 @@ The one override surface for where things live and which binary runs. Every one
| `PARAKEET_CLI` | `parakeet-cli` on PATH | The parakeet.cpp binary the wrapper drives (the wrapper reads it too). | common/lib/paths.ts (getPaths) |
| `PARAKEET_MODEL` | none | parakeet.cpp's `.gguf`, when a worker names none (the wrapper reads it too). | common/lib/paths.ts (getPaths) |
| `DIARIZE_BIN` | `<repo>/scripts/diarize.mjs` | The speaker-diarization wrapper. The e2e suite swaps in a fake here. | common/lib/paths.ts (getPaths) |
+| `TTS_BIN` | `<repo>/scripts/tts.mjs` | The text-to-speech wrapper (text in, 48 kHz WAV out) every engine runs behind. A test swaps in a fake here. | common/lib/paths.ts (getPaths) |
+| `ESPEAK_NG_BIN` | `espeak-ng` on PATH | eSpeak NG, the zero-install text-to-speech engine (the wrapper reads it too). | common/lib/paths.ts (getPaths) |
| `RSYNC_BIN` | `rsync` on PATH | Mirrors the saved-video store to a backup destination. | common/lib/paths.ts (getPaths) |
| `FINDMNT_BIN` | `findmnt` on PATH | The read-only volume-identity probe behind storage locations. Optional. | common/lib/paths.ts (getPaths) |
| `UDISKSCTL_BIN` | `udisksctl` on PATH | Mounts an attached volume from `/storage`. Optional. | common/lib/paths.ts (getPaths) |
diff --git a/SETTINGS.md b/SETTINGS.md
@@ -49,6 +49,7 @@ A copied example PINS every default it spells — including each lane's `autoQue
| [`archiveOrg`](#archiveorg) | object — see below |
| [`publish`](#publish) | object — see below |
| [`seeder`](#seeder) | object — see below |
+| [`tts`](#tts) | object — see below |
## `adminTitle`
@@ -887,3 +888,29 @@ Default:
"bindInterface": ""
}
```
+
+## `tts`
+
+Local text-to-speech (release 25): narration for report videos and podcasts, synthesized as an editor job (`pnpm ops tts`, the `tts` queue, one at a time) with a STOCK voice — never a cloned one — and cached by content. The default engine is Kokoro-82M with the voice `af_heart`, installed by `archilyzer tts setup`; espeak-ng needs no install. Every synthesis is disclosed as a synthetic voice (its sidecar and the result's `disclosure`). See TtsSettings and common/controller/ttsFile.ts.
+
+#### `tts`
+
+| Key | Default | Description |
+|---|---|---|
+| `engine` | `"kokoro"` | The engine a synthesis uses when the request names none: `kokoro` (Kokoro-82M, Apache-2.0, CPU; installed by `archilyzer tts setup`) or `espeak-ng` (the zero-install fallback). An unknown id falls back to `kokoro`. |
+| `voice` | `"af_heart"` | 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. A voice the engine does not have falls back to the engine's default. |
+| `speed` | `1` | Speaking pace, 1 = the engine's natural pace (Kokoro speaks briskly; 0.9 slows it). Clamped to [0.5, 2]. In the cache key: a new speed is a new synthesis. |
+| `home` | `""` | Where `archilyzer tts setup` installs engines, one directory per engine (`<home>/kokoro`: its python venv and model files). Blank = `~/.local/share/archilyzer/tts`. Absolute, or `~/`-relative. |
+| `dir` | `""` | The synthesis cache: `<sha256>.wav` (48 kHz mono 16-bit) and a `<sha256>.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 = `<repo>/.tts/cache` (gitignored). Absolute, or `~/`-relative. |
+
+Default:
+
+```json
+{
+ "engine": "kokoro",
+ "voice": "af_heart",
+ "speed": 1,
+ "home": "",
+ "dir": ""
+}
+```
diff --git a/common/lib/envVars.ts b/common/lib/envVars.ts
@@ -74,6 +74,8 @@ const DECLARED: EnvVarDecl[] = [
paths("PARAKEET_CLI", "`parakeet-cli` on PATH", "The parakeet.cpp binary the wrapper drives (the wrapper reads it too)."),
paths("PARAKEET_MODEL", "none", "parakeet.cpp's `.gguf`, when a worker names none (the wrapper reads it too)."),
paths("DIARIZE_BIN", "`<repo>/scripts/diarize.mjs`", "The speaker-diarization wrapper. The e2e suite swaps in a fake here."),
+ paths("TTS_BIN", "`<repo>/scripts/tts.mjs`", "The text-to-speech wrapper (text in, 48 kHz WAV out) every engine runs behind. A test swaps in a fake here."),
+ paths("ESPEAK_NG_BIN", "`espeak-ng` on PATH", "eSpeak NG, the zero-install text-to-speech engine (the wrapper reads it too)."),
paths("RSYNC_BIN", "`rsync` on PATH", "Mirrors the saved-video store to a backup destination."),
paths("FINDMNT_BIN", "`findmnt` on PATH", "The read-only volume-identity probe behind storage locations. Optional."),
paths("UDISKSCTL_BIN", "`udisksctl` on PATH", "Mounts an attached volume from `/storage`. Optional."),
diff --git a/common/lib/paths.ts b/common/lib/paths.ts
@@ -152,6 +152,16 @@ export type Paths = {
// parakeetBin is. Overridable via DIARIZE_BIN — which is also how the e2e
// suite swaps in a fake diarizer.
diarizeBin: string;
+ // Text-to-speech (release 25): the wrapper every engine runs behind
+ // (scripts/tts.mjs, TTS_BIN — how a test swaps in a fake), espeak-ng (the
+ // zero-install engine), and the two defaults settings.tts falls back to when
+ // its `home`/`dir` are blank: where `archilyzer tts setup` installs engines
+ // (`<ttsHome>/<engine id>`, outside the checkout) and the synthesis cache
+ // (`<repo>/.tts/cache`, gitignored; never inside the corpus).
+ ttsBin: string;
+ espeakNgBin: string;
+ ttsHome: string;
+ ttsCacheDir: string;
// Base URL of the local ollama server, the local-GPU digest lane
// (common/lib/digestApps.ts posts to `${ollamaUrl}/api/chat`). The FIRST
// URL-valued entry in Paths, so it is normalized here the way
@@ -299,6 +309,10 @@ export function getPaths(): Paths {
diarizeBin:
process.env.DIARIZE_BIN ??
under(monorepoRoot, "scripts", "diarize.mjs"),
+ ttsBin: process.env.TTS_BIN ?? under(monorepoRoot, "scripts", "tts.mjs"),
+ espeakNgBin: process.env.ESPEAK_NG_BIN ?? "espeak-ng",
+ ttsHome: path.join(os.homedir(), ".local", "share", "archilyzer", "tts"),
+ ttsCacheDir: under(monorepoRoot, ".tts", "cache"),
ollamaUrl: (process.env.OLLAMA_URL ?? "http://127.0.0.1:11434").replace(
/\/+$/,
"",
diff --git a/common/lib/settingsDocs.ts b/common/lib/settingsDocs.ts
@@ -22,6 +22,7 @@ import {
DIGEST_SETTINGS_FIELD_DOCS,
SAVED_VIDEO_BACKUP_SETTINGS_FIELD_DOCS,
SEEDER_SETTINGS_FIELD_DOCS,
+ TTS_SETTINGS_FIELD_DOCS,
SOCIAL_LINK_FIELD_DOCS,
SOCIAL_SETTINGS_FIELD_DOCS,
X_SOCIAL_SETTINGS_FIELD_DOCS,
@@ -260,6 +261,13 @@ export function blockTables(d: SiteSettings): Partial<Record<keyof SiteSettings,
defaults: fromObject(d.seeder),
},
],
+ tts: [
+ {
+ path: "tts",
+ docs: TTS_SETTINGS_FIELD_DOCS,
+ defaults: fromObject(d.tts),
+ },
+ ],
};
}
diff --git a/common/lib/settingsSchema.test.ts b/common/lib/settingsSchema.test.ts
@@ -31,6 +31,7 @@ import type {
import type { StorageSettings } from "./storageLocations";
import type { ArchiveOrgFetchSettings } from "./archiveOrgTorrent";
import type { SeederSettings } from "./seederSettings";
+import type { TtsSettings } from "./ttsSettings";
import type {
AttributionSettings,
BackfillSettings,
@@ -106,13 +107,15 @@ type PreSchemaSiteSettings = {
publish: PublishSettings;
// The home seeder of last resort (release 21 D4b).
seeder: SeederSettings;
+ // Local text-to-speech (release 25 T1).
+ tts: TtsSettings;
};
// Bracketed so the conditional does not distribute (see commit 8c43231).
type Same<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
const shapeUnchanged: Same<SiteSettings, PreSchemaSiteSettings> = true;
-test("SiteSettings keeps its 37 fields, in file order", () => {
+test("SiteSettings keeps its 38 fields, in file order", () => {
assert.equal(shapeUnchanged, true);
assert.deepEqual(Object.keys(siteSettingsSchema.shape), [
"adminTitle",
@@ -152,6 +155,7 @@ test("SiteSettings keeps its 37 fields, in file order", () => {
"archiveOrg",
"publish",
"seeder",
+ "tts",
]);
// A parsed object carries every key, in that order — writeSettings writes
// exactly this, so the order is the on-disk order.
diff --git a/common/lib/settingsSchema.ts b/common/lib/settingsSchema.ts
@@ -78,6 +78,8 @@ import {
} from "./archiveOrgTorrent";
import { sanitizeSeeder, type SeederSettings } from "./seederSettings";
export { SEEDER_SETTINGS_FIELD_DOCS, type SeederSettings } from "./seederSettings";
+import { sanitizeTts, type TtsSettings } from "./ttsSettings";
+export { TTS_SETTINGS_FIELD_DOCS, type TtsSettings } from "./ttsSettings";
import {
DEFAULT_COOKIE_MODE,
isCookieMode,
@@ -1827,6 +1829,9 @@ export const siteSettingsSchema = z.object({
seeder: settingsField((v): SeederSettings => sanitizeSeeder(v)).describe(
"The home seeder of last resort (release 21): `archilyzer seed` seeds the sites' playable torrents (`archilyzer media playable`), each one only while no other seeder has it, and only behind a VPN (the docker profile `seeder`, docker-compose.seeder.yml). Not configured until `sites` names one. See SeederSettings and common/controller/seeder.ts.",
),
+ tts: settingsField((v): TtsSettings => sanitizeTts(v)).describe(
+ "Local text-to-speech (release 25): narration for report videos and podcasts, synthesized as an editor job (`pnpm ops tts`, the `tts` queue, one at a time) with a STOCK voice — never a cloned one — and cached by content. The default engine is Kokoro-82M with the voice `af_heart`, installed by `archilyzer tts setup`; espeak-ng needs no install. Every synthesis is disclosed as a synthetic voice (its sidecar and the result's `disclosure`). See TtsSettings and common/controller/ttsFile.ts.",
+ ),
});
export type SiteSettings = z.infer<typeof siteSettingsSchema>;
diff --git a/common/lib/ttsSettings.test.ts b/common/lib/ttsSettings.test.ts
@@ -0,0 +1,37 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import os from "node:os";
+import path from "node:path";
+import { DEFAULT_TTS_SETTINGS, resolveTtsCacheDir, resolveTtsHome, sanitizeTts } from "./ttsSettings";
+import { defaults } from "./settingsSchema";
+
+// Run with:
+// pnpm --filter yt-dlp-transcript-common exec tsx --test lib/ttsSettings.test.ts
+
+test("the default block: kokoro, af_heart, natural pace, blank dirs", () => {
+ assert.deepEqual(defaults().tts, { engine: "kokoro", voice: "af_heart", speed: 1, home: "", dir: "" });
+ assert.deepEqual(sanitizeTts(undefined), DEFAULT_TTS_SETTINGS);
+ assert.deepEqual(sanitizeTts("nonsense"), DEFAULT_TTS_SETTINGS);
+});
+
+test("an unknown engine or a voice the engine lacks falls back; speed is clamped", () => {
+ assert.equal(sanitizeTts({ engine: "piper" }).engine, "kokoro");
+ assert.deepEqual(sanitizeTts({ engine: "espeak-ng" }), { ...DEFAULT_TTS_SETTINGS, engine: "espeak-ng", voice: "en-us" });
+ assert.equal(sanitizeTts({ engine: "espeak-ng", voice: "en-gb" }).voice, "en-gb");
+ assert.equal(sanitizeTts({ voice: "bm_george" }).voice, "bm_george");
+ assert.equal(sanitizeTts({ voice: "someone_real" }).voice, "af_heart");
+ assert.equal(sanitizeTts({ speed: 0.1 }).speed, 0.5);
+ assert.equal(sanitizeTts({ speed: 9 }).speed, 2);
+ assert.equal(sanitizeTts({ speed: 0.904 }).speed, 0.9);
+ assert.equal(sanitizeTts({ speed: "fast" }).speed, 1);
+});
+
+test("home and dir: blank is the Paths default, ~/ expands, a relative path is dropped", () => {
+ const paths = { ttsHome: "/d/home", ttsCacheDir: "/d/cache" };
+ assert.equal(resolveTtsHome(sanitizeTts({}), paths), "/d/home");
+ assert.equal(resolveTtsCacheDir(sanitizeTts({}), paths), "/d/cache");
+ assert.equal(resolveTtsHome(sanitizeTts({ home: "/opt/tts" }), paths), "/opt/tts");
+ assert.equal(resolveTtsCacheDir(sanitizeTts({ dir: "~/tts-cache" }), paths), path.join(os.homedir(), "tts-cache"));
+ assert.equal(sanitizeTts({ dir: "relative/cache" }).dir, "");
+ assert.equal(sanitizeTts({ home: 7 }).home, "");
+});
diff --git a/common/lib/ttsSettings.ts b/common/lib/ttsSettings.ts
@@ -0,0 +1,90 @@
+// 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";
+
+export type TtsSettings = {
+ engine: string;
+ voice: string;
+ speed: number;
+ home: string;
+ dir: string;
+};
+
+export const DEFAULT_TTS_SETTINGS: TtsSettings = {
+ engine: DEFAULT_TTS_ENGINE_ID,
+ voice: DEFAULT_TTS_VOICE,
+ speed: 1,
+ home: "",
+ dir: "",
+};
+
+export const TTS_SETTINGS_FIELD_DOCS: FieldDocs<TtsSettings> = {
+ engine:
+ "The engine a synthesis uses when the request names none: `kokoro` (Kokoro-82M, " +
+ "Apache-2.0, CPU; installed by `archilyzer tts setup`) 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. 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 [0.5, 2]. In the cache key: a new speed is a new synthesis.",
+ home:
+ "Where `archilyzer tts setup` installs engines, one directory per engine " +
+ "(`<home>/kokoro`: its python venv and model files). Blank = " +
+ "`~/.local/share/archilyzer/tts`. Absolute, or `~/`-relative.",
+ dir:
+ "The synthesis cache: `<sha256>.wav` (48 kHz mono 16-bit) and a `<sha256>.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 = `<repo>/.tts/cache` (gitignored). Absolute, or `~/`-relative.",
+};
+
+// "" (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<string, unknown>) : {};
+ 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;
+ const speed =
+ typeof r.speed === "number" && Number.isFinite(r.speed)
+ ? Math.min(2, Math.max(0.5, Math.round(r.speed * 100) / 100))
+ : d.speed;
+ return { engine: engine.id, voice, speed, home: dirSetting(r.home), dir: dirSetting(r.dir) };
+}
+
+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<TtsSettings, "home">, paths: Pick<Paths, "ttsHome">): string {
+ return tts.home ? expand(tts.home) : paths.ttsHome;
+}
+
+/** The synthesis cache: settings.tts.dir, else paths.ttsCacheDir. */
+export function resolveTtsCacheDir(tts: Pick<TtsSettings, "dir">, paths: Pick<Paths, "ttsCacheDir">): string {
+ return tts.dir ? expand(tts.dir) : paths.ttsCacheDir;
+}
diff --git a/settings.json.example b/settings.json.example
@@ -216,5 +216,12 @@
"pollSeconds": 60,
"standbyAfterSeconds": 600,
"bindInterface": ""
+ },
+ "tts": {
+ "engine": "kokoro",
+ "voice": "af_heart",
+ "speed": 1,
+ "home": "",
+ "dir": ""
}
}