Files
tts-server/examples/voice-clone.mjs
mikael-lovqvists-claude-agent f6ff8c72e8 Convert chatterbox-server.py to HTTP server, add Node.js examples
Replace stdin/stdout JSON line protocol with a stdlib HTTP server
(ThreadingHTTPServer). Three endpoints: POST /speak, /chime, /preload.
All return {"status": "ok"} after audio is queued for playback.
TTS generation is serialized via a threading.Lock; concurrent chime/preload
requests are handled without waiting for generation.

Add examples/speak.mjs, chime.mjs, voice-clone.mjs using Node.js built-in
fetch (no libraries required, Node 18+).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 07:28:18 +00:00

25 lines
767 B
JavaScript

// Speak text using a reference WAV for voice cloning.
// The server reads the audio_prompt path from its own filesystem.
// Usage: node voice-clone.mjs /path/to/reference.wav "Text to speak"
const PORT = process.env.TTS_PORT ?? '11500'
const audio_prompt = process.argv[2]
const text = process.argv[3] ?? 'Hello, this is a cloned voice.'
if (!audio_prompt) {
console.error('usage: node voice-clone.mjs /path/to/reference.wav "text"')
process.exit(1)
}
const res = await fetch(`http://localhost:${PORT}/speak`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, audio_prompt }),
})
const data = await res.json()
if (data.status !== 'ok') {
console.error('error:', data.message)
process.exit(1)
}