from scipy.io import wavfile from scipy.interpolate import interp1d import damage, recognize, utils, evaluate import numpy as np sample_rate, samples = wavfile.read('songs/hakuna_matata.wav') samples = samples[1000000:2000000] fp = [0, 0.05, 0.1, 0.2, 0.3] fn = [0, 0.05, 0.1, 0.2, 0.3] print('zerofill') for p in fp: for n in fn: newsamples = samples.copy() damage.zerofill(newsamples, 0.4) matches = recognize.cheat(samples, newsamples, false_positives=p, false_negatives=n) validx, validy = utils.tovalidxy(newsamples, matches) f = interp1d(validx, validy, kind='cubic', fill_value='extrapolate') invalidx = utils.invalidx(matches) fixedy = f(invalidx) utils.replace(newsamples, invalidx, fixedy) print('fp:', p, 'fn:', n, 'mean:', np.mean(evaluate.abserrors(samples, newsamples))) print('noiseadd') for p in fp: for n in fn:
#! /usr/bin/env python from scipy.io import wavfile from scipy.interpolate import interp1d import damage, recognize, utils sample_rate, samples = wavfile.read('songs/hakuna_matata.wav') samples = samples[5000000:5000100] newsamples = samples.copy() damage.zerofill(newsamples, 0.5, blocksize=2) matches = recognize.cheat(samples, newsamples) x, y = utils.tovalidxy(newsamples, matches) f = interp1d(x, y, kind='cubic', fill_value='extrapolate') utils.repair(newsamples, matches, f) import matplotlib.pyplot as plt plt.title('Cubic interpolation') plt.xlabel('Frame') plt.ylabel('Amplitude') plt.plot(samples, label='real') plt.plot(newsamples, label='interpolated') plt.legend(loc='best') plt.show()