from fastapi import FastAPI, UploadFile, File from faster_whisper import WhisperModel import tempfile app = FastAPI() model = WhisperModel("base", compute_type="int8") @app.post("/transcribe") async def transcribe(file: UploadFile = File(...)): with tempfile.NamedTemporaryFile(delete=False) as tmp: tmp.write(await file.read()) tmp_path = tmp.name segments, _ = model.transcribe(tmp_path) text = " ".join([seg.text for seg in segments]) return {"text": text}