Spaces:
Sleeping
Sleeping
File size: 966 Bytes
936ef75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse
import os
import uuid
from fastapi.middleware.cors import CORSMiddleware
from synthesize import synthesize
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/generate")
async def generate_api(text: str, lang: str, model: str):
output_filename = f"audio_{uuid.uuid4().hex}"
try:
# Ejecuta tu lógica original
synthesize(text, lang, model, output_filename)
file_path = f"./output/{output_filename}.wav"
if os.path.exists(file_path):
return FileResponse(file_path, media_type="audio/wav")
raise HTTPException(status_code=500, detail="Error: El binario no generó el archivo.")
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) |