librosa: librosa.load (audioread) breaks on this audio file, not sure why?

Calling librosa.load('101729.wav', sr=None) (download file here) gives the following error:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-172-5d71d5777356> in <module>()
----> 1 audio, sr = librosa.load('101729.wav', sr=None)

/Users/justin/dev/miniconda3/envs/py27/lib/python2.7/site-packages/librosa/core/audio.pyc in load(path, sr, mono, offset, duration, dtype)
    121         n = 0
    122 
--> 123         for frame in input_file:
    124             frame = util.buf_to_float(frame, dtype=dtype)
    125             n_prev = n

/Users/justin/dev/miniconda3/envs/py27/lib/python2.7/site-packages/audioread/rawread.pyc in read_data(self, block_samples)
    110 
    111             # Make sure we have the desired bitdepth and endianness.
--> 112             data = audioop.lin2lin(data, old_width, TARGET_WIDTH)
    113             if self._needs_byteswap and self._file.getcomptype() != 'sowt':
    114                 # Big-endian data. Swap endianness.

error: Size should be 1, 2 or 4

Must be something about the file’s format that causes the problem, though I’m not sure what. Here’s the file info (as returned by pysox):

{'bitrate': 24,
 'channels': 2,
 'duration': 84.580021,
 'encoding': 'Signed Integer PCM',
 'num_samples': 4059841,
 'sample_rate': 48000.0,
 'silent': False}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

@pratistha you mentioned pyaudio, but my solution was to use pysoundfile (pip install pysoundfile). Then loading the audio is just:

import soundfile as sf
data, samplerate = sf.read('existing_file.wav')

Hope this helps!

To quote brmcfee, please refer to this thread https://groups.google.com/d/topic/librosa/Z1-HXBsHLi0/discussion.

DAn.

On Wed, Jul 12, 2017 at 3:53 AM, Khalidhussain1134 <notifications@github.com

wrote:

Hi Bmcfee, I got error while reading audio file using librosa.load(file.wav)

File “D:/DECASE2017/urbansoudclassification/urban.py”, line 37, in extract_features sound_clip, s = librosa.load(fn)

File “C:\Users\CL_1\Anaconda3\lib\site-packages\librosa\core\audio.py”, line 107, in load with audioread.audio_open(os.path.realpath(path)) as input_file:

File “C:\Users\CL_1\Anaconda3\lib\site-packages\audioread_init_.py”, line 116, in audio_open raise NoBackendError()

NoBackendError

What type of this error will be? Thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/librosa/librosa/issues/477#issuecomment-314685060, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhs0f3Yc3mLz19vdyNyM0GVMhkwrkOuks5sNHtmgaJpZM4LLDtd .

I have installed decoding library ffmpeg as mentioned in the group “https://groups.google.com/d/topic/librosa/Z1-HXBsHLi0/discussion

Now it is working, thank you

This is actually Python2’s audioop.lin2lin issue, which cannot handle 3-byte input. Python3 may handle this.