Skip to content

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

Open
@Rubix982

Description

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!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions