first commit

This commit is contained in:
2026-07-18 01:25:01 +03:30
parent dee06ba093
commit c18a1c2298
22 changed files with 981 additions and 0 deletions

14
tts/Dockerfile Normal file
View 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
View 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
View File

@@ -0,0 +1,2 @@
flask==3.0.3
piper-tts==1.2.0