[Python][Scipy]Help with Sound Recognition Testing Protocol - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: [Python][Scipy]Help with Sound Recognition Testing Protocol (/thread-6242.html) |
[Python][Scipy]Help with Sound Recognition Testing Protocol - WebsterAugust - Nov-12-2017 Hey guys! I’m working on a small project using some open source sound recognition code (referenced below w/ op) and I was wondering how I would test against an entire “database”/folder of files vs just the one. Code posted below with code in question highlighted: #meaty from scipy.io.wavfile import read def calc_distances(sound_file): #The minimun value for the sound to be recognized as a knock min_val = 5000 fs, data = read(sound_file) data_size = len(data) #The number of indexes on 0.15 seconds focus_size = int(0.15 * fs) focuses = distances = idx = 0 while idx < len(data): if data[idx] > min_val: mean_idx = idx + focus_size // 2 focuses.append(float(mean_idx) / data_size) if len(focuses) > 1: last_focus = focuses[-2] actual_focus = focuses[-1] distances.append(actual_focus - last_focus) idx += focus_size else: idx += 1 return distances print calc_distances('knock.wav') #bindtobuttoncode def accept_test(pattern, test, min_error): if len(pattern) > len(test): return False for i, dt in enumerate(pattern): if not dt - test < min_error: return False return True pattern = calc_distances('knock.wav') test = calc_distances('knock2.wav') # the minimum difference between the patterns in seconds min_error = 0.1 print accept_test(pattern, test, min_error) #Outputs True |