diff --git a/services/tts/server.py b/services/tts/server.py new file mode 100644 index 0000000..a6fa863 --- /dev/null +++ b/services/tts/server.py @@ -0,0 +1,33 @@ +"""Coqui XTTS wrapper: POST /synthesize -> WAV audio bytes.""" +import os +import uuid +from pathlib import Path +from flask import Flask, request, send_file, jsonify + +app = Flask(__name__) +VOICE_NAME = os.getenv("VOICE_NAME", "wizard") +REFERENCE_DIR = Path("/app/reference") +OUT_DIR = Path("/tmp/tts-out") +OUT_DIR.mkdir(parents=True, exist_ok=True) + +_ref = REFERENCE_DIR / "voice-sample.wav" + +from TTS.api import TTS +tts = TTS(model_name="tts_models/en/vctk/vits", progress_bar=False, gpu=False) + +@app.get("/health") +def health(): + return {"status": "ok", "voice": VOICE_NAME} + +@app.post("/synthesize") +def synthesize(): + data = request.get_json(force=True) + text = data.get("text", "") + if not text: + return jsonify({"error": "text required"}), 400 + out = OUT_DIR / f"{uuid.uuid4().hex}.wav" + tts.tts_to_file(text=text, file_path=str(out)) + return send_file(str(out), mimetype="audio/wav") + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5002) \ No newline at end of file