-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
54 lines (44 loc) · 1.53 KB
/
client.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
50
51
52
53
54
#!/usr/local/bin/python3
import os
from pathlib import Path
from clients.webcamclient import WebcamClient
from clients.audioclient import AudioClient
def on_success(res):
"""print thread success result"""
print(res)
def on_failure(res):
""" print thread failure result"""
print(res)
HANDLERS = {'on_success':on_success, 'on_failure': on_failure}
def main(user_input):
""" execute the ms emotion apis """
try:
client = WebcamClient(
os.environ['EMOTION_API'],
os.environ['FACE_API'],
os.environ['CV_API'],
HANDLERS)
if user_input == 'emotion':
client.set_emotion()
elif user_input == 'face':
client.set_face()
else:
client.set_cv()
client.disable_local_faces()
client.run()
except KeyboardInterrupt:
temp_image = Path(client.IMAGE_PATH)
if temp_image.is_file():
os.remove(client.IMAGE_PATH)
exit(0)
if __name__ == '__main__':
print("Say 'Emotion' if you want to detect the emotion")
print("Say 'Face' if you want to detect the face")
print("Say 'Computer' if you want to run the computer vision detection")
user_input = ""
audioclient = AudioClient(os.environ['SPEECH_API'])
while user_input not in ["emotion", "face", "computer"]:
print("I'm listening.... ")
user_input = audioclient.run().lower()
print("You said: {}".format("unrecognizable word" if user_input == 'error' else user_input))
main(user_input)