def getCepsMatrixFromWavFile(filename): ''' funkcja wyznacza z odczytanego pliku wav (ze sciezki filename) wspolczynniki MFCC a potem je zwraca ''' Fs = 44100.0; # sampling rate t,y = PlotModule.readWav(filename, Fs) ########## ceps_matrix = getCepsMatrixFromData(t,y) return ceps_matrix
for i in range(giter): ''''' if i < giter/4: wr = W(map, QModel, 0.9, 1, 1, 0, True) if i >= giter/4 and i <= giter * 3 / 4: wr = W(map, QModel, 0.4, 1, 1, 0, True) if i > giter * 3 / 4: ''' wr = W(map, QModel, 0.1, 1, 1, True) iter = wr.play() plot_epoh.append(iter) if i % 100 == 99: print(i, iter) #print( i * 0.8/(giter+1)) #mapgen.generateMap(map, 0.3 + i * 0.6/(giter+1)) randomnum = (random.random() - 0.5) * 0.5 #randomnum = 0 mapgen.generateMap(map, 0.7 + randomnum) for i in QModel.state: print(i, QModel.state[i]) plotBuilder = PlotModule.plotBilder() plotBuilder.buildPlot(plot_epoh) FileWR.FileWR.writeQ(QModel, 'Qmodel.txt') animation = plot_animation.moveAnimation() #mapgen.generateMap(map, 0.85) wr = W(map, QModel, 0, 1, 11) anim = wr.play(True) animation.animate(map, anim, 'randMap')
# cooef = [1]*numCoefficients len(signal) # Small data filt = lazy_lpc.lpc.kautocor(signal, 2) filt # The analysis filter cooef = filt.numerator # List of coefficients filt.error # Prediction error (squared!) return cooef if __name__ == '__main__': i = 0 filename = "learn_set//wlacz//" + str(i + 1) + ".wav" sampleRate, signal = PlotModule.readWav(filename, Fs) rate = 22050 s, Hz = sHz(rate) size = 512 table = signal #sin_table.harmonize({1: 1, 2: 5, 3: 3, 4: 2, 6: 9, 8: 1}).normalize() data = table(str2freq("Bb3") * Hz).take(size) filt = lpc(signal, order=14) # Analysis filter gain = 1e-2 # Gain just for alignment with DFT # Plots the synthesis filter # - If blk is given, plots the block DFT together with the filter # - If rate is given, shows the frequency range in Hz (gain / filt).plot(blk=data, rate=rate, samples=1024, unwrap=False) pylab.show()
vect_of_mccf[0] = 0 return vect_of_mccf if __name__ == '__main__': # ++++++++++++++++++++++++++++++++++++++++++++ for i in range(11): print("please speak a word into the microphone") filename = "learn_set//wlacz//"+str(i+1)+".wav" # RecordModule.record_to_file(filename) # print("done - result written to ", filename) # filename = 'learn_set//wlacz//3.wav' # ++++++++++++++++++++++++++++++++++++++++++++ t, extract = PlotModule.readWav(filename, FS) extract = RecordModule.preemp(extract) fr, wordspower, wordszeros, wordsdetect, ITL ,ITU, word_fr, word_y = RecordModule.detectSingleWord(t,extract) ceps, mspec, spec = mfcc(word_y) show_MFCC_spectrum(ceps) # show_MFCC(ceps) vect_of_mccf = np.zeros(len(ceps.T)) for i in range(len(ceps.T)): vect_of_mccf[i] = max(ceps.T[i]) # sum(data.T[i]) #
# Compute the spectrum magnitude spec = np.abs(fft(framed, nfft, axis=-1)) # Filter the spectrum through the triangle filterbank mspec = np.log10(np.dot(spec, fbank.T)) # Use the DCT to 'compress' the coefficients (spectrum -> cepstrum domain) ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:, :nceps] return ceps, mspec, spec def preemp(input, p): """Pre-emphasis filter.""" return lfilter([1., -p], 1, input) if __name__ == '__main__': for i in range(10): filename = "learn_set//wlacz//"+str(i+1)+".wav" RATE = 44100.0 t,y = PlotModule.readWav(filename, RATE) ceps, mspec, spec = mfcc(y) print(ceps.shape) vect_of_mccf = np.zeros(len(ceps.T)) for i in range(len(ceps.T)): vect_of_mccf[i] = RecordModule.arithmeticMean(ceps.T[i]) # sum(data.T[i]) # pylab.title("ceps : ") pylab.plot(range(len(vect_of_mccf)), vect_of_mccf, 'g') pylab.show()
filt = lazy_lpc.lpc.kautocor(signal, 2) filt # The analysis filter cooef = filt.numerator # List of coefficients filt.error # Prediction error (squared!) return cooef if __name__ == '__main__': i = 0 filename = "learn_set//wlacz//"+str(i+1)+".wav" sampleRate, signal = PlotModule.readWav(filename, Fs) rate = 22050 s, Hz = sHz(rate) size = 512 table = signal #sin_table.harmonize({1: 1, 2: 5, 3: 3, 4: 2, 6: 9, 8: 1}).normalize() data = table(str2freq("Bb3") * Hz).take(size) filt = lpc(signal, order=14) # Analysis filter gain = 1e-2 # Gain just for alignment with DFT # Plots the synthesis filter # - If blk is given, plots the block DFT together with the filter # - If rate is given, shows the frequency range in Hz (gain / filt).plot(blk=data, rate=rate, samples=1024, unwrap=False) pylab.show()
mspec = np.log10(np.dot(spec, fbank.T)) # Use the DCT to 'compress' the coefficients (spectrum -> cepstrum domain) ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:, :nceps] return ceps, mspec, spec def preemp(input, p): """Pre-emphasis filter.""" return lfilter([1., -p], 1, input) if __name__ == '__main__': for i in range(10): filename = "learn_set//wlacz//" + str(i + 1) + ".wav" RATE = 44100.0 t, y = PlotModule.readWav(filename, RATE) ceps, mspec, spec = mfcc(y) print(ceps.shape) vect_of_mccf = np.zeros(len(ceps.T)) for i in range(len(ceps.T)): vect_of_mccf[i] = RecordModule.arithmeticMean( ceps.T[i]) # sum(data.T[i]) # pylab.title("ceps : ") pylab.plot(range(len(vect_of_mccf)), vect_of_mccf, 'g') pylab.show()