MTG / essentia

C++ library for audio and music analysis, description and synthesis, including Python bindings
http://essentia.upf.edu
GNU Affero General Public License v3.0
2.83k stars 530 forks source link

Error cannot convert parameter REAL to INTEGER #927

Closed erbazkhan closed 3 years ago

erbazkhan commented 4 years ago

I am new to Python and Essentia, and trying to extract features from audio files, but MFCC is giving an error.

Check1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/essentia/standard.py in configure(self, **kwargs)
     55                 try:
---> 56                     convertedVal = _c.convertData(val, goalType)
     57                 except TypeError: # as e: # catching exception as sth is only

3 frames
TypeError: Cannot convert data from type REAL (<class 'float'>) to type INTEGER

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/essentia/standard.py in configure(self, **kwargs)
     58                                           #available as from python 2.6
     59                     raise TypeError('Error cannot convert parameter %s to %s'\
---> 60                                     %(str(_c.determineEdt(val)),str(goalType))) #\''+name+'\' parameter: '+str(e))
     61 
     62                 kwargs[name] = convertedVal

TypeError: Error cannot convert parameter REAL to INTEGER

Here is the respective code exerpt :

filepath = datasetPath+'violin/violin0.wav'

frameSize = 1024
hopSize = 512
mel_order = 15
lpc_order = 15

# Instantiating each class
spectrum = ess.Spectrum(size = frameSize)
print('Check1')
mfcc = ess.MFCC(numberCoefficients=15, inputSize=frameSize/2 + 1)
print('Check2')
lpc = ess.LPC(order = lpc_order, type='warped')
print('Check3')
window = ess.Windowing(type = 'hann')
print('Check4')

loader = ess.MonoLoader(filename=filepath)
print('Check5')
audio = loader()

print('Check6')

(fs, audio) = read(filepath)
audio = ess.array(audio)
print('Check7')

mfccs = []
wlpcs = []

for frame in FrameGenerator(audio, frameSize=frameSize, hopSize=hopSize, startFromZero=True):
  mX = spectrum(window(frame))
  mfcc_bands, mfcc_coeffs = mfcc(mX)  
  mfccs.append(mfcc_coeffs)
  wlpc = lpc(frame)[0]
  #the first LPC coefficient is always 1
  wlpcs.append(wlpc[1:])

mfccs = np.array(mfcc)
wlpcs = np.array(wlpcs)

features = np.zeros([lpc_order+mel_order])
features[:lpc_order] = normalize_features(np.median(wlpcs,axis = 0))
features[lpc_order:] = normalize_features(np.median(mfccs, axis = 0))

Only the first debug printing statement (Check1) is shown in the output, which is why I am assuming that the error is in MFCC.

dbogdanov commented 3 years ago

You should match the parameter types explicitly. In this case, the integer value should be given instead of float.