How to find the average length of audio files in saved in a folder ?

152 views
Skip to first unread message

KRISHNA CHAUHAN

unread,
Oct 26, 2021, 1:41:21 PM10/26/21
to librosa
import librosa 
import glob 


path=glob.glob('E:/...*/*.wav')
 for i in range(len(path)) :
        y, sr = librosa.load(path[i], sr=16000)
        z=librosa.get_duration(y) return average(z)


How to find the average of all z values also can I find the max and min duration of audio files.

Brian McFee

unread,
Oct 26, 2021, 1:46:00 PM10/26/21
to librosa
1. You don't actually need to load the audio to determine its duration.  get_duration can probe this directly from the file and it will be much faster. (Refer to the documentation for how to do that.)
2. Durations are just numbers (in seconds), so you average them just like you would any other collection of numbers.  Probably you should collect them in a list if you want to do anything other than averaging.

KRISHNA CHAUHAN

unread,
Oct 27, 2021, 2:29:30 AM10/27/21
to librosa
before loading this was not working so I did that, also it's not giving any relevant output, I read the doc. How to find that? could anyone correct my code?
Reply all
Reply to author
Forward
0 new messages