Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Fix 400 errors not detected as permanent and unsupported file extensions

Murtaza Nasir01110bd529ef
diff --git a/src/services/job_queue.py b/src/services/job_queue.py
index 7703581f..d545021d 100644
--- a/src/services/job_queue.py
+++ b/src/services/job_queue.py
@@ -245,6 +245,7 @@ class FairJobQueue:
Detect if an error is permanent and should not be retried.
Permanent errors include:
+ - 400: Bad request (invalid format, invalid parameters)
- 413: File too large (user needs to enable chunking or compress file)
- 401/403: Authentication/authorization errors (credentials issue)
- 402: Payment required (billing issue)
@@ -254,12 +255,12 @@ class FairJobQueue:
error_lower = error_str.lower()
# HTTP status codes that indicate permanent errors
- permanent_codes = ['413', '401', '402', '403']
+ permanent_codes = ['400', '413', '401', '402', '403', '404']
for code in permanent_codes:
if f'error code: {code}' in error_lower or f'status {code}' in error_lower:
return True
- # Specific error patterns that are permanent
+ # Specific error patterns that are permanent (simple substring matching)
permanent_patterns = [
'maximum content size limit',
'file too large',
@@ -274,10 +275,12 @@ class FairJobQueue:
'payment required',
'quota exceeded',
'insufficient funds',
- 'model.*not found',
+ 'model not found',
'invalid model',
- 'unsupported.*format',
- 'invalid.*file.*format',
+ 'unsupported format',
+ 'invalid file format',
+ 'invalid_request_error',
+ 'bad request',
]
for pattern in permanent_patterns:
diff --git a/src/utils/audio_conversion.py b/src/utils/audio_conversion.py
index daf3bcb6..9c810a94 100644
--- a/src/utils/audio_conversion.py
+++ b/src/utils/audio_conversion.py
@@ -224,9 +224,18 @@ def convert_if_needed(
# Handle audio files - check if conversion needed
needs_conversion = False
+
+ # OpenAI Whisper API only accepts specific file extensions
+ # Even if codec is fine, extension must be in this list
+ openai_supported_extensions = {'.flac', '.m4a', '.mp3', '.mp4', '.mpeg', '.mpga', '.oga', '.ogg', '.wav', '.webm'}
+ file_ext = os.path.splitext(filepath)[1].lower()
+
if audio_codec is None:
needs_conversion = True
logger.info(f"Unknown codec for {original_filename}, will attempt conversion")
+ elif file_ext not in openai_supported_extensions:
+ needs_conversion = True
+ logger.info(f"Converting {original_filename} - extension '{file_ext}' not supported by OpenAI API")
elif is_asr_endpoint and audio_codec == 'aac':
needs_conversion = True
logger.info(f"Converting AAC-encoded file for ASR endpoint compatibility")