Files
stt-whisper-cpp-ap/app/main.py
2025-06-14 23:19:35 +05:30

20 lines
528 B
Python

from fastapi import FastAPI, File, UploadFile
import os
import shutil
from whispercpp import Whisper
app = FastAPI()
# Load model using the updated API
whisper = Whisper.from_pretrained("./app/model/ggml-base.en.bin")
@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}