failed to hear audio on jupyter with librosa but can with scipy – sampling rate issues?


I can hear audio in jupyter if loaded with scipy.
However, I can hear untill 192000 sampling rate. If I set to 192001 or above, I cannot hear anything.

from IPython.display import Audio
from import read

wave_filename = 'mywave.wav'

fs, data = read(wave_filename, mmap=True)  # fs - sampling frequency
data = data.reshape(-1, 1)
Audio(data = data[:, 0], rate = 180000)

I try the same with librosa:

from IPython.display import Audio
import librosa

wave_filename = 'mywave.wav'

data, fs = librosa.load(wave_filename)  # fs - sampling frequency
Audio(data = data, rate = 120000)

But cannot hear nothing, for any rate value I set.

What can the issue be?

Note – with librosa I can hear a synthetic sound, using a numpy array. But not from original wave.

(p.s. original sampling rate is 250000, I m working with animals vocalisations..)

Asked By: user305883



The issue could be related to the maximum sampling rate supported by your audio system. Most audio devices have a maximum sampling rate supported, and anything beyond that will not be played.

In your case, it seems that your audio system can play audio with sampling rates up to 192000, but not higher. This is why you can hear audio using scipy, but not with librosa.

To confirm this, you can try playing the audio file outside of Jupyter using a media player or audio editor that supports high sampling rates.

If you want to play audio with a sampling rate higher than what your audio system supports, you can try resampling the audio to a lower sampling rate using the librosa.resample function, for example:

from IPython.display import Audio
import librosa

wave_filename = 'mywave.wav'
sr_target = 192000  # or any other value supported by your audio system

data, fs = librosa.load(wave_filename, sr=sr_target)
Audio(data=data, rate=sr_target)

This will resample the audio file to the specified target sampling rate before playing it. Note that resampling may result in some loss of quality, so it’s generally best to work with the original sampling rate whenever possible.

Answered By: Dex Special