forked from efforting.tech/tts-server
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user