Whisper audio format not supported fix
Quick answer
To fix the Whisper audio format not supported error, convert your audio file to a supported format like mp3, wav, or m4a before transcription. Use tools like ffmpeg to convert unsupported formats to these standard ones compatible with the openai Whisper API.
PREREQUISITES
Python 3.8+OpenAI API key (free tier works)pip install openai>=1.0ffmpeg installed and accessible in system PATH
Setup
Install the openai Python package and ensure ffmpeg is installed on your system for audio conversion.
- Install OpenAI Python SDK:
pip install openai - Install
ffmpegvia your OS package manager or from ffmpeg.org
pip install openai Step by step
Convert unsupported audio formats to mp3 or wav using ffmpeg in Python, then transcribe with Whisper API.
import os
import subprocess
from openai import OpenAI
# Convert audio to mp3 using ffmpeg
input_file = "input_audio.unsupported"
converted_file = "converted_audio.mp3"
subprocess.run(["ffmpeg", "-y", "-i", input_file, converted_file], check=True)
# Transcribe with Whisper API
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
with open(converted_file, "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
print("Transcription:", transcript.text) output
Transcription: This is the transcribed text from the audio.
Common variations
You can convert audio to other supported formats like wav or m4a by changing the ffmpeg output filename extension. Async transcription is also possible with async libraries but requires additional setup.
import os
import subprocess
from openai import OpenAI
# Convert to wav instead of mp3
input_file = "input_audio.unsupported"
converted_file = "converted_audio.wav"
subprocess.run(["ffmpeg", "-y", "-i", input_file, converted_file], check=True)
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
with open(converted_file, "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
print("Transcription:", transcript.text) output
Transcription: This is the transcribed text from the audio.
Troubleshooting
- If you get
audio format not supportederrors, verify yourffmpeginstallation and that the converted file is a validmp3,wav, orm4a. - Check file size limits (max 25MB for Whisper API).
- Use
ffmpeg -i input_fileto inspect audio format details.
Key Takeaways
- Always convert unsupported audio formats to mp3, wav, or m4a before using Whisper API.
- Use ffmpeg for reliable audio format conversion in Python scripts.
- Check audio file size and format compatibility to avoid transcription errors.