Skip to content

Commit 90d1edb

Browse files
committed
add status
1 parent 84951fb commit 90d1edb

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

Readme.md

+15-21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ You can launch the server on the terminal with :
1212

1313
### API calls :
1414

15+
16+
- To create the enrollement input file `enrollement.json`:
17+
`python3 create_enrollement_input.py -a voice_database/ihab/recording.wav -b voice_database/unknown/flute.wav -c voice_database/ihab/recording.wav
18+
`
19+
20+
- To create the 1-to-1 authentification input file `auth.json`:
21+
`python3 create_auth_input.py -a voice_database/unknown/flute.wav -b gmm_models/ihab.gmm
22+
`
23+
24+
- To create the 1-to-N authentification input file `auth.json`:
25+
`python3 create_auth_input.py -a voice_database/unknown/flute.wav
26+
`
27+
1528
All API responses are the same as specified in the specifications
1629

1730
- For the main enrollment, this is an example of the curl request to send :
@@ -27,25 +40,6 @@ You can specify the username you desire, as well as the path for the audio file
2740
The voiceprintid is returned in the first API calls
2841

2942

30-
- For authentification, the 1-to-N curl request is :
31-
`curl -X POST -F audio_file=@voice_database/ihab/recording.wav 'http://127.0.0.1:5000/api/voiceident/authentication?username=ihab&voiceprintId=5df8cb542e276886223cbe36'
43+
- For authentification, the curl request is :
44+
`curl -X POST -F audio_file=@auth.json 'http://127.0.0.1:5000/api/voiceident/authentication?username=ihab&voiceprintId=5df8cb542e276886223cbe36'
3245
`
33-
34-
- For the 1-to-1 authentification, the curl request is :
35-
`curl -X POST -F audio_file=@voice_database/unknown/flute.wav -F voiceModel=@gmm_models/ihab.gmm 'http://127.0.0.1:5000/api/voiceident/authentication?username=ihab&voiceprintId=5df8cb542e276886223cbe36'
36-
`
37-
38-
39-
40-
41-
42-
43-
44-
45-
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

+25-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
@app.route('/api/voiceident/enrollments', methods=['POST'])
4040
def enroll():
41+
status = 200
4142
output = {}
4243
record = {}
4344
if 'audio_file' not in request.files:
@@ -46,7 +47,7 @@ def enroll():
4647
output['DecisionReason']="AUDIO_FILE_NOT_SENT"
4748
output['voiceprintId'] = ""
4849
output['voiceModel'] = ""
49-
return output
50+
return output,status
5051

5152

5253
audio_file = request.files['audio_file']
@@ -57,14 +58,14 @@ def enroll():
5758
output['DecisionReason']="MISSING_ARGUMENTS"
5859
output['voiceprintId'] = ""
5960
output['voiceModel'] = ""
60-
return output
61+
return output,status
6162
if audio_file.filename == '':
6263
output['trained'] = "failed"
6364
output['EnrollStatus'] = "REJECTED"
6465
output['DecisionReason']="INEXISTANT_FILENAME"
6566
output['voiceprintId'] = ""
6667
output['voiceModel'] = ""
67-
return output
68+
return output,status
6869

6970
username = request.args.get('username')
7071
if username == '':
@@ -73,7 +74,7 @@ def enroll():
7374
output['DecisionReason']="INEXISTANT_USERNAME"
7475
output['voiceprintId'] = ""
7576
output['voiceModel'] = ""
76-
return output
77+
return output,status
7778
#recording = json.loads(audio_file)
7879
#print(recording)
7980
filename = secure_filename(audio_file.filename)
@@ -118,7 +119,7 @@ def enroll():
118119
output['DecisionReason']="ERROR_TRAINING_THE_MODEL"
119120
output['voiceprintId'] = ""
120121
output['voiceModel'] = ""
121-
return output
122+
return output,status
122123
else :
123124
# Saving needed data in mongodb
124125
record['username'] = username
@@ -142,29 +143,30 @@ def enroll():
142143
output['EnrollStatus'] = "ACCEPTED"
143144
output['DecisionReason']="Accepted"
144145

145-
return output
146+
return output,status
146147

147148

148149

149150

150151

151152
@app.route('/api/voiceident/enrollments', methods=['GET'])
152153
def check_enroll():
154+
status = 200
153155
output = {}
154156
if 'username' not in request.args:
155157
output['trained'] = "failed"
156158
output['EnrollStatus'] = "REJECTED"
157159
output['DecisionReason']="MISSING_ARGUMENTS"
158160
output['voiceprintId'] = ""
159161
output['voiceModel'] = ""
160-
return output
162+
return output,status
161163
if 'voiceprintId' not in request.args:
162164
output['trained'] = "failed"
163165
output['EnrollStatus'] = "REJECTED"
164166
output['DecisionReason']="MISSING_ARGUMENTS"
165167
output['voiceprintId'] = ""
166168
output['voiceModel'] = ""
167-
return output
169+
return output,status
168170
voiceprintId = request.args.get('voiceprintId')
169171
username = request.args.get('username')
170172
record = users.find_one({'_id':ObjectId(voiceprintId)})
@@ -175,7 +177,7 @@ def check_enroll():
175177
output['DecisionReason']="ERROR_TRAINING_THE_MODEL"
176178
output['voiceprintId'] = ""
177179
output['voiceModel'] = ""
178-
return output
180+
return output,status
179181
else:
180182
with open(gmm_model_path, 'rb') as binary_file:
181183
binary_file_data = binary_file.read()
@@ -185,41 +187,46 @@ def check_enroll():
185187
output['voiceModel'] = base64_encoded_data
186188
output['EnrollStatus'] = "ACCEPTED"
187189
output['DecisionReason']="Accepted"
188-
return output
190+
return output,status
189191

190192

191193

192194

193195
@app.route('/api/voiceident/authentication', methods=['POST'])
194196
def authentificate():
195197
output = {}
198+
status = 200
196199
if 'audio_file' not in request.files:
200+
status = 403
197201
output['score'] = None
198202
output['Decision'] = "MISMATCH"
199203
output['DecisionReason']="AUDIO_FILE_NOT_SENT"
200-
return output
204+
return output,status
201205

202206

203207

204208

205209
audio_file = request.files['audio_file']
206210

207211
if audio_file.filename == '':
212+
status = 403
208213
output['score'] = None
209214
output['Decision'] = "MISMATCH"
210215
output['DecisionReason']="INEXISTANT_FILENAME"
211-
return output
216+
return output,status
212217
if 'username' not in request.args:
218+
status = 464
213219
output['score'] = None
214220
output['Decision'] = "MISMATCH"
215221
output['DecisionReason']="MISSING_ARGUMENTS"
216-
return output
222+
return output,status
217223

218224
if 'voiceprintId' not in request.args:
225+
status = 464
219226
output['score'] = None
220227
output['Decision'] = "MISMATCH"
221228
output['DecisionReason']="MISSING_ARGUMENTS"
222-
return output
229+
return output,status
223230

224231
filename = secure_filename(audio_file.filename)
225232
audio_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
@@ -239,10 +246,11 @@ def authentificate():
239246
username = request.args.get('username')
240247
record = users.find_one({'username':username})
241248
if record == None:
249+
status = 464
242250
output['score'] = None
243251
output['Decision'] = "MISMATCH"
244252
output['DecisionReason']="INEXISTANT_USERNAME"
245-
return output
253+
return output,status
246254

247255

248256

@@ -267,7 +275,7 @@ def authentificate():
267275
output['score'] = round(score*100,2)
268276
output['Decision'] = "MISMATCH"
269277
output['DecisionReason']="BIOMETRIC_MISMATCH"
270-
return output
278+
return output,status
271279
else:
272280
identity,score = recognize(os.path.join(app.config['UPLOAD_FOLDER'], filen),username)
273281
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
@@ -280,7 +288,7 @@ def authentificate():
280288
output['score'] = round(score*100,2)
281289
output['Decision'] = "MISMATCH"
282290
output['DecisionReason']="BIOMETRIC_MISMATCH"
283-
return output
291+
return output,status
284292

285293

286294

gmm_models/ihab.gmm

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)