tts: male VCTK fallback until voice-sample.wav lands
Some checks failed
ci / lint (push) Has been cancelled
Some checks failed
ci / lint (push) Has been cancelled
This commit is contained in:
parent
d9a4e8dcae
commit
e1995bab11
|
|
@ -1,23 +1,31 @@
|
||||||
"""Coqui XTTS wrapper: POST /synthesize -> WAV audio bytes."""
|
"""TTS wrapper: clone mode if reference audio is present, else fallback to VCTK male."""
|
||||||
import os
|
|
||||||
import uuid
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from flask import Flask, request, send_file, jsonify
|
from flask import Flask, request, send_file, jsonify
|
||||||
|
import os, uuid
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
VOICE_NAME = os.getenv("VOICE_NAME", "wizard")
|
|
||||||
REFERENCE_DIR = Path("/app/reference")
|
|
||||||
OUT_DIR = Path("/tmp/tts-out")
|
OUT_DIR = Path("/tmp/tts-out")
|
||||||
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
REF = Path(os.getenv("REFERENCE_AUDIO", "/app/reference/voice-sample.wav"))
|
||||||
_ref = REFERENCE_DIR / "voice-sample.wav"
|
|
||||||
|
|
||||||
from TTS.api import TTS
|
from TTS.api import TTS
|
||||||
tts = TTS(model_name="tts_models/en/vctk/vits", progress_bar=False, gpu=False)
|
tts = TTS(model_name="tts_models/en/vctk/vits", progress_bar=False, gpu=False)
|
||||||
|
|
||||||
|
def synth_to_file(text: str, out: Path):
|
||||||
|
if REF.exists():
|
||||||
|
tts.tts_to_file(text=text, speaker_wav=str(REF), file_path=str(out))
|
||||||
|
else:
|
||||||
|
# male VCTK fallback speaker
|
||||||
|
tts.tts_to_file(text=text, speaker="p267", file_path=str(out))
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
def health():
|
def health():
|
||||||
return {"status": "ok", "voice": VOICE_NAME}
|
return {
|
||||||
|
"status": "ok",
|
||||||
|
"mode": "clone" if REF.exists() else "fallback-male",
|
||||||
|
"reference": str(REF),
|
||||||
|
"model": "tts_models/en/vctk/vits",
|
||||||
|
}
|
||||||
|
|
||||||
@app.post("/synthesize")
|
@app.post("/synthesize")
|
||||||
def synthesize():
|
def synthesize():
|
||||||
|
|
@ -26,8 +34,8 @@ def synthesize():
|
||||||
if not text:
|
if not text:
|
||||||
return jsonify({"error": "text required"}), 400
|
return jsonify({"error": "text required"}), 400
|
||||||
out = OUT_DIR / f"{uuid.uuid4().hex}.wav"
|
out = OUT_DIR / f"{uuid.uuid4().hex}.wav"
|
||||||
tts.tts_to_file(text=text, file_path=str(out))
|
synth_to_file(text, out)
|
||||||
return send_file(str(out), mimetype="audio/wav")
|
return send_file(str(out), mimetype="audio/wav")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5002)
|
app.run(host="0.0.0.0", port=5002)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user