beetbox / beetbox/audioread

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

Open
#108 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
538
Forks
112
PR merge metrics
No merged PRs in 30d

Description

Hello!

I was using the following piece of code,
```python
audio, sample_rate = librosa.load(file_name, res_type='kaiser_fast')
```

But I was thrown the following error,

```python
--> 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!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported librosa.load call and the audioread backend path shown in the traceback. Reproduce the failure with the same Python audio-loading setup and determine why the source sample rate reaches resampling as zero. Done means the failing case is understood and the issue has a verified regression test or clearly documented resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
audio-video-rtc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.