def gen(fname): print(fname) samples, samplingrate = loadAudio(fname) lmfcc, mspec = mfcc(samples, liftering=False) wordTrans = list(path2info(fname)[2]) phoneTrans = words2phones(wordTrans, prondict, addShortPause=True) hmms = concatHMMs(phoneHMMs, phoneTrans) stateTrans = [ phone + '_' + str(stateid) for phone in phoneTrans for stateid in range(nstates[phone]) ] stateTrans_idx = list(map(stateList.index, stateTrans)) aligned = forcedAlignment(lmfcc, hmms, stateTrans_idx) return aligned, lmfcc, mspec
import numpy as np from lab1 import proto import matplotlib.pyplot as plt from lab1.tools import * from scipy.cluster.hierarchy import linkage, dendrogram import scipy data = np.load('lab1_data.npz')['data'] example_data = np.load('lab1_example.npz')['example'].item() target = 'lmfcc' plt.figure(figsize=(10, 20)) ax = plt.subplot(8, 1, 1) ax.set_title('Samples') ax.set_yticklabels([]) ax.set_xticklabels([]) plt.plot(example_data['samples'], linewidth=0.5) output = proto.mfcc(example_data['samples']) plt.savefig('Results/part4.png', bbox_inches='tight') plt.show()
import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture from lab1 import proto loaded = np.load('lab1_data.npz') data = loaded['data'] size = 12 target = 'lmfcc' giant_mfcc = [] seven = [] unrelated = [] i = 0 for d in data: out = proto.mfcc(d['samples']) giant_mfcc.append(out) #voice seven if i in [16, 17, 38, 39]: seven.append(out) if i in [5,35, 20]: unrelated.append(out) i += 1 giant_mfcc = np.vstack(giant_mfcc) est = GaussianMixture(size) est.fit(giant_mfcc)
import numpy as np from lab1 import proto import matplotlib.pyplot as plt loaded = np.load('lab1_data.npz') data = loaded['data'] target = 'lmfcc' giant_mfcc = [] giant_mspec = [] for d in data: out, mspec = proto.mfcc(d['samples'], liftering=False) giant_mfcc.append(out) giant_mspec.append(mspec) giant_mfcc = np.vstack(giant_mfcc) giant_mspec = np.vstack(giant_mspec) # Answer for part 5 correlation_mfcc = np.corrcoef(giant_mfcc) correlation_mspec = np.corrcoef(giant_mspec) plt.figure(figsize=(20, 10)) ax = plt.subplot(1, 2, 1) ax.set_title('MFCC') ax.set_yticklabels([]) ax.set_xticklabels([]) plt.pcolormesh(correlation_mfcc) ax = plt.subplot(1, 2, 2) ax.set_title('MSPEC') ax.set_yticklabels([])
#Get stateList ''' #with open('stateList.pkl', 'wb') as f: # pickle.dump(stateList, f) ''' phoneHMMs = np.load('lab3/lab2_models.npz')['phoneHMMs'].item() phones = sorted(phoneHMMs.keys()) nstates = {phone: phoneHMMs[phone]['means'].shape[0] for phone in phones} stateList = [ph + '_' + str(id) for ph in phones for id in range(nstates[ph])] # with open('lab3/stateList.pkl', 'rb') as f: # stateList = pickle.load(f) fname = 'lab3/asset/tidigits/disc_4.1.1/tidigits/train/man/nw/z43a.wav' samples, samplingrate = loadAudio(fname) lmfcc = mfcc(samples) wordTrans = list(path2info(fname)[2]) phoneTrans = words2phones(wordTrans, prondict, addShortPause=True) hmms = concatHMMs(phoneHMMs, phoneTrans) stateTrans = [ phone + '_' + str(stateid) for phone in phoneTrans for stateid in range(nstates[phone]) ] stateTrans_idx = list(map(stateList.index, stateTrans)) aligned = forcedAlignment(lmfcc, hmms, stateTrans) frames2trans(aligned, outfilename='z43a.lab') print("Done")