File size: 993 Bytes
23bd097
c0a983b
 
23bd097
c0a983b
 
 
23bd097
 
 
 
 
 
 
 
 
 
c0a983b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
# main.py
from fastapi import FastAPI,status
from fastapi.responses import StreamingResponse

from models import load_text_model,generate_text,load_audio_model,generate_audio
from schemas import VoicePresets
from utils import audio_array_to_buffer
app = FastAPI() 

@app.get("/")
def root_controller():
    return {"status": "healthy"}

@app.get("/generate/text") 
def serve_language_model_controller(prompt: str) -> str: 
    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: str,
    preset: VoicePresets = "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"
    )