1

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.

3 Answers3

0

First try this: To check all the installed Python modules, we can use the following two commands with the 'pip': Using 'pip freeze' command. Using 'pip list command. you should run pip with the same way you run your program, for example: python -m pip ... if you cant find librosa, try installing it the python -m way. If you find it and it doesn't load, try loading it in the installation directory for example.

EDIT: ModuleNotFoundError: No module named 'librosa' this article states that it could also be a dependency error, try installing those too, with python -m pip

NoBlockhit
  • 369
  • 2
  • 15
  • I was able to find librosa and it does work in the previous use "data, sampling_rate = librosa.load(fname)" but I am getting the error for the specific use of librosa stated in the question. – DaddyMuffin Jun 07 '23 at 19:45
0

As you can see , the ModuleNotFoundError is not for Librosa module at all. It is for a module that is used either within the librosa module or you are passing in the wrong dimensions (not likely , but check.)

Also, check if there is any filter names 'kaiser_fast' , I think that is what is causing error.

coder_n007
  • 40
  • 4
  • According to the resample_type documentation, there is a type called 'kaiser_fast'. https://librosa.org/doc/main/generated/librosa.resample.html#librosa.resample – DaddyMuffin Jun 07 '23 at 19:43
0

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.