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:
parent
463c6580f4
commit
b5a81bdb15
10 changed files with 780 additions and 0 deletions
48
src/routers/tts.js
Normal file
48
src/routers/tts.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// /tts — TTS voice builder: combine engines, voices, pitch/speed, layers and effects, test, save as named voices.
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const db = require('../db');
|
||||
const tts = require('../tts');
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
let voices = null, error = null;
|
||||
try { voices = await tts.voices(); }
|
||||
catch (e) { error = e.message; }
|
||||
res.render('tts', {
|
||||
voices, error, saved: db.getAllTtsVoices(),
|
||||
effects: Object.fromEntries(Object.entries(tts.EFFECTS).map(([k, e]) => [k, { label: e.label, hint: e.hint }])),
|
||||
limits: tts.LIMITS, defaults: tts.DEFAULT_CONFIG, maxChars: tts.MAX_CHARS,
|
||||
});
|
||||
});
|
||||
|
||||
// play: { config, text } -> { url, ms, cached }
|
||||
router.post('/preview', async (req, res) => {
|
||||
try {
|
||||
const out = await tts.synth(req.body.config, req.body.text);
|
||||
res.json({ ok: true, url: out.url, ms: out.ms, cached: out.cached });
|
||||
} catch (e) {
|
||||
res.status(400).json({ ok: false, error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
// save: { id?, name, config } -> { voice }
|
||||
router.post('/voices', (req, res) => {
|
||||
try {
|
||||
const name = String(req.body.name || '').trim().slice(0, 60);
|
||||
if (!name) throw new Error('give the voice a name');
|
||||
const config = tts.normalize(req.body.config);
|
||||
const id = parseInt(req.body.id, 10);
|
||||
if (!isNaN(id) && db.getTtsVoice(id)) db.updateTtsVoice(id, name, config);
|
||||
const voice = !isNaN(id) && db.getTtsVoice(id) ? db.getTtsVoice(id) : db.createTtsVoice(name, config);
|
||||
res.json({ ok: true, voice });
|
||||
} catch (e) {
|
||||
res.status(400).json({ ok: false, error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/voices/:id/delete', (req, res) => {
|
||||
db.deleteTtsVoice(req.params.id);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue