-
Notifications
You must be signed in to change notification settings - Fork 5
/
faceadd.py
49 lines (42 loc) · 1.4 KB
/
faceadd.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import speech_recognition as sr
from gensound import generate_sound
import f_part
import cv2 as cv
def speech(abc):
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Pls say something....")
generate_sound(abc)
audio = r.listen(source)
# recognize speech
try:
print("Google Audio:" + r.recognize_google(audio))
return(r.recognize_google(audio))
# print("Sphinx:" + r.recognize_sphinx(audio))
except sr.UnknownValueError:
generate_sound("Could not understand your response Speak again")
speech(abc)
except sr.RequestError as e:
print("error: {0}".format(e))
generate_sound("Connection Error")
def addn(save):
ans = str(speech("Yes or No"))
if(ans == "yes" or ans == "Yes"):
saveface(save)
elif(ans == "no" or ans == "No"):
ignoreface()
else:
generate_sound("Could not understand your response Answer again")
addn(save)
def saveface(save):
# generate_sound("Tell me the name")
x1 = speech("Tell me the name")
print(x1 + ' face saved')
cv.imwrite(r"images//" +
str(x1) + ".jpg", save)
data = {x1: f_part.img_to_encoding(
"images//" + str(x1) + ".jpg").tolist()}
f_part.digi_db.insert_one(data)
def ignoreface():
generate_sound("Not saved")