beetbox / audioread

cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python
MIT License
481 stars 108 forks source link

Bug: Error when reading file with librosa, audioread reports `float division by zero` error #108

Open Rubix982 opened 3 years ago

Rubix982 commented 3 years ago

Hello!

I was using the following piece of code,

audio, sample_rate = librosa.load(file_name, res_type='kaiser_fast')

But I was thrown the following error,

--> 103     audio, sample_rate = librosa.load(file_name, res_type='kaiser_fast')
    104     mfccs = librosa.feature.mfcc(y=audio, sr=sample_rate, n_mfcc=40)
    105     mfccs_processed = np.mean(mfccs.T,axis=0)

/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    170 
    171     if sr is not None:
--> 172         y = resample(y, sr_native, sr, res_type=res_type)
    173 
    174     else:

/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py in resample(y, orig_sr, target_sr, res_type, fix, scale, **kwargs)
    551         return y
    552 
--> 553     ratio = float(target_sr) / orig_sr
    554 
    555     n_samples = int(np.ceil(y.shape[-1] * ratio))

ZeroDivisionError: float division by zero

I was trying to load a .mp3 using librosa, while using audioread as a backend. I am not sure why the error is ocuring, but I'll use a try - catch block to avoid it. A similar issue is here, https://github.com/librosa/librosa/issues/765, but the solution to the problem by the author has not been stated.

Help would be appreciated. Thank you!

sampsyo commented 3 years ago

Hi! It looks like this error happens in librosa code, not in audioread code. So I'm not sure we can do anything about it… do you have more information that indicates that something is wrong in audioread itself?

Rubix982 commented 3 years ago

Hi!! Thanks for the response! A similar issue is here, https://github.com/librosa/librosa/issues/765 , but quoting one of the comments from there,

Thanks for reporting this. I've never seen that before, but I'm pretty sure that it's coming from an upstream dependency (audioread) incorrectly reporting the sample rate of the input file as 0, when it should be 44100. Why it's doing that, I'm not sure, but it's probably something going wrong in one of audioread's codec backends (ffmpeg or gstreamer). I suggest that you take it up with the audioread developers.

Which gave me the impression that this issue comes from audioread or from it's codec backends as mentioned. I'm really new to audioread / librosa, so I maybe wrong about this assumption.

Rubix982 commented 3 years ago

Also, I was actually reading a .mp3 file instead of a wav file using librosa. I message that I got when I did was a warning that said,

/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py:162: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn("PySoundFile failed. Trying audioread instead.")
sampsyo commented 3 years ago

Got it; thanks for clarifying. It seems like there are two independent things to be done:

In any case, for the audioread side of things, the thing to do is to try to reproduce the problem. To that end, can you share an example file that triggers the problem? Details about your system setup would also be helpful.

Rubix982 commented 3 years ago

Of course, let me write a script for this quick.

Rubix982 commented 3 years ago

Edit, it was with a specific audio clip. I'm trying to find that right now. :/ Be back in a few hours.

Stapelueberflieger commented 3 years ago

Edit, it was with a specific audio clip. I'm trying to find that right now. :/ Be back in a few hours.

@Rubix982 I encounter the same issue. Did you solve it? For more info pls look at 765 https://github.com/librosa/librosa/issues/765#issuecomment-730489687

Rubix982 commented 3 years ago

I did not, @Stapelueberflieger It was an error I encountered was during a Kaggle competition with shuffled data. That was about more than 500 audio clips, and I was unable to determine which one exactly caused this issue, so I closed the issue instead. :/ Yeah, sure, let me take a look at it.

Stapelueberflieger commented 3 years ago

https://github.com/librosa/librosa/issues/765#issuecomment-730515664

@Rubix982 Now it just got killed. Perhaps the pi is not powerful enough to analyse? I will setup pi2.

Rubix982 commented 3 years ago

@Stapelueberflieger try out ps aux to see where the hardware consumption is going towards. Maybe you might need a lighter version for the device you have.