Compare commits

..

2 Commits

Author SHA1 Message Date
e15ba903c1 Merge pull request 'Add POST /command endpoint with terminate support' (#3) from mikael-lovqvists-claude-agent/tts-server:add-terminate-command into main
Reviewed-on: #3
2026-06-07 07:41:52 +00:00
6357ff6a58 Add POST /command endpoint with terminate support (closes #2)
Sends {"status": "ok"} before shutting down so the caller gets a clean
response. Shutdown runs in a daemon thread to avoid deadlocking the
handler. Adds examples/terminate.mjs as a Node.js usage example.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 07:37:42 +00:00
2 changed files with 25 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ Endpoints:
POST /speak {"text": "...", "temperature": 0.8, "top_p": 0.95, "audio_prompt": "/path.wav"}
POST /chime {"path": "/path/to/file.wav"}
POST /preload {"path": "/path/to/file.wav"}
POST /command {"command": "terminate"}
All endpoints return {"status": "ok"} or {"status": "error", "message": "..."}.
Responses are sent after audio is queued for playback (not after playback finishes).
@@ -237,6 +238,14 @@ class Handler(BaseHTTPRequestHandler):
except Exception as e:
self.send_json({'status': 'error', 'message': str(e)}, 500)
elif self.path == '/command':
command = req.get('command', '')
if command == 'terminate':
self.send_json({'status': 'ok'})
threading.Thread(target=server.shutdown, daemon=True).start()
else:
self.send_json({'status': 'error', 'message': f'unknown command: {command}'}, 400)
else:
self.send_json({'status': 'error', 'message': 'not found'}, 404)

16
examples/terminate.mjs Normal file
View File

@@ -0,0 +1,16 @@
// Gracefully terminate the Chatterbox TTS server.
// Usage: node terminate.mjs
const PORT = process.env.TTS_PORT ?? '11500'
const res = await fetch(`http://localhost:${PORT}/command`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command: 'terminate' }),
})
const data = await res.json()
if (data.status !== 'ok') {
console.error('error:', data.message)
process.exit(1)
}