1

Using this code for the same its working But how to display the average length of these audio files, also how to find maximum and minimum duration files?

import librosa

import glob
import librosa

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

Z/len(path)

1 Answers1

2

You can use code such as this. Using get_duration(filename=...) makes it work without having to load the files, which is much faster. Here we use a list comprehension to loop over paths and collect all the durations into a list.


import glob
import librosa
import numpy

paths = glob.glob('E:/...*/*.wav')
durations = [ librosa.get_duration(filename=p) for p in paths ]

stats = {
    'mean': numpy.mean(durations),
    'max': numpy.max(durations),
    'min': numpy.min(durations),
}

print(stats)
Jon Nordby
  • 5,494
  • 1
  • 21
  • 50