Add TTS voice builder (/tts): Piper + espeak, layers, effects

- src/tts.js: synth(config, text) -> cached mp3 in public/tts; up to 3 layers
  (engine, voice, speaker, speed, pitch, volume, delay) mixed with ffmpeg,
  8 effects (stadium, echo, 8-bit, radio, robot, choir, warp, shaky), loudnorm;
  config is clamped and voice/speaker names are restricted to plain names
- tools/tts/worker.py: long-running Python worker (JSON lines), Piper models
  kept loaded (LRU of 4), espeak-ng via libespeak-ng + ctypes
- tools/tts/setup.sh: venv + piper-tts + default voice set
- /tts page: presets, layers, effects, test playback, save/load/delete named
  voices (tts_voices table); TTS link in the nav
- public/tts, tools/tts/venv and tools/tts/voices are gitignored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-21 13:06:32 +02:00
parent 463c6580f4
commit b5a81bdb15
10 changed files with 780 additions and 0 deletions

View file

@ -135,6 +135,22 @@ Chat (`?parts=chat`) is `public/chat/chat.css` + `public/chat/chat.js` (window.H
- Moderation: deleted messages, timeouts, bans and /clear remove the matching slips at once.
- Design preview with other styles: `~/Desktop/Stream/chat/index.html` (not in the repo).
## TTS voices (/tts)
Builder page to make named TTS voices; redeems do not use them yet.
- `src/tts.js`: `synth(config, text)` -> cached mp3 in `public/tts/<sha1>.mp3` (gitignored, newest 300 kept).
Config = up to 3 `layers` (engine `piper`|`espeak`, voice, speaker, speed, pitch in semitones, volume, delay ms)
+ `effects` {stadium, echo, crush, radio, robot, chorus, flanger, tremolo: 0..1}. `normalize()` clamps everything
and only accepts plain voice/speaker names (no paths). Pitch = asetrate+atempo (formants shift too: the demon sound).
ffmpeg: per-layer pitch/volume/delay -> amix -> effects -> loudnorm -> mono mp3.
- `tools/tts/worker.py`: long-running Python process (JSON lines over stdin/stdout), started on first use. Piper
models stay loaded (LRU, `TTS_MAX_LOADED`=4, ~100 MB each); espeak-ng via libespeak-ng + ctypes (no binary needed).
- Setup (server): `sudo apt install python3-venv ffmpeg espeak-ng`, then `tools/tts/setup.sh` (venv + default voices
into `tools/tts/voices/`, both gitignored). Extra voices: `tools/tts/setup.sh en_US-amy-medium ...`.
Env overrides: `TTS_PYTHON`, `TTS_VOICES_DIR`.
- Table `tts_voices` (name, config JSON). Routes: GET `/tts`, POST `/tts/preview`, POST `/tts/voices`, POST `/tts/voices/:id/delete`.
- SAM (C64 voice) was left out on purpose: the only JS port has no licence (abandonware).
## Gap / new-message audio
Configured in `settings`. When a chat message arrives in the overlay, tmi.js checks: