A simple yet powerful tool to split audio files using FFmpeg.
CLI-based audio segmentation made easy.
Click to collapse/expand
audio_splitter
is a lightweight CLI tool built to split audio files (and automatically extract audio from video files) into smaller, fixed-duration segments using FFmpeg and the Python library ffmpeg-python.
I initially developed audio_splitter
to complement my other project, Whisper_Transcriber, enhancing the workflow for transcribing audio files via OpenAI's Whisper API. Two main motivations drove the creation of this utility:
- Whisper's API Duration Limit: Whisper API strictly limits the maximum audio duration per transcription request, necessitating prior audio segmentation.
- Clearer Cost Monitoring & Control: Splitting audio into shorter segments allows for precise monitoring of transcription costs per request, enabling better budget management and visibility into Whisper API credit usage.
audio_splitter
seamlessly handles multiple audio formats (MP3, WAV, M4A, FLAC, etc.) and extracts audio from popular video formats (MP4, AVI, MKV, MOV), converting them automatically into MP3 segments. It thus provides a practical solution for audio management and transcription tasks.
The primary goal of audio_splitter is to streamline and simplify audio preprocessing, offering a straightforward and effective solution to quickly segment lengthy audio and video recordingsโespecially when used in conjunction with tools like
Whisper_Transcriber
.
โ๏ธ Features of audio_splitter
- โ Quickly splits audio and video files into customizable-duration segments.
- โ Supports major audio formats (MP3, WAV, M4A, FLAC, and others).
- โ Automatically extracts and converts audio tracks from videos (MP4, AVI, MKV, MOV).
- โ Fast and accurate segmentation powered by FFmpeg and the Python package ffmpeg-python.
- โ Built-in utility for cleaning temporary files (e.g., .pyc, cache, logs).
- โ Intuitive and user-friendly CLI, with optional detailed logging and debug mode.
Before getting started, make sure you meet the following prerequisites.
- Python 3: Ensure Python 3 is installed on your system.
โ ๏ธ Note: audio_splitter has been tested on Python 3.11.10 under Linux. While it might work on other versions or operating systems, compatibility is officially guaranteed only for this specific setup.
- Dependencies: Install the required Python dependencies using pip:
pip install -r requirements.txt
ffmpeg-python requires FFmpeg to be installed on your system. Please ensure that FFmpeg is installed and accessible via your system's PATH.
- Clone the repository via Git:
git clone https://github.com/franckferman/audio_splitter.git
- Go to GitHub repo.
- Click
<> Code
โDownload ZIP
. - Extract the archive to your desired location.
Below you'll find common commands and usage examples for audio_splitter
.
To quickly view all available commands and options:
python3 src/audio_splitter.py --help
- split: Splits audio files into segments of customizable duration.
- clean: Cleans temporary and unwanted files from the project.
Use the split command to split audio files into smaller segments.
Split an audio file into segments of 10 minutes (600 seconds) each:
python3 src/audio_splitter.py split ./audio/example.mp3 ./output/ --duration 600
Argument | Description | Example |
---|---|---|
input_file |
Path to the input audio/video file | ./my_audio.mp3 |
output_folder |
Directory where split segments will be saved | ./output |
-d, --duration |
Duration in seconds of each segment (default: 600) | -d 300 (5-minute segments) |
--debug |
Enable verbose debug logging | --debug |
Split a video file (e.g., MP4) by extracting audio automatically and creating 5-minute segments with debug enabled:
python3 src/audio_splitter.py split ./videos/lecture.mp4 ./segments/ --duration 300 --debug
Use the clean command to remove temporary files from your project.
To clean temporary files (like .pyc, pycache) from your current directory:
python3 src/audio_splitter.py clean
We truly appreciate and welcome community involvement. Your contributions, feedback, and suggestions play a crucial role in improving the project for everyone. If you're interested in contributing or have ideas for enhancements, please feel free to open an issue or submit a pull request on our GitHub repository. Every contribution, no matter how big or small, is highly valued and greatly appreciated!
Explore the star history of this project and see how it has evolved over time:
Your support is greatly appreciated. We're grateful for every star! Your backing fuels our passion. โจ
This project is licensed under the GNU Affero General Public License, Version 3.0. For more details, please refer to the LICENSE file in the repository: Read the license on GitHub