Download chatwithbelel/audio_input.py from TTOPM/belel-protocol: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/TTOPM/belel-protocol/resolve/main/chatwithbelel/audio_input.py
- Command line
-
hf download hf://TTOPM/belel-protocol/chatwithbelel/audio_input.py
-
curl -L -o audio_input.py https://huggingface.co/TTOPM/belel-protocol/resolve/main/chatwithbelel/audio_input.py
646 Bytes
| 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") | |
| 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 | |
| }) | |