Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Rubix982 opened this issue Aug 26, 2020 · 10 comments

Comments

@Rubix982
Copy link

Rubix982 commented Aug 26, 2020

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, librosa/librosa#765, but the solution to the problem by the author has not been stated.

Help would be appreciated. Thank you!

@sampsyo
Copy link
Member

sampsyo commented Aug 26, 2020

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
Copy link
Author

Rubix982 commented Aug 27, 2020

Hi!! Thanks for the response!
A similar issue is here, librosa/librosa#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
Copy link
Author

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
Copy link
Member

sampsyo commented Aug 27, 2020

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

  • We can figure out why audioread is reporting a zero sample rate.
  • Librosa can consider avoiding a crash when we report a zero sample rate.

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
Copy link
Author

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

@Rubix982
Copy link
Author

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

@Stapelueberflieger
Copy link

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 librosa/librosa#765 (comment)

@Rubix982
Copy link
Author

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
Copy link

Stapelueberflieger commented Nov 19, 2020

#librosa/librosa#765 (comment)
@Rubix982
Now it just got killed. Perhaps the pi is not powerful enough to analyse? I will setup pi2.

@Rubix982
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants