from fastapi import FastAPI, Query
from fastapi.responses import FileResponse
from TTS.api import TTS
import tempfile

app = FastAPI()
tts = TTS(model_name="tts_models/en/ljspeech/vits", gpu=True)

@app.get("/api/tts")
def synth(text: str = Query(...)):
    tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
    tts.tts_to_file(text=text, file_path=tmp.name)
    return FileResponse(tmp.name, media_type="audio/wav", filename="speech.wav")