4

I have installed librosa correctly with pip3 on ubuntu subsystem on windows, but when I try to execute a simple program like this one:

import librosa
data, sr = librosa.load('sound.mp3')
print(data.shape)

It is what happens:

/home/henistein/librosa/librosa/core/audio.py:144: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn('PySoundFile failed. Trying audioread instead.')
Traceback (most recent call last):
  File "/home/henistein/librosa/librosa/core/audio.py", line 128, in load
    with sf.SoundFile(path) as sf_desc:
  File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 740, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 1264, in _open  
    _error_check(_snd.sf_error(file_ptr),
  File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 1455, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'sound.mp3': File contains data in an unknown format.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "PerfectPitch.py", line 2, in <module>
    data, sr = librosa.load('sound.mp3')
  File "/home/henistein/librosa/librosa/core/audio.py", line 145, in load
    y, sr_native = __audioread_load(path, offset, duration, dtype)
  File "/home/henistein/librosa/librosa/core/audio.py", line 169, in __audioread_load
    with audioread.audio_open(path) as input_file:
  File "/home/henistein/.local/lib/python3.8/site-packages/audioread/__init__.py", line 116, in audio_open
    raise NoBackendError()
audioread.exceptions.NoBackendError

What am I doing wrong?

1 Answers1

6

According to the manual you'll probably also need to install ffmpeg, to allow for librosa to decode various formats.

Since you're working in the Ubuntu subsystem, simply

apt install ffmpeg

should do the trick.

Stuart
  • 9,597
  • 1
  • 21
  • 30
AKX
  • 152,115
  • 15
  • 115
  • 172