5

I'm currently experimenting with librosa to reproduce an scientific approach (deep learning) that used PRAAT to extract the MFCCs of audio files. I'm not that experienced with phonetics/acoustics and I had a lot of issues understanding PRAAT - so I started using librosa whose API was more "accessible" for me.

The paper's authors used a Hamming window in the MFCC calculation and I tried to provide the function as additional parameter in the function call of mfcc or as part of **kwargs as dictionary:

import os
from scipy.signal import get_window
from librosa import load, get_duration
from librosa.feature import mfcc
import pandas
import tables
import matplotlib.pyplot as plt

# ...

kwargs = {"n_fft": 160, "hop_length": 80, "window": get_window("hamming", Nx=160)}
mfccs = mfcc(y=y, sr=sr, S=None, n_mfcc=12, **kwargs)

I still have a lot to learn about acoustics, so I'm not very sure about the values, but (considering the API) this should work. On my Windows computer running this commands in my Anaconda environment causes the following error:

processing  03a01Fa.wav ...
Traceback (most recent call last):
File "xxx\librosaData.py", line 37, in <module>
mfccs = mfcc(y=y, sr=sr, S=None, n_mfcc=12, **kwargs)
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\librosa\feature\spectral.py", line 1442, in mfcc
S = power_to_db(melspectrogram(y=y, sr=sr, **kwargs))
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\envs\xxx\lib\site-packages\librosa\feature\spectral.py", line 1534, in melspectrogram
mel_basis = filters.mel(sr, n_fft, **kwargs)
TypeError: mel() got an unexpected keyword argument 'window'

Process finished with exit code 1 

I tried this today on MacOS (also using an Anaconda environment) and it's causing no error. Most of the time I'm using the Windows computer for my experiments, because I can accelerate the calculations with CUDA. I'm not sure whether this is an Librosa-related issue, because I already had some other issues with my environments there (e.g. I couldn't persist a pandas.DataFrame using HDF5, but I somehow managed to fix this by myself. And PyCharm on Windows doesn't display my installed packages - not fixed yet, but less important).

I don't know what causes this behavior and I would really like to fix this problem. Did anybody encounter the same (or a similar) problem and found a way to fix it?

Thank you very much. :-)

Edit: As suggested in ZF007's answer I tried out to run the following script on (another/my private) Windows Computer:

import librosa

from scipy.signal import get_window

y, sr = librosa.load('audio/01-01-01-01-01-01-01.mp4',)
meltspec_args = {"n_fft": 160, "hop_length": 80, "window":  get_window("hamming", 160)}
mfccs = librosa.feature.mfcc(y=y, sr=sr, S=None, n_mfcc=12, **meltspec_args)

print(mfccs.shape)

But it still runs into the same error.

Edit2: I created a git repository to share code and configuration (https://github.com/Keanri828/librosa_mfcc_WindowsError).

Keanri
  • 96
  • 9
  • Hi, did you find the solution for this problem? – Milos Milunovic Jan 12 '20 at 13:36
  • Sadly not. I lost days during my thesis while I searched for a solution. I'm not sure whether it's a Python or Librosa issue. 'window' shouldn't be passed into the mel-filter-function. I don't know why this happens on Windows and Google Collab (in your case). – Keanri Jan 14 '20 at 10:06
  • Post "full" working example code and also link to your yml-file for people to recreate your conda env. (From Review). – ZF007 Jan 15 '20 at 11:18
  • 2
    Thank you. I don't know wether I can post it today, because I'm currently working on another project and I don't have much time today. My code changed due to refactoring and I didn't touch it since my thesis' deadline in December. I'll need a moment for writing a small, but full working example and testing out your suggestions below. – Keanri Jan 15 '20 at 12:14
  • n.v.m.. the error is in parsing `Nx=160` into the get_window(str, int, kwarg1) function. See my updated answer. – ZF007 Jan 15 '20 at 14:46
  • I created a repository on GitHub to share code and yml-file: https://github.com/Keanri828/librosa_mfcc_WindowsError – Keanri Jan 16 '20 at 14:05

1 Answers1

2

So... I finally know why this happens, because I opened an issue in the librosa repository (https://github.com/librosa/librosa/issues/1060):

Conda somehow installed 0.6.3 instead of >0.7. These parameters are supported since version 0.7. Due to the fact that I installed Anaconda today I embarrassingly did not compare the versions between this computer and my Mac (using 0.7.1 without any installing issues).

It seems to be a package issue that is not solved yet.

I'll keep this "answer" up-to-date.

Keanri
  • 96
  • 9