Transcribing Audio & Video Using OpenAI Whisper API
Manage large audio or video files with pydub and OpenAI
Most of the recordings I want transcribed are long ones: talks, meetings, the odd screencast. The Whisper API handles the speech-to-text part well, but any recording of real length runs straight into the API's file size limit. So the actual job becomes: split the audio into chunks, transcribe each chunk, and stitch the text back together. This post walks through that workflow with a bit of Python.
When I first wrote this, Whisper had no UI and whisper-1 was the only transcription model on offer. OpenAI has since shipped newer transcription models (gpt-4o-transcribe and gpt-4o-mini-transcribe) that are drop-in replacements for the model name below, but the size limit and the chunking workflow are unchanged.
The 25 MB limit
That limit is the whole reason this post exists. For longer recordings, you divide the audio into smaller chunks, transcribe each chunk individually, and then combine the results. Keeping chunks comfortably under the limit also avoids timeouts and flaky uploads.
Step-by-Step Guide to Transcribing Audio with Whisper API
1. Install Required Libraries
First, you need to install the necessary Python libraries. You can do this using pip:
The library is used for audio processing, and openai is the official library to interact with OpenAI's APIs. One practical note: pydub is a wrapper around , so ffmpeg needs to be installed on your machine (brew install ffmpeg on macOS, apt install ffmpeg on Debian/Ubuntu) or pydub will fail to open anything that isn't a plain WAV file.
2. Chunking the Audio File
You can use the pydub library to split your audio file into smaller chunks. Here's a Python script to do that:
This script divides the audio into 1-minute chunks. You can adjust the chunk_length_ms parameter based on your needs, for example:
Keep the chunk duration honest against the 25 MB limit: how many minutes fit depends entirely on the bitrate. At 128 kbps an MP3 hits 25 MB at roughly 27 minutes, so something like a 45-minute chunk can easily blow past the limit; 10 to 20 minutes leaves a safe margin for most encodings.
One more caveat worth being upfront about: slicing at fixed time boundaries will happily cut through the middle of a word or sentence, which is exactly what the warning above tells you to avoid; each cut can lose or garble a few words of context. The simple code is good enough for my use cases, but the upgrade path is silence-based splitting with pydub's (split_on_silence / detect_silence), which snaps the cut points to natural pauses.
3. Transcribing Each Chunk
Next, you need to transcribe each chunk using the Whisper API:
4. Putting it all together
Finally, you can aggregate the transcriptions from each chunk into a single text file:
For more information on the Whisper API and its capabilities, check the
Update: How to transcribe video files
Transcribing video files is similar to transcribing audio files. You can extract the audio from the video file and then follow the same process as described above. Here's a Python script to extract audio from a video file using the moviepy library (note that moviepy 2.x dropped the old moviepy.editor module; you import from moviepy directly):