【问题标题】:How to read audio in python using Librosa?如何使用 Librosa 在 python 中读取音频?
【发布时间】:2019-10-10 21:32:43
【问题描述】:

我正在尝试在 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 都已安装但根本无法正常工作。如果您需要更多信息,请告诉我。

【问题讨论】:

  • 可能带有ffmpeg 的文件夹添加到变量PATH 这样您就可以在终端中运行它而不使用ffmpeg 的完整路径,然后脚本运行它也可能没有问题。

标签: python python-3.x audio ffmpeg librosa


【解决方案1】:

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

conda install -c conda-forge librosa

出了什么问题 pip install librosa 似乎无法正常工作。我需要通过conda install 安装librosa

希望对未来的访客有所帮助。

【讨论】:

  • 您可以创建一个新的用户环境并在那里安装。这也是迄今为止的首选方案。请注意,您的不同项目可能有相互冲突的要求。把所有东西都放在一个袋子里是自找麻烦。
  • 不。那是针对 macOS 而我的是在 Windows 中。
猜你喜欢
  • 1970-01-01
  • 2020-10-21
  • 1970-01-01
  • 2011-03-15
  • 2018-01-18
  • 1970-01-01
  • 2022-07-20
  • 1970-01-01
相关资源
最近更新 更多