This script splits an audio file into multiple files based on silence gaps. Each non-silent segment is saved as a separate audio file, with optional silence padding before and after the segment.
pydub
libraryffmpeg
orlibav
installed on your system (required bypydub
)
All Python dependencies can be installed using requirements.txt
.
- Clone the repository or download the script:
git clone <repository_url>
cd <repository_directory>
- Install the required Python libraries:
pip install -r requirements.txt
-
Install
ffmpeg
:- On Ubuntu:
sudo apt-get install ffmpeg
- On macOS:
brew install ffmpeg
- On Windows: Download the executable from the ffmpeg official website and follow the installation instructions.
- On Ubuntu:
Run the script with the following command-line arguments:
python audio_splitter.py <audio_file> --out-dir <output_directory> [--padding <padding_duration>] [--min-silence-length <silence_length>]
<audio_file>
: The input audio file (e.g.,audio.mp3
).--out-dir
: The directory to save the split audio files.--padding
: (Optional) Duration of silence padding before and after each segment (in milliseconds). Default is1000
ms.--min-silence-length
: (Optional) Minimum duration of silence to use for splitting (in milliseconds). Default is500
ms.
To split audio.mp3
into segments based on silence and save the segments in the output
directory:
python audio_splitter.py audio.mp3 --out-dir output --padding 500 --min-silence-length 300
This project is licensed under the MIT License.
Happy splitting! 🎶