Skip to content

Instantly share code, notes, and snippets.

@BonfaceKilz
Last active July 22, 2018 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BonfaceKilz/1703aa61c36c4268f79ca2a8c84018fc to your computer and use it in GitHub Desktop.
Save BonfaceKilz/1703aa61c36c4268f79ca2a8c84018fc to your computer and use it in GitHub Desktop.
A fix for some(his) code my friend shared with me
import sys
import librosa
from numpy.linalg import norm
import librosa
from numpy.linalg import norm
from dtw import dtw
from random import shuffle
words = ['open','close']
chosen_word = words[:]
shuffle (chosen_word)
print(chosen_word[0])
if chosen_word[0] == 'open':
prompt = 'tevo/tevinOpen.wav'
else :
prompt = 'tevo/tevinClose.wav'
print(prompt)
y1, sr1 = librosa.load(prompt)
y2, sr2 = librosa.load('tevo/berylOpen.wav')
#Loading audio files
mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC value
mfcc2 = librosa.feature.mfcc(y2, sr2) #Computing MFCC value
dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))
print('Normalized distance between the two sounds:', dist)
print(dist)
if dist <= 120.000000000:
words = ['open','close']
chosen_word = words[:]
shuffle (chosen_word)
print(chosen_word[0])
else:
print(dist <= 120)
sys.exit("ACCESS DENIED")
if (chosen_word[0]) == open :
prompt = 'tevo/tevinOpen.wav'
else :
prompt = 'tevo/tevinClose.wav'
y1, sr1 = librosa.load(prompt)
y2, sr2 = librosa.load('tevo/berylOpen.wav')
mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC value
mfcc2 = librosa.feature.mfcc(y2, sr2) #Computing MFCC value
dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))
print('Normalized distance between the two sounds:', dist)
if dist <=120.000000000:
print('ACCESS GRANTED')
else :
print('ACCESS DENIED')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment