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: efforting.tech/tts-server#3
This commit is contained in:
2026-06-07 07:41:52 +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 /speak {"text": "...", "temperature": 0.8, "top_p": 0.95, "audio_prompt": "/path.wav"}
POST /chime {"path": "/path/to/file.wav"} POST /chime {"path": "/path/to/file.wav"}
POST /preload {"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": "..."}. All endpoints return {"status": "ok"} or {"status": "error", "message": "..."}.
Responses are sent after audio is queued for playback (not after playback finishes). Responses are sent after audio is queued for playback (not after playback finishes).
@@ -237,6 +238,14 @@ class Handler(BaseHTTPRequestHandler):
except Exception as e: except Exception as e:
self.send_json({'status': 'error', 'message': str(e)}, 500) 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: else:
self.send_json({'status': 'error', 'message': 'not found'}, 404) 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)
}