Python Forum
[Python][Scipy]Help with Sound Recognition Testing Protocol
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python][Scipy]Help with Sound Recognition Testing Protocol
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Solve a system of non-linear equations in Python (scipy.optimize.fsolve) drudox 7 22,633 Aug-18-2018, 02:27 AM
Last Post: scidam
  How to use/install different versions of Python packages (Scipy) on the same system? gzb001 3 6,037 Nov-07-2016, 12:56 AM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020