-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (26 loc) · 968 Bytes
/
main.py
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, Query, status
from fastapi.responses import StreamingResponse
from models.audio import generate_audio, load_audio_model
from models.text import generate_text, load_text_model
from schemas import VoicePresets
from utils import audio_array_to_buffer
app = FastAPI()
@app.get("/generate/text")
def serve_language_model_controller(prompt=Query(...)):
pipe = load_text_model()
output = generate_text(pipe, prompt)
return output
@app.get(
"/generate/audio",
responses={status.HTTP_200_OK: {"content": {"audio/wav": {}}}},
response_class=StreamingResponse,
)
def serve_text_to_audio_model_controller(
prompt=Query(...),
preset: VoicePresets = Query(default="v2/en_speaker_1"),
):
processor, model = load_audio_model()
output, sample_rate = generate_audio(processor, model, prompt, preset)
return StreamingResponse(
audio_array_to_buffer(output, sample_rate), media_type="audio/wav"
)