如何使用 Librosa 读取 python 中的音频?

How to read audio in python using Librosa?

我正在尝试在 Librosa 中读取音频文件,但出现以下错误

FileNotFoundError: [WinError 2] The system cannot find the file specified

有人说我需要在某处安装ffmpeg,但并没有解决问题。我在 ffmpeg in c:\programdata\anaconda3\lib\site-packages (1.4).

安装了 ffmpeg

这是我用来读取示例音频文件的示例代码

import librosa
filename = librosa.util.example_audio_file()
print(filename)
y, sr = librosa.load(filename)

它在第 4 行抛出此错误

C:\ProgramData\Anaconda3\lib\site-packages\librosa\util\example_data\Kevin_MacLeod_-_Vibe_Ace.ogg
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-7-0780b3498898> in <module>
      1 filename = librosa.util.example_audio_file()
      2 print(filename)
----> 3 y, sr = librosa.load(filename)

C:\ProgramData\Anaconda3\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    117 
    118     y = []
--> 119     with audioread.audio_open(os.path.realpath(path)) as input_file:
    120         sr_native = input_file.samplerate
    121         n_channels = input_file.channels

C:\ProgramData\Anaconda3\lib\site-packages\audioread\__init__.py in audio_open(path, backends)
    105     """
    106     if backends is None:
--> 107         backends = available_backends()
    108 
    109     for BackendClass in backends:

C:\ProgramData\Anaconda3\lib\site-packages\audioread\__init__.py in available_backends()
     84 
     85     # FFmpeg.
---> 86     if ffdec.available():
     87         result.append(ffdec.FFmpegAudioFile)
     88 

C:\ProgramData\Anaconda3\lib\site-packages\audioread\ffdec.py in available()
    106         stdout=subprocess.PIPE,
    107         stderr=subprocess.PIPE,
--> 108         creationflags=PROC_FLAGS,
    109     )
    110     proc.wait()

C:\ProgramData\Anaconda3\lib\site-packages\audioread\ffdec.py in popen_multiple(commands, command_args, *args, **kwargs)
     92         cmd = [command] + command_args
     93         try:
---> 94             return subprocess.Popen(cmd, *args, **kwargs)
     95         except OSError:
     96             if i == len(commands) - 1:

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    767                                 c2pread, c2pwrite,
    768                                 errread, errwrite,
--> 769                                 restore_signals, start_new_session)
    770         except:
    771             # Cleanup if the child failed starting.

C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1170                                          env,
   1171                                          os.fspath(cwd) if cwd is not None else None,
-> 1172                                          startupinfo)
   1173             finally:
   1174                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

我不确定这里有什么问题。 Librosaffmpeg 都已安装但根本无法运行。如果您需要更多信息,请告诉我。

通过以下方式解决 使用 admin 权限打开 anaconda promt 并且 运行 在行

之后
conda install -c conda-forge librosa

问题是什么 似乎 pip install librosa 没有正常工作。我需要通过 conda install.

安装 librosa

希望对以后的访客有所帮助。