audioread.exceptions.NoBackendError in librosa
Asked Answered
C

6

8
import librosa
import librosa.display
import IPython.display
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.font_manager as fm

audio_path = 'rec.wav'
y, sr = librosa.load(audio_path)

I tried to load the audio file into librosa. So I wrote the code like that. But I get the error "File contains data in an unknown format", "File contains data in an unknown format".

I searched on Google and I was told to install ffmpeg. So I installed ffmpeg but still get the error

What's wrong? (I guess there is a problem with the encoding.........)

all error messege:

Traceback (most recent call last):
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 129, in load
    with sf.SoundFile(path) as sf_desc:
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 629, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1184, in _open
    "Error opening {0!r}: ".format(self.name))
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1357, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'rec.mp3': File contains data in an unknown format.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/****/PycharmProjects/pitch_project_/pitdetec.py", line 12, in <module>
    y, sr = librosa.load(audio_path)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 147, in load
    y, sr_native = __audioread_load(path, offset, duration, dtype)
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 171, in __audioread_load
    with audioread.audio_open(path) as input_file:
  File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open
    raise NoBackendError()
audioread.exceptions.NoBackendError 

try:

audio_path = 'C:/Users/ddolcju/PycharmProjects/pitch_project/rec.mp3'
Confess answered 3/1, 2020 at 14:48 Comment(2)
I found that installing librosa via miniconda gives the best results and usually avoids the missing library issues.Alvar
Thank you, but problem was not solved.Confess
D
10

There are few things you need to check:

  1. librosa can't read mp3 files directly so it tries to use the audioread package.

  2. Audioread tries to utilise a number of different packages that may or may not be installed. One of those is ffmpeg.

  3. However it uses FFmpeg 'via its command-line interface'. I think this is the reason that pip installing FFmpeg doesn't work. It needs the ffmpeg.exe file.

  4. You can download the ffmpeg installer from here

  5. After it is installed make sure you can start ffmpeg from the command line (type ffmpeg -h). You will probably need to add the path to the install folder (eg c:\ffmpeg\bin) to the Windows path.

  6. Finally, make sure to restart your IDE. Visual Studio Code probably won't recognise the new path until after a reset.

Desolation answered 23/12, 2020 at 5:28 Comment(0)
S
6

In ubuntu I resolved it by following command

sudo apt update
sudo apt install ffmpeg

pip install ffmpeg did not worked for me

Sorn answered 30/7, 2022 at 17:40 Comment(1)
Thank you very much for this. Installing ffmpeg in Ubuntu Ubuntu 22.04.1 LTS x86_64 indeed solved the issue for me.Fronton
H
2

I got the same problem on windows 10, after installing ffmpeg and configuring it to PATH, it works. Need restart a python session.

Halvorsen answered 26/3, 2020 at 6:29 Comment(0)
V
2

I'm assuming that you solved your problem, but if anyone else has this problem:

I installed ffmpeg (the following code) and it worked.

pip install ffmpeg
Veradia answered 1/2, 2021 at 19:1 Comment(0)
Z
0
Zeringue answered 14/9, 2021 at 20:44 Comment(0)
J
0

I also had this problem and the issue was that I had only partially downloaded the targetted .wav file and it was therefore corrupted. Once I re-downloaded the file and tried again it worked fine. The error was a bit misleading in my case because the backend was available and working. As such, if none of the suggestions here work, try loading your target file in a music player to confirm its veracity.

Jurywoman answered 10/5, 2023 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.