-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspeaker_recognition.py
executable file
·36 lines (29 loc) · 1 KB
/
speaker_recognition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from piwho import recognition
from piwho import vad
from sound_recorder import record
def find_speaker(flag):
recog = recognition.SpeakerRecognizer()
# Record voice until silence is detected
# save WAV file
#vad.record()
record(5,'test.wav')
# use newly recorded file for recognition
name = []
name = recog.identify_speaker('test.wav')
dictn = recog.get_speaker_scores()
print(name[0])
print(dictn)
if flag == 1:
if float(dictn[name[0]]) < 0.5:
print ('Congratulation !!! with distance ' + dictn[name[0]])
return "CONGRATULATIONS!"
else:
print ('Sorry... with distance ' + dictn[name[0]])
return "Please retry."
elif flag == -1:
if float(dictn[name[0]]) < 0.4:
print ('Congratulation !!! with distance ' + dictn[name[0]])
return "CONGRATULATIONS!"
else:
print ('Sorry... with distance ' + dictn[name[0]])
return "Please retry."