Skip to content

Commit 84951fb

Browse files
committed
binary authentification
1 parent b801c51 commit 84951fb

File tree

6 files changed

+61
-19
lines changed

6 files changed

+61
-19
lines changed

Readme.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can launch the server on the terminal with :
1515
All API responses are the same as specified in the specifications
1616

1717
- For the main enrollment, this is an example of the curl request to send :
18-
`curl -X POST -F audio_file=@voice_database/ihab/recording.wav 'http://127.0.0.1:5000/api/voiceident/enrollments?username=ihab'
18+
`curl -X POST -F audio_file=@enrollement.json 'http://127.0.0.1:5000/api/voiceident/enrollments?username=ihab'
1919
`
2020

2121
You can specify the username you desire, as well as the path for the audio file you would like to use.
@@ -43,3 +43,9 @@ The voiceprintid is returned in the first API calls
4343

4444

4545
python3 create_enrollement_input.py -a voice_database/ihab/recording.wav -b voice_database/unknown/flute.wav -c voice_database/ihab/recording.wav
46+
47+
curl -X POST -F audio_file=@enrollement.json 'http://127.0.0.1:5000/api/voiceident/enrollments?username=ihab'
48+
49+
python3 create_auth_input.py -a voice_database/unknown/flute.wav -b gmm_models/ihab.gmm
50+
51+
curl -X POST -F audio_file=@auth.json 'http://127.0.0.1:5000/api/voiceident/authentication?username=ihab&voiceprintId=5df8cb542e276886223cbe36'

app.py

+53-16
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,36 @@ def enroll():
8282
record1 = recording['record1']
8383
record2 = recording['record2']
8484
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))
94112
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+
97115
if gmm_model_path == '':
98116
output['trained'] = "failed"
99117
output['EnrollStatus'] = "REJECTED"
@@ -205,6 +223,19 @@ def authentificate():
205223

206224
filename = secure_filename(audio_file.filename)
207225
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+
208239
username = request.args.get('username')
209240
record = users.find_one({'username':username})
210241
if record == None:
@@ -215,14 +246,19 @@ def authentificate():
215246

216247

217248

218-
if 'voiceModel' in request.files:
249+
if model is not None:
219250

220251
unknown_path = 'gmm_models/unknown.gmm'
221252
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)
225259
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')
226262
if identity == username:
227263
output['score'] = round(score*100,2)
228264
output['Decision'] = "MATCH"
@@ -233,8 +269,9 @@ def authentificate():
233269
output['DecisionReason']="BIOMETRIC_MISMATCH"
234270
return output
235271
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)
237273
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
274+
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filen))
238275
if identity == username:
239276
output['score'] = round(score*100,2)
240277
output['Decision'] = "MATCH"

auth.json

+1-1
Large diffs are not rendered by default.

gmm_models/ihab.gmm

0 Bytes
Binary file not shown.

temp/enrollement.json

-1
This file was deleted.

temp/models/ihab.gmm

-10.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)