def compare(control_path, exp_path): """ Compares two wav files and returns a score. Uses mel frequency ceptrum coefficients as well as dynamic time warping. :param control_path: the 'correct' wav - what you are comparing to :param exp_path: the unknown wav """ (rate,sig) = wavread(control_path) (rate2,sig2) = wavread(exp_path) x = mfcc(sig,rate) y = mfcc(sig2,rate2) dist, cost, acc = dtw.dtw(x, y, dist=lambda x, y: dtw.norm(x - y, ord=1))\ return dist
def compare(control_path, exp_path): """ Compares two wav files and returns a score. Uses mel frequency ceptrum coefficients as well as dynamic time warping. :param control_path: the 'correct' wav - what you are comparing to :param exp_path: the unknown wav """ (rate, sig) = wavread(control_path) (rate2, sig2) = wavread(exp_path) x = mfcc(sig, rate) y = mfcc(sig2, rate2) dist, cost, acc = dtw.dtw(x, y, dist=lambda x, y: dtw.norm(x - y, ord=1))\ return dist
def compare_mfcc(*args): if len(args) < 2: print 'Invalid number of arguments' return -1 input_paths = args[1:] processed_wav_data = [] if check_file_paths(input_paths) == -1: return -1 mfcc_data = [] for path in input_paths: (rate, sig) = wavread(path) mfcc_data.append(mfcc(sig, rate)) zipped_data = zip(*mfcc_data) mean_data = map(np.mean, zipped_data) user_path = args[0] (rate, sig) = wavread(user_path) user_data = mfcc(sig, rate) dist, cost, acc = dtw.dtw(mean_data, user_data, dist=lambda x, y: dtw.norm(x - y, ord=1)) return dist
# # Images for debugging purposes # cv2.imwrite('nativethresh.png', native_thresh) # cv2.imwrite('userthresh.png', user_thresh) # # cv2.imwrite('diffthresh.png', diff_thresh) # non_zeros = np.count_nonzero(diff_thresh.flatten(0)) # print non_zeros/len(diff_thresh.flatten(0)) # # CLEANUP # try: # # os.remove('native.png') # # os.remove('user.png') # os.remove('difference.png') # except OSError: # pass (rate, sig) = wav.read(native_wav_path) mfcc_feat = mfcc(sig, rate) fbank_feat = logfbank(sig, rate) (rate2, sig2) = wav.read(user_wav_path) mfcc_feat2 = mfcc(sig2, rate2) fbank_feat2 = logfbank(sig2, rate2) x = mfcc(sig, rate) y = mfcc(sig2, rate2) dist, cost, acc = dtw.dtw(x, y, dist=lambda x, y: dtw.norm(x - y, ord=1)) print dist