I am trying to load an audio file using librosa
for an audio classification project. However, when I run the code, I get an OSError
with the message cannot load library 'C:\Users\beek6\anaconda3\envs\tensorflow2\Library\bin\sndfile.dll': error 0x7e
. The relevant code snippet is:
audio_file_path = '17973-2-0-32.wav'
librosa_audio_data, librosa_sample_rate = librosa.load(audio_file_path)
Additionally, I get the following error traceback:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
File ~\anaconda3\envs\tensorflow2\lib\site-packages\soundfile.py:161
159 raise OSError('no packaged library for this platform')
--> 161 import _soundfile_data # ImportError if this doesn't exist
162 _path = _os.path.dirname(_soundfile_data.__file__) # TypeError if __file__ is None
ModuleNotFoundError: No module named '_soundfile_data'
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
File ~\anaconda3\envs\tensorflow2\lib\site-packages\soundfile.py:171
170 raise OSError('sndfile library not found using ctypes.util.find_library')
--> 171 _snd = _ffi.dlopen(_libname)
173 except OSError:
174 # Try explicit file name, if the general does not work (e.g. on nixos)
OSError: cannot load library 'C:\Users\beek6\anaconda3\envs\tensorflow2\Library\bin\sndfile.dll': error 0x7e
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
Cell In[11], line 2
1 audio_file_path = '17973-2-0-32.wav'
----> 2 librosa_audio_data, librosa_sample_rate = librosa.load(audio_file_path)
File ~\anaconda3\envs\tensorflow2\lib\site-packages\lazy_loader\__init__.py:77, in attach.<locals>.__getattr__(name)
75 submod_path = f"{package_name}.{attr_to_modules[name]}"
76 submod = importlib.import_module(submod_path)
---> 77 attr = getattr(submod, name)
79 # If the attribute lives in a file (module) with the same
80 # name as the attribute, ensure that the attribute and *not*
81 # the module is accessible on the package.
82 if name == attr_to_modules[name]:
File ~\anaconda3\envs\tensorflow2\lib\site-packages\lazy_loader\__init__.py:76, in attach.<locals>.__getattr__(name)
74 elif name in attr_to_modules:
75 submod_path = f"{package_name}.{attr_to_modules[name]}"
---> 76 submod = importlib.import_module(submod_path)
77 attr = getattr(submod, name)
79 # If the attribute lives in a file (module) with the same
80 # name as the attribute, ensure that the attribute and *not*
81 # the module is accessible on the package.
File ~\anaconda3\envs\tensorflow2\lib\importlib\__init__.py:127 in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1030 in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1007 in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:986 in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:680 in _load_unlocked(spec)
File <frozen importlib._bootstrap_external>:850 in exec_module(self, module)
File <frozen importlib._bootstrap>:228 in _call_with_frames_removed(f, *args, **kwds)
File ~\anaconda3\envs\tensorflow2\lib\site-packages\librosa\core\audio.py:10
7 import pathlib
8 import warnings
--> 10 import soundfile as sf
11 import audioread
12 import numpy as np
File ~\anaconda3\envs\tensorflow2\lib\site-packages\soundfile.py:192
190 _snd = _ffi.dlopen(_os.path.join(_hbrew_path, _explicit_libname))
191 else:
--> 192 _snd = _ffi.dlopen(_explicit_libname)
194 __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
195 if __libsndfile_version__.startswith('libsndfile-'):
OSError: cannot load library 'libsndfile.dll': error 0xc1
What is causing this problem and how can I fix it?