seed repo scaffold
This commit is contained in:
parent
e38934b862
commit
44dc96cb91
33
services/tts/server.py
Normal file
33
services/tts/server.py
Normal file
|
|
@ -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)
|
||||
Loading…
Reference in New Issue
Block a user