amsehili / auditok

An audio/acoustic activity detection and audio segmentation tool
MIT License
732 stars 94 forks source link

splitting the audio with overlaps. #19

Closed vaibhav0195 closed 4 years ago

vaibhav0195 commented 5 years ago

Hi thanks for this library. I was wondering if there is a way in which i can split my audio into smaller clips but with adjacent clips having overlapping samples. Example: Lets say I have a clip of 1min and it has silences from 10-20sec and then 30-40 secs and my max length of audio is lets say 5 secs. So I was wondering if there is a way in which i can get the splitted audio with duration lets say 1st audio from 0-5 then second audio from 3-8 (overlapping 4and 5 seconds) and so on?

Thanks any help is appreciated.

amsehili commented 4 years ago

Hello, I don't know if you still need this, in case you do, please check the new version on Github (cannot yet be installed via pip but will asap).

The split function returns a generator of AudioRegion that can be sliced manually. You can do something like this:


SLICE_DURATION = 5
OVERLAP = 3

regions = split("audiofile.wav", ...) # set other split parameters
reg = next(regions)
stop = int(reg.duration)
overlapping_regions = [reg[i:i+SLICE_DURATION] for i in range(0, stop, OVERLAP)]