Python scripts that slice audios with silence detection
pip install librosa
pip install soundfile # Optional. You can use any library you like to write audio files.
or
pip install -r requirements.txt
import librosa
import soundfile
from slicer import Slicer
audio, sr = librosa.load('example.wav', sr=None) # Load an audio file with librosa
slicer = Slicer(
sr=sr,
db_threshold=-40,
min_length=5000,
win_l=400,
win_s=20,
max_silence_kept=500
)
chunks = slicer.slice(audio)
for i, chunk in enumerate(chunks):
soundfile.write(f'example_{i}.wav', chunk, sr) # Save sliced audio files with soundfile
TODO
This script may be quite slow due to convolution operations. Since the Slicer class is thread-safe, using multi-threading can speed up the process.