Skip to content

Commit 9fcdb1f

Browse files
committed
improved 1to1 authentification
1 parent ccbacf3 commit 9fcdb1f

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed
-632 Bytes
Binary file not shown.

app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ def authentificate():
263263
model_file.write(gmm_model)
264264
#gmm = request.files['voiceModel']
265265
#gmm.save("./temp/models/"+username+".gmm")
266-
identity,score = reconize_with_model(os.path.join(app.config['UPLOAD_FOLDER'], filen),"./temp/models/",username)
266+
the_model_path = "temp/models/"+ username + ".gmm"
267+
identity,score = reconize_with_model(os.path.join(app.config['UPLOAD_FOLDER'], filen),"./temp/models/"+ username + ".gmm",username)
267268
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
268269
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filen))
269270
os.remove("./temp/models/" + username + '.gmm')

auth.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

recognize_voice.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,44 +137,48 @@ def reconize_with_model(filename,model,username):
137137
#modelpath = "./temp/models/"
138138

139139

140-
gmm_files = [os.path.join(modelpath,fname) for fname in
141-
os.listdir(modelpath) if fname.endswith('.gmm')]
140+
#gmm_files = [os.path.join(modelpath,fname) for fname in
141+
#os.listdir(modelpath) if fname.endswith('.gmm')]
142142

143-
models = [pickle.load(open(fname,'rb')) for fname in gmm_files]
143+
models = pickle.load(open(modelpath,'rb'))
144144

145-
speakers = [fname.split("/")[-1].split(".gmm")[0] for fname
146-
in gmm_files]
145+
#speakers = [fname.split("/")[-1].split(".gmm")[0] for fname
146+
#in gmm_files]
147147

148-
if len(models) == 0:
149-
print("No Users in the Database!")
150-
return
148+
#if len(models) == 0:
149+
#print("No Users in the Database!")
150+
#return
151151

152152
#read test file
153153
sr,audio = read(FILENAME)
154154

155155
# extract mfcc features
156156
vector = extract_features(audio,sr)
157-
log_likelihood = np.zeros(len(models))
157+
log_likelihood = 0
158158

159159
#checking with each model one by one
160160
#scorer = 0
161-
for i in range(len(models)):
162-
gmm = models[i]
163-
scores = np.array(gmm.score(vector))
164-
log_likelihood[i] = scores.sum()
165-
if speakers[i] == username:
166-
scorer = log_likelihood[i]
167-
print("\n\n\n")
168-
print(speakers[i])
169-
print(log_likelihood[i])
170-
171-
pred = np.argmax(log_likelihood)
172-
identity = speakers[pred]
173-
maximum = max(log_likelihood)
174-
minimum = min(log_likelihood)
175-
176-
score = (2*(scorer - minimum)/(maximum - minimum)) - 1
161+
#for i in range(len(models)):
162+
gmm = models
163+
scores = np.array(gmm.score(vector))
164+
log_likelihood = scores.sum()/len(scores)
165+
#if speakers[i] == username:
166+
#scorer = log_likelihood[i]
167+
print("\n\n\n")
168+
#print(speakers[i])
169+
print(log_likelihood)
170+
171+
#pred = np.argmax(log_likelihood)
172+
if log_likelihood > -4:
173+
identity = username
174+
else :
175+
identity = "Unknown"
176+
maximum = 0
177+
minimum = -30
178+
179+
score = (2*(log_likelihood - minimum)/(maximum - minimum)) - 1
177180
#score = int(score)
181+
#score = log_likelihood
178182

179183

180184
# if voice not recognized than terminate the process

temp/models/unknown.gmm

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)