File size: 646 Bytes
e33e68d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import whisper
from fastapi import UploadFile, File
from fastapi.responses import JSONResponse
from responder import get_belel_reply
from voice_player import generate_voice

model = whisper.load_model("base")

@app.post("/chatwithbelel/audio")
async def audio_input(file: UploadFile = File(...)):
    path = f"temp/{file.filename}"
    with open(path, "wb") as f:
        f.write(await file.read())
    
    result = model.transcribe(path)
    text = result['text']
    reply = get_belel_reply(text)
    voice = generate_voice(reply)

    return JSONResponse({
        "transcript": text,
        "response": reply,
        "voice": voice
    })