Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a single audio file into multiple files?

I want to split a single audio file into multiple audio files using python and save them, the peaks in file is separated by silence. The audio file contains 5 A's

The waveform is given below: Waveform

I have tried librosa library and pydub codes for the same Also i have referred to this link: https://gist.github.com/kylemcdonald/c8e62ef8cb9515d64df4

But it is cutting file into 1 second equal interval and i don't want that. I want to split the file on basis of silence

import librosa as l
from scipy.io import wavfile
audio = l.load("D:/Downloads/Voice_a.wav")[0]
x = l.effects.trim(audio, top_db = 50)[0]

expected output is 5 different files each with a single 'A'

like image 761
Hrishikesh Vichore Avatar asked Feb 05 '26 15:02

Hrishikesh Vichore


1 Answers

I did some research and finally got the answer

def split(filepath):
    sound = AudioSegment.from_wav(filepath)
    dBFS = sound.dBFS
    chunks = split_on_silence(sound, 
        min_silence_len = 500,
        silence_thresh = dBFS-16)
    return chunks
like image 154
Hrishikesh Vichore Avatar answered Feb 07 '26 04:02

Hrishikesh Vichore