IM
imAbdelhadi/audio2srt
Convert audio files (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, and webm) to SRT subtitles with OpenAI Whisper. Easy script for fast, accurate transcription.
Audio to SRT Transcription (subtitle) Script using OpenAI Whisper
This script transcribes audio files in a specified folder to SRT (subtitle) format using the OpenAI Whisper API. The script processes multiple audio files and saves the transcriptions in a specified output folder.
Prerequisites
- Python 3.6 or higher
requestslibrarytqdmlibrary- OpenAI API key
Installation
- Clone the repository or download the script file.
- Install the required Python libraries using pip:
pip install requests tqdm- Obtain an OpenAI API key by signing up at OpenAI.
Setup
- Save your OpenAI API key in the script by replacing
'YOUR_API_KEY'with your actual API key. - Ensure you have a folder containing your audio files. create a folder called
audio_files, but you can change this in the script if needed. - Ensure the output folder (
srt_files) exists or will be created by the script.
Usage
- Place your audio files in the specified input folder (
audio_filesby default). Supported audio file formats includeflac,mp3,mp4,mpeg,mpga,m4a,ogg,wav, andwebm. - Chnage audio type on the line 39.
- Run the script:
python audio2srt.pyThe script will process each audio file in the input folder, transcribe it using the OpenAI API, and save the resulting SRT file in the output folder (srt_files by default).
Notes
- Ensure you have a stable internet connection while running the script, as it communicates with the OpenAI API.
- Handle your API key with care. Avoid sharing or exposing it in public repositories.