Skip to content

The open-source AI voice studio. Clone, dictate, create.

Fix: keep the uploaded file extension when transcribing (#903)

Elem Oghenekarob680097dfbfb
diff --git a/backend/routes/transcription.py b/backend/routes/transcription.py
index dc949132..7ba19d74 100644
--- a/backend/routes/transcription.py
+++ b/backend/routes/transcription.py
@@ -15,6 +15,10 @@ router = APIRouter()
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