Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

librosa does not normalize wave file between [-1, 1]

In passing a file via the use:

librosa_audio, librosa_sample_rate = librosa.load(filename)

The output produces an audio file such that:

Librosa audio file min~max range: -1.2105224 to 1.2942806

The file that I am working on was obtained from https://www.boomlibrary.com/ and had a bit depth of 24. I down sampled to 16 and also up sampled to 32 to work with librosa. Both of these files produced the same min-max range after going through librosa.

Why does this happen?
Is there a way to parse the wav file to Librosa such that the data will fall between [-1,1]?

Here is a link to the files:

https://drive.google.com/drive/folders/12a0ii5i0ugyvdMMRX4MPfWMSN0arD0bn?usp=sharing

like image 272
Joe Avatar asked Apr 15 '26 10:04

Joe


1 Answers

The behaviour you are observing stems directly from resampling to 22050 Hz that librosa load does by default:

librosa.core.load(path, sr=22050)

Resampling process always affects the audio, hence you see values that are not normalized. You have to do this yourself.

More likely, you wanted to read the audio with the native sampling rate, in which case you should have passed None to sr like this:

librosa.core.load(path, sr=None)

Example based on the audio sample you have provided:

In [4]: y, sr = librosa.load('201-AWCKARAK47Close0116BIT.wav', sr=None)
In [5]: y.max()
Out[5]: 0.9773865

In [6]: y.min()
Out[6]: -0.8358917
like image 69
Lukasz Tracewski Avatar answered Apr 17 '26 00:04

Lukasz Tracewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!