Search code examples
machine-learningdtw

Getting the error "dtw() got an unexpected keyword argument 'dist'" while calculating dtw of 2 voice samples


I am getting the error "dtw() got an unexpected keyword argument 'dist'" while I'm trying to calculate the dtw of 2 wav files. I can't figure out why or what to do to fix it. I am attaching the code below.

import librosa

import librosa.display

y1, sr1 = librosa.load('sample_data/Abir_Arshad_22.wav')

y2, sr2 = librosa.load('sample_data/Abir_Arshad_22.wav')

%pylab inline

subplot(1, 2, 1)

mfcc1 = librosa.feature.mfcc(y1, sr1)

librosa.display.specshow(mfcc1)

subplot(1, 2, 2)

mfcc2 = librosa.feature.mfcc(y2, sr2)

librosa.display.specshow(mfcc2)

from dtw import dtw

from numpy.linalg import norm

dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))

print ('Normalized distance between the two sounds:', dist)

the error is occurring in the 2nd last line.


Solution

  • The error message is straight forward. Lets read the docs of the method you are calling:

    https://dynamictimewarping.github.io/py-api/html/api/dtw.dtw.html#dtw.dtw

    The dtw function has the following parameters:

    Parameters x – query vector or local cost matrix

    y – reference vector, unused if x given as cost matrix

    dist_method – pointwise (local) distance function to use.

    step_pattern – a stepPattern object describing the local warping steps allowed with their cost (see [stepPattern()])

    window_type – windowing function. Character: “none”, “itakura”, “sakoechiba”, “slantedband”, or a function (see details).

    open_begin,open_end – perform open-ended alignments

    keep_internals – preserve the cumulative cost matrix, inputs, and other internal structures

    distance_only – only compute distance (no backtrack, faster)

    You try to pass an argument named dist and that argument simply is not known.

    Instead, removing that argument would solve the issue, such as

    dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T)