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))