first commit
This commit is contained in:
18
tts/app.py
Normal file
18
tts/app.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import os, subprocess, tempfile
|
||||
from flask import Flask, request, send_file
|
||||
|
||||
app = Flask(__name__)
|
||||
PIPER_VOICE = os.environ.get("PIPER_VOICE", "/models/piper/fa_IR-model.onnx")
|
||||
|
||||
@app.route("/synthesize", methods=["POST"])
|
||||
def synthesize():
|
||||
text = request.get_json().get("text", "")
|
||||
p_out = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
|
||||
a_out = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
|
||||
|
||||
subprocess.run(["piper", "--model", PIPER_VOICE, "--output_file", p_out], input=text.encode("utf-8"), capture_output=True)
|
||||
subprocess.run(["ffmpeg", "-y", "-i", p_out, "-ar", "8000", "-ac", "1", "-acodec", "pcm_s16le", "-f", "wav", a_out], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
return send_file(a_out, mimetype="audio/wav")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5002)
|
||||
Reference in New Issue
Block a user