Skip to content Skip to sidebar Skip to footer

Difference Between Load Of Librosa And Read Of Scipy.io.wavfile

I have a question about the difference between the load function of librosa and the read function of scipy.io.wavfile. from scipy.io import wavfile import librosa fs, data = wavfi

Solution 1:

From the docstring of librosa.core.load:

Load an audio file as a floating point time series.

Audio will be automatically resampled to the given rate (default sr=22050).

To preserve the native sampling rate of the file, use sr=None.

scipy.io.wavfile.read does not automatically resample the data, and the samples are not converted to floating point if they are integers in the file.


Solution 2:

It's worth also mentioning that librosa.load() normalizes the data (so that all the data points are between 1 and -1), whereas wavfile.read() does not.


Solution 3:

librosa.core.load has support for 24 bit audio files and 96kHz sample rates. Because of this, converting to float and default resampling, it can be considerably slower than scipy.io.wavfile.read in many cases.


Solution 4:

The data is different because scipy does not normalize the input signal.

Here is a snippet showing how to change scipy output to match librosa's:

nbits = 16

l_wave, rate = librosa.core.load(path, sr=None)
rate, s_wave = scipy.io.wavfile.read(path)

s_wave /= 2 ** (nbits - 1)

all(s_wave == l_wave)
# True

Post a Comment for "Difference Between Load Of Librosa And Read Of Scipy.io.wavfile"