audioread.exceptions.NoBackendError 在 librosa 中

huangapple go评论67阅读模式
英文:

audioread.exceptions.NoBackendError in librosa

问题

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".

我尝试将音频文件加载到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'

答案1

得分: 10

  1. librosa 无法直接读取 mp3 文件,因此它尝试使用 audioread 包。

  2. Audioread 尝试利用多种不同的可能已安装或未安装的包。其中之一是 ffmpeg

  3. 但是它通过 '通过其命令行界面' 使用 FFmpeg。我认为这是 pip 安装 FFmpeg 不起作用的原因。它需要 ffmpeg.exe 文件。

  4. 您可以从这里下载 ffmpeg 安装程序。

  5. 安装后,请确保可以从命令行启动 ffmpeg(输入 ffmpeg -h)。您可能需要将安装文件夹的路径(例如 c:\ffmpeg\bin)添加到 Windows 路径中。

  6. 最后,请确保重新启动您的集成开发环境。Visual Studio Code 可能需要重启才能识别新的路径。

英文:

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.

答案2

得分: 6

在Ubuntu上,我通过以下命令解决了这个问题:

sudo apt update
sudo apt install ffmpeg

pip install ffmpeg 对我没有起作用。

英文:

In ubuntu I resolved it by following command

sudo apt update
sudo apt install ffmpeg

pip install ffmpeg did not worked for me

答案3

得分: 2

我在Windows 10上遇到了相同的问题,在安装ffmpeg并配置到PATH后,它可以工作。需要重新启动Python会话。

英文:

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

答案4

得分: 2

我假设你已经解决了你的问题,但如果有其他人遇到这个问题:

我安装了ffmpeg(以下代码)并且它起作用了。

pip install ffmpeg
英文:

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

答案5

得分: 0

wav文件应该被原生支持,根据https://github.com/librosa/librosa/issues/219
而mp3则需要后端支持,例如ffmpeg。

英文:

答案6

得分: 0

我也遇到过这个问题,问题是我只部分下载了目标的.wav文件,因此它损坏了。一旦我重新下载文件并再次尝试,它就正常工作了。在我的情况下,错误有点误导,因为后端是可用的并且正常工作。因此,如果这里的建议都不起作用,尝试在音乐播放器中加载目标文件以确认其真实性。

英文:

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.

huangapple
  • 本文由 发表于 2020年1月3日 22:48:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定