init
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
FROM python:3.11-slim
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ffmpeg \
|
||||
libsndfile1 \
|
||||
build-essential \
|
||||
git \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY requirements.txt ./
|
||||
RUN python -m pip install --upgrade pip setuptools wheel && \
|
||||
pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY server.py ./
|
||||
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8002"]
|
||||
@@ -0,0 +1,6 @@
|
||||
fastapi==0.100.0
|
||||
uvicorn[standard]==0.22.0
|
||||
TTS==0.12.0
|
||||
torch==2.2.0
|
||||
soundfile==0.12.1
|
||||
numpy==1.26.0
|
||||
@@ -0,0 +1,28 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi import Body
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from TTS.api import TTS
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Load a German-capable model. Model may be downloaded on first run.
|
||||
tts = TTS(model_name="tts_models/de/thorsten_hsmm")
|
||||
|
||||
|
||||
@app.post("/speak")
|
||||
def speak(payload: dict = Body(...)):
|
||||
text = payload.get("text")
|
||||
language = payload.get("language", "de")
|
||||
if not text:
|
||||
raise HTTPException(status_code=400, detail="Missing 'text' in body")
|
||||
|
||||
fd, path = tempfile.mkstemp(suffix=".wav")
|
||||
os.close(fd)
|
||||
try:
|
||||
tts.tts_to_file(text=text, speaker=None, language=language, file_path=path)
|
||||
return FileResponse(path, media_type="audio/wav", filename="response.wav")
|
||||
finally:
|
||||
# FileResponse will stream the file; don't remove immediately. Consumer can manage cleanup.
|
||||
pass
|
||||
Reference in New Issue
Block a user