tyiannak / pyAudioAnalysis

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications
Apache License 2.0
5.76k stars 1.18k forks source link

Split Audio #334

Open engmohamedsalah opened 3 years ago

engmohamedsalah commented 3 years ago

How I can use this library to split audio into chunks for example, I have an audio file with a size of 100 seconds I need to cut that into small files from as following a file contains the audio from second 0 to second 5 a file contains the audio from second 23 to second 40 a file contains the audio from second 80 to second 90

I use the following code but I got an error message

`from pyAudioAnalysis import audioTrainTest as aT from pyAudioAnalysis import audioBasicIO from pyAudioAnalysis import ShortTermFeatures from pyAudioAnalysis import audioSegmentation as aS

[Fs, x] = audioBasicIO.read_audio_file("C:/Test/HelloDialog.wav") F, f_names = ShortTermFeatures.feature_extraction(x, Fs, 0.005Fs, 0.9Fs)`

is this correct ?

tyctor commented 3 years ago

maybe better to use sox command line tool for such tasks

tyiannak commented 3 years ago

Indeed u can use sox, or ffmpeg command line (check may article here for some examples https://medium.com/behavioral-signals-ai/basic-audio-handling-d4cc9c70d64d)

also there are plenty of examples in this library that show how u can do this programmatically using wavwrite (e.g. check the silence removal function wrapper that also saves the non-silence segments to wav files).