from fastapi import FastAPI, File, UploadFile import shutil import os from whispercpp import Whisper app = FastAPI() # Load the model (auto-download and cache it) whisper = Whisper.from_pretrained("base.en") # Options: tiny, base, small, etc. @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) result = whisper.transcribe(temp_file) os.remove(temp_file) return {"text": result}