Created
May 2, 2016 00:46
-
-
Save adhithyan15/99820091e78fa28761293e419cb73075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scikits.audiolab import wavread | |
from scikits.talkbox.features import mfcc | |
from scikits.talkbox.linpred.levinson_lpc import lpc | |
import os | |
import numpy as np | |
from test.LPC import LPCExtractor | |
from test.MFCC import get_mfcc_extractor | |
from collections import defaultdict | |
from sklearn.mixture import GMM | |
from collections import Counter | |
import pickle | |
import operator | |
import random | |
from random import randint | |
gmm_labels = [] | |
gmm_instances = [] | |
gmm_tables = {} | |
random_str = str(1290152) | |
f = open("pickle_dump/"+ random_str + "/ubm-pickle.txt","r") | |
ubm_model = pickle.load(f) | |
f.close() | |
base_dir = "/Users/adhithyar/Desktop/ece6255/" | |
l = LPCExtractor(16000) | |
mfcc_extractor = get_mfcc_extractor() | |
counter = 0 | |
for file_name in os.listdir(base_dir + "pickle_dump/" + random_str + "/"): | |
print file_name | |
if file_name != random_str: | |
counter = counter + 1 | |
f = open("pickle_dump/" + random_str + "/" + file_name) | |
gmm_instance = pickle.load(f) | |
f.close() | |
k = file_name.split("-")[0] | |
gmm_labels.append(k) | |
gmm_tables[k] = gmm_instance | |
gmm_instances.append(gmm_instance) | |
results = {} | |
correct_scores = {} | |
print gmm_labels | |
f = open("testing_list"+random_str+".txt","r") | |
testing_set_filenames = pickle.load(f) | |
f.close() | |
base_dir = "/Users/adhithyar/Desktop/ece6255/converted_data/" | |
audio_files = os.listdir(base_dir) | |
counter = 0 | |
for file_name in audio_files: | |
print counter + 1 | |
if file_name not in testing_set_filenames: | |
counter = counter + 1 | |
flits = file_name.split("-") | |
if flits[0] not in correct_scores: | |
correct_scores[flits[0]] = [] | |
data, fs = wavread(base_dir + file_name)[:2] | |
ceps = mfcc_extractor.extract(data) | |
lpcs = l.extract(data) | |
b = np.concatenate((ceps, lpcs), axis=1) | |
corresponding_gmm_instance = gmm_tables[flits[0]] | |
correct_scores[flits[0]].append(np.sum(corresponding_gmm_instance.score(b))) | |
f = open("pickle_dump/" + random_str + "/correct_scores.txt", 'w') | |
pickle.dump(correct_scores, f) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment