@@ -82,18 +82,36 @@ def enroll():
82
82
record1 = recording ['record1' ]
83
83
record2 = recording ['record2' ]
84
84
record3 = recording ['record3' ]
85
- recording1 = base64 .b64decode (record1 )
86
- recording2 = base64 .b64decode (record2 )
87
- recording3 = base64 .b64decode (record3 )
88
- #print(recording2)
89
- filename2 = "recording1.wav"
90
- with open (os .path .join (app .config ['UPLOAD_FOLDER' ],filename2 ), 'wb' ) as recording_file :
91
- recording_file .write (recording1 )
92
-
93
- gmm ,gmm_model_path = add_user (username ,os .path .join (app .config ['UPLOAD_FOLDER' ], filename2 ))
85
+ base_records = []
86
+ base_records .append (base64 .b64decode (record1 ))
87
+ base_records .append (base64 .b64decode (record2 ))
88
+ base_records .append (base64 .b64decode (record3 ))
89
+
90
+ recordings = []
91
+ filename0 = "recording0.wav"
92
+ filename1 = "recording1.wav"
93
+ for recording1 in base_records :
94
+ with open (os .path .join (app .config ['UPLOAD_FOLDER' ],filename1 ), 'wb' ) as recording_file :
95
+ recording_file .write (recording1 )
96
+ w = wave .open (os .path .join (app .config ['UPLOAD_FOLDER' ],filename1 ), 'rb' )
97
+ recordings .append ( [w .getparams (), w .readframes (w .getnframes ())] )
98
+ w .close ()
99
+ os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filename1 ))
100
+
101
+
102
+
103
+ outputFile = wave .open (os .path .join (app .config ['UPLOAD_FOLDER' ], filename0 ), 'wb' )
104
+ outputFile .setparams (recordings [0 ][0 ])
105
+ outputFile .writeframes (recordings [0 ][1 ])
106
+ outputFile .writeframes (recordings [1 ][1 ])
107
+ outputFile .writeframes (recordings [2 ][1 ])
108
+ outputFile .close ()
109
+
110
+
111
+ gmm ,gmm_model_path = add_user (username ,os .path .join (app .config ['UPLOAD_FOLDER' ], filename0 ))
94
112
os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ))
95
- #send_file(gmm_model_path, attachment_filename= 'ma.gmm' )
96
- #model = json.loads(open(gmm_model_path,'rb'))
113
+ os . remove ( os . path . join ( app . config [ 'UPLOAD_FOLDER' ], filename0 ) )
114
+
97
115
if gmm_model_path == '' :
98
116
output ['trained' ] = "failed"
99
117
output ['EnrollStatus' ] = "REJECTED"
@@ -205,6 +223,19 @@ def authentificate():
205
223
206
224
filename = secure_filename (audio_file .filename )
207
225
audio_file .save (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ))
226
+ recording = json .load (open (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ),'rb' ))
227
+ auth_record = base64 .b64decode (recording ['record' ])
228
+ filen = "auth.wav"
229
+ with open (os .path .join (app .config ['UPLOAD_FOLDER' ],filen ), 'wb' ) as recording_file :
230
+ recording_file .write (auth_record )
231
+
232
+ try :
233
+ model = recording ['voiceModel' ]
234
+ except :
235
+ model = None
236
+
237
+
238
+
208
239
username = request .args .get ('username' )
209
240
record = users .find_one ({'username' :username })
210
241
if record == None :
@@ -215,14 +246,19 @@ def authentificate():
215
246
216
247
217
248
218
- if 'voiceModel' in request . files :
249
+ if model is not None :
219
250
220
251
unknown_path = 'gmm_models/unknown.gmm'
221
252
copyfile (unknown_path , 'temp/models/unknown.gmm' )
222
- gmm = request .files ['voiceModel' ]
223
- gmm .save ("./temp/models/" + username + ".gmm" )
224
- identity ,score = reconize_with_model (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ),"./temp/models/" ,username )
253
+ gmm_model = base64 .b64decode (model )
254
+ with open ("./temp/models/" + username + '.gmm' , 'wb' ) as model_file :
255
+ model_file .write (gmm_model )
256
+ #gmm = request.files['voiceModel']
257
+ #gmm.save("./temp/models/"+username+".gmm")
258
+ identity ,score = reconize_with_model (os .path .join (app .config ['UPLOAD_FOLDER' ], filen ),"./temp/models/" ,username )
225
259
os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ))
260
+ os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filen ))
261
+ os .remove ("./temp/models/" + username + '.gmm' )
226
262
if identity == username :
227
263
output ['score' ] = round (score * 100 ,2 )
228
264
output ['Decision' ] = "MATCH"
@@ -233,8 +269,9 @@ def authentificate():
233
269
output ['DecisionReason' ]= "BIOMETRIC_MISMATCH"
234
270
return output
235
271
else :
236
- identity ,score = recognize (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ),username )
272
+ identity ,score = recognize (os .path .join (app .config ['UPLOAD_FOLDER' ], filen ),username )
237
273
os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filename ))
274
+ os .remove (os .path .join (app .config ['UPLOAD_FOLDER' ], filen ))
238
275
if identity == username :
239
276
output ['score' ] = round (score * 100 ,2 )
240
277
output ['Decision' ] = "MATCH"
0 commit comments