The gpt-4o-transcribe model was returning "unsupported format" errors for WAV files that worked fine with whisper-1. This is a known issue documented in the OpenAI Community.
- Format Mismatch: Mobile apps using
expo-audiotypically record in M4A format, but the file handling logic was sometimes mislabeling files - WebM Naming Issues: Web recordings in WebM format were being incorrectly named as
.wavfiles - Strict Format Requirements:
gpt-4o-transcribeappears to be more strict about audio format validation thanwhisper-1 - No Fallback Mechanism: When
gpt-4o-transcribefailed, there was no automatic fallback towhisper-1
- Automatic Fallback: Added intelligent fallback from
gpt-4o-transcribetowhisper-1when format errors occur - Better Error Detection: Detect "unsupported_format" errors specifically and trigger fallback
- Enhanced Logging: Added detailed logging for debugging transcription issues
- M4A Support: Added
audio/m4ato supported MIME types
# Key changes in transcribe_audio endpoint:
try:
response = llm_client.client.audio.transcriptions.create(**clean_kwargs)
# ... success handling
except Exception as e:
error_str = str(e).lower()
# Check if it's a format error and we're using gpt-4o models
if ("unsupported_format" in error_str or "format you provided" in error_str) and model.startswith("gpt-4o"):
# Fallback to whisper-1
fallback_kwargs = clean_kwargs.copy()
fallback_kwargs["model"] = "whisper-1"
response = llm_client.client.audio.transcriptions.create(**fallback_kwargs)- Fixed File Naming: Web recordings now correctly use
.webmextension instead of.wav - Smart Model Selection: Automatically use
whisper-1for WebM files since they have known compatibility issues - Improved Format Detection: Better logic to detect actual audio format based on platform and file extension
- Proper MIME Types: Correctly set MIME types for different platforms:
- iOS/Android:
audio/mp4for M4A files - Web:
audio/webmfor WebM files
- iOS/Android:
- Enhanced Logging: Added console logging for debugging file format issues
// Key changes in stopRecording:
if (Platform.OS === 'web') {
// Web typically records in WebM format
mimeType = 'audio/webm';
filename = 'audio.webm'; // Always use .webm for web recordings
} else {
// Mobile platforms (iOS/Android) - typically M4A
if (filename.endsWith('.m4a') || filename.endsWith('.mp4')) {
mimeType = 'audio/mp4';
filename = filename.replace(/\.[^.]+$/, '.m4a');
}
// ... other format handling
}
// Smart model selection
const response: TranscriptionResponse = await transcribeAudio(
formData,
// Use whisper-1 directly for WebM files since they have known issues with gpt-4o-transcribe
mimeType === 'audio/webm' ? 'whisper-1' : 'gpt-4o-transcribe'
);- Model Parameter: Added optional model parameter to
transcribeAudiofunction - URL Construction: Properly construct URL with query parameters
Run the comprehensive test suite to verify the fix:
# Basic test
python test_transcription.py
# Comprehensive format testing
python test_transcription_formats.pyThe comprehensive test will verify:
- WAV files with both models
- WebM files with both models
- Fallback mechanisms
- Proper error handling
Based on the logs, the system now works as follows:
-
Web Platform:
- Records in WebM format
- Automatically uses
whisper-1(skipsgpt-4o-transcribe) - Files correctly named as
.webm
-
Mobile Platforms:
- Records in M4A format
- Tries
gpt-4o-transcribefirst - Falls back to
whisper-1if format issues occur - Files correctly named as
.m4a
-
Fallback Logging:
[WARNING] Format error with gpt-4o-transcribe, falling back to whisper-1 [INFO] Retrying transcription with whisper-1 [INFO] Transcription successful with whisper-1 fallback
- Reliability: Automatic fallback ensures transcription always works
- Performance: Still attempts to use the newer
gpt-4o-transcribemodel when appropriate - Smart Routing: WebM files bypass
gpt-4o-transcribeentirely to avoid known issues - Compatibility: Better handling of different audio formats across platforms
- Debugging: Enhanced logging makes it easier to diagnose issues
- Existing code will continue to work without changes
- The fallback is automatic and transparent to the client
- WebM files now automatically use
whisper-1for better reliability - The response includes the actual model used for transcription
- No breaking changes to the API interface