stt-whisper-cpp-ap/app/main.py

20 lines
501 B
Python

from fastapi import FastAPI, File, UploadFile
import os
import shutil
from whispercpp import Whisper
app = FastAPI()
model_path = "./app/model/ggml-base.en.bin"
whisper = Whisper(model_path)
@app.post("/transcribe")
async def transcribe_audio(audio: UploadFile = File(...)):
temp_file = f"temp_{audio.filename}"
with open(temp_file, "wb") as buffer:
shutil.copyfileobj(audio.file, buffer)
text = whisper.transcribe(temp_file)
os.remove(temp_file)
return {"text": text}