File size: 534 Bytes
44571ac
1ee91f8
 
44571ac
 
 
1ee91f8
 
 
 
 
 
 
 
44571ac
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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")