def get_label_data(label): files = os.listdir(label) test_mfcc = [ MFCC.get_mfcc(os.path.join(label, f)) for f in files if f.endswith("wav") ] return test_mfcc
def get_label_data(directory): files = os.listdir(directory) # Randomized Test and Train set test_files = rand.sample(files, TEST_SIZE) train_mfcc = [] test_mfcc = [] for f in test_files: if f.endswith("wav"): test_mfcc.append(MFCC.get_mfcc(os.path.join(directory, f))) files.pop(files.index(f)) train_mfcc = [MFCC.get_mfcc(os.path.join(directory, f)) for f in files if f.endswith("wav")] return train_mfcc, test_mfcc
def runHMM(file_path): models = {} for label in CLASS_LABELS: with open(os.path.join("Models", label + ".pkl"), "rb") as file: models[label] = pk.load(file) with open("Models/kmeans.pkl", "rb") as file: kmeans = pk.load(file) sound_mfcc = MFCC.get_mfcc(file_path) sound_mfcc = kmeans.predict(sound_mfcc).reshape(-1, 1) evals = { cname: model.score(sound_mfcc, [len(sound_mfcc)]) for cname, model in models.items() } conclusion = max(evals.keys(), key=(lambda k: evals[k])) return evals, conclusion