diff --git a/backend/routes/transcription.py b/backend/routes/transcription.py index dc949132d..7ba19d74c 100644 --- a/backend/routes/transcription.py +++ b/backend/routes/transcription.py @@ -15,6 +15,10 @@ UPLOAD_CHUNK_SIZE = 1024 * 1024 # 1MB +# Same set profiles.py accepts for voice samples. librosa picks its decoder from the +# file extension, so the temp file has to keep the uploaded one. +ALLOWED_AUDIO_EXTS = {".wav", ".mp3", ".m4a", ".ogg", ".flac", ".aac", ".webm", ".opus"} + @router.post("/transcribe", response_model=models.TranscriptionResponse) async def transcribe_audio( @@ -23,7 +27,10 @@ async def transcribe_audio( model: str | None = Form(None), ): """Transcribe audio file to text.""" - with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp: + uploaded_ext = Path(file.filename or "").suffix.lower() + file_suffix = uploaded_ext if uploaded_ext in ALLOWED_AUDIO_EXTS else ".wav" + + with tempfile.NamedTemporaryFile(suffix=file_suffix, delete=False) as tmp: while chunk := await file.read(UPLOAD_CHUNK_SIZE): tmp.write(chunk) tmp_path = tmp.name