gpt4 book ai didi

python - 不能将 librosa 与 python 3 一起使用

转载 作者:行者123 更新时间:2023-12-05 01:35:36 24 4
gpt4 key购买 nike

我已经在 Windows 的 ubuntu 子系统上使用 pip3 正确安装了 librosa,但是当我尝试执行一个像这样的简单程序时:

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

事情是这样的:

/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

我做错了什么?

最佳答案

根据 the manual您可能还需要安装 ffmpeg,以允许 librosa 解码各种格式。

由于您在 Ubuntu 子系统中工作,只需

apt install ffmpeg

应该可以解决问题。

关于python - 不能将 librosa 与 python 3 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62774301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com