A minimal, elegant CLI tool to convert audio files to SRT subtitle format using OpenAI's Whisper API.
- Convert audio files (MP3, MP4, MPEG, MPGA, M4A, WAV, WEBM) to SRT subtitles
- Clean, simple Python implementation
- Uses OpenAI's official Whisper API
- Automatic timestamp generation
-
Clone this repository or download the files
-
Install dependencies:
pip install -r requirements.txt- Set up your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'Or create a .env file:
cp .env.example .env
# Edit .env and add your API keypython whisper_to_srt.py audio.mp3python whisper_to_srt.py podcast.mp3 subtitles.srtfrom whisper_to_srt import convert_to_srt
# Convert with default settings
convert_to_srt("podcast.mp3")
# Specify output path
convert_to_srt("podcast.mp3", "output/subtitles.srt")
# Use custom API key
convert_to_srt("podcast.mp3", api_key="sk-...")- Python 3.10+
- OpenAI API key with access to Whisper API
- Audio file in supported format (MP3, MP4, MPEG, MPGA, M4A, WAV, WEBM)
OpenAI Whisper API pricing is $0.006 per minute of audio (as of 2024).
MIT