I am trying to load the audio files into the NumPy array using this code
#%%
import librosa
import matplotlib.pyplot as plt
import IPython.display as ipd
import os, os.path
import time
import joblib
import numpy as np
#%%
fname = 'archive\\Actor_01\\03-01-01-01-01-01-01.wav'
data, sampling_rate = librosa.load(fname)
plt.figure(figsize=(15, 5))
librosa.display.waveshow(data, sr=sampling_rate)
ipd.Audio(fname)
# %%
lst = []
for subdir, dirs, files in os.walk('archive'):
for file in files:
try:
X, sample_rate = librosa.load(os.path.join(subdir, file), res_type='kaiser_fast')
mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T, axis=0)
file_class = int(file[7:8]) - 1
arr = mfccs, file_class
lst.append(arr)
except ValueError as err:
print(err)
continue
Everything runs fine except I am getting an error at line 25
ModuleNotFoundError Traceback (most recent call last)
c:\Users\powellt1\Documents\COMP5500\NonGitSED\algorithm.py in line 7
23 for file in files:
24 try:
----> 25 X, sample_rate = librosa.load(os.path.join(subdir, file), res_type='kaiser_fast')
26 mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T, axis=0)
27 file_class = int(file[7:8]) - 1
File c:\Users\powellt1\AppData\Local\Programs\Python\Python311\Lib\site-packages\librosa\core\audio.py:193, in load(path, sr, mono, offset, duration, dtype, res_type)
190 y = to_mono(y)
192 if sr is not None:
--> 193 y = resample(y, orig_sr=sr_native, target_sr=sr, res_type=res_type)
195 else:
196 sr = sr_native
File c:\Users\powellt1\AppData\Local\Programs\Python\Python311\Lib\site-packages\librosa\core\audio.py:684, in resample(y, orig_sr, target_sr, res_type, fix, scale, axis, **kwargs)
675 y_hat = np.apply_along_axis(
676 soxr.resample,
677 axis=axis,
(...)
681 quality=res_type,
682 )
683 else:
--> 684 y_hat = resampy.resample(y, orig_sr, target_sr, filter=res_type, axis=axis)
I know I have librosa installed properly and it works in the previous cells.
I've tried to reinstall and verify the installation of librosa and I've tried using
from librosa.core import load
but nothing seems to be working to fix the error.
I figured out after coming through the documentation that you have to install resampy package separately from the librosa package itself. After installing the package I was able to get it to work.