first commit
This commit is contained in:
14
tts/Dockerfile
Normal file
14
tts/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
wget ffmpeg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY app.py .
|
||||
|
||||
EXPOSE 5002
|
||||
CMD ["python3", "app.py"]
|
||||
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)
|
||||
2
tts/requirements.txt
Normal file
2
tts/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
flask==3.0.3
|
||||
piper-tts==1.2.0
|
||||
Reference in New Issue
Block a user