Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

audioread.exceptions.NoBackendError in librosa

Tags:

python

librosa

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'
like image 972
kimhanuu Avatar asked Mar 03 '23 23:03

kimhanuu


1 Answers

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.

like image 74
Andrew Avatar answered Mar 05 '23 15:03

Andrew