buchi-stdesign's picture
Upload 2 files
44571ac verified
from fastapi import FastAPI, Query
from fastapi.responses import StreamingResponse
import io
import numpy as np
import soundfile as sf
from inference import load_model, synthesize
app = FastAPI()
@app.on_event("startup")
async def startup_event():
load_model()
@app.get("/voice")
async def voice(text: str = Query(..., description="Text to synthesize")):
audio = synthesize(text)
buf = io.BytesIO()
sf.write(buf, audio, 24000, format="WAV")
buf.seek(0)
return StreamingResponse(buf, media_type="audio/wav")