A Python-based command-line tool that transcribes audio and video files to text using OpenAI's Whisper API. Handles large files automatically by extracting audio from videos and splitting files into manageable chunks.
- Transcribes both audio and video files to text
- Automatic audio extraction from video files using ffmpeg
- Intelligent file splitting for files larger than 20MB
- Batch processing of multiple files
- Progress tracking with detailed logging
- Automatic cleanup of temporary files
- UTF-8 encoding support for international characters
- Audio:
.mp3,.m4a,.wav,.mpga - Video:
.mp4,.mpeg,.webm
- Python 3.7 or higher
- ffmpeg (for video processing)
- OpenAI API key
macOS:
brew install ffmpegLinux:
sudo apt update
sudo apt install ffmpegWindows: Download from ffmpeg.org and add to PATH.
git clone https://github.com/Axelj00/transcribe-video-and-audio.git
cd transcribe-video-and-audiopython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root:
cp .env.example .envEdit .env and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
You can get an API key from platform.openai.com.
You can customize the transcription behavior by adding these optional settings to your .env file:
Whisper Model Selection:
WHISPER_MODEL=gpt-4o-transcribe
Language Setting (improves accuracy if you know the language):
WHISPER_LANGUAGE=en
Common language codes: en (English), es (Spanish), fr (French), de (German), ja (Japanese), zh (Chinese)
Leave WHISPER_LANGUAGE unset or empty for automatic language detection.
- Place your audio or video files in the
input/folder - Run the transcription script:
python main.py- Find your transcriptions in the
results/folder as.txtfiles
The script will automatically:
- Detect all supported media files in the input folder
- Extract audio from video files
- Split large files into chunks
- Transcribe each file using OpenAI's Whisper API
- Save transcriptions with the same filename as the original (with
.txtextension)
======================================================================
Audio/Video Transcription Tool - Starting...
======================================================================
[19:03:40] Scanning 'input' folder for media files...
[19:03:40] Found 1 .mp4 file(s)
[19:03:40] Total files found: 1
[19:03:40] [1/1] Starting transcription: video.mp4
[19:03:40] Original file size: 3673.84 MB
[19:03:40] This is a video file, extracting audio track...
[19:04:04] Audio extracted successfully in 24.6 seconds
[19:04:04] Audio file is 74.60 MB (over 20MB limit)
[19:04:04] Splitting into 4 chunks of ~20m 20s each
[19:07:29] Successfully saved!
======================================================================
[19:07:29] ALL TRANSCRIPTIONS COMPLETE!
======================================================================
- File Detection: Scans the
input/folder for supported audio/video files - Audio Extraction: If the file is a video, extracts the audio track using ffmpeg
- File Splitting: If the audio is larger than 20MB, splits it into smaller chunks
- Transcription: Sends each chunk to OpenAI's Whisper API (gpt-4o-transcribe model)
- Merging: Combines transcriptions from multiple chunks if applicable
- Output: Saves the final transcription as a text file in
results/ - Cleanup: Removes all temporary files
This tool uses OpenAI's Whisper API. Pricing is based on audio duration:
- $0.006 per minute (as of 2024)
- Example: A 1-hour video costs approximately $0.36 to transcribe
Check current pricing at openai.com/pricing.
transcribe-video-and-audio/
├── main.py # Main transcription script
├── requirements.txt # Python dependencies
├── .env # API key (not committed to git)
├── .env.example # Template for .env file
├── .gitignore # Git ignore rules
├── input/ # Place your media files here
├── results/ # Transcriptions output here
└── README.md # This file
"ffmpeg not found" error:
- Make sure ffmpeg is installed and accessible in your PATH
- Installation instructions:
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg(or use your package manager) - Windows: Download from ffmpeg.org
- macOS:
- Test by running
ffmpeg -versionin your terminal
"No API key found" error:
- Ensure you've created a
.envfile in the project root - Verify your API key is correctly formatted in the
.envfile
Large file processing is slow:
- This is normal. Large files are split into chunks and processed sequentially
- A 1-hour video typically takes 3-5 minutes to transcribe
API errors:
- Check that your OpenAI API key is valid and has sufficient credits
- Verify your internet connection is stable
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Uses OpenAI's Whisper API for transcription
- Uses ffmpeg for audio/video processing