This repository was archived by the owner on Nov 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvoice.py
More file actions
62 lines (52 loc) · 1.98 KB
/
voice.py
File metadata and controls
62 lines (52 loc) · 1.98 KB
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
55
56
57
58
59
60
61
62
from flask import Flask
from flask_ask import Ask, statement, question, session
import traceback
import random
import os
import requests
import logging
import time
import json
import subprocess
import face_recognition
logging.getLogger('flask_ask').setLevel(logging.DEBUG)
app = Flask(__name__)
ask = Ask(app, '/')
""" These functions handle what are essentially the beginning and end of the main use case of the skill."""
@ask.launch
def start_session():
return question("Please Wait. Processing...")
@ask.intent('DescribeWorldIntent')
def speaknext():
result = subprocess.getoutput(
'curl -F "image=@imgcptn/png/example.jpeg" -X POST http://localhost:5000/model/predict')
result = result.split('{', 1)[1]
result = "{" + result
res = json.loads(result)
speechstring = res["predictions"][0]["caption"]
return question(speechstring)
@ask.intent('WantPersonNames')
def speakpersonname():
directory = os.fsencode("knownpeople")
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith(".jpeg"):
picture_of_me = face_recognition.load_image_file(
"knownpeople/"+filename)
my_face_encoding = face_recognition.face_encodings(picture_of_me)[
0]
unknown_picture = face_recognition.load_image_file(
"imgcptn/png/example.jpeg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[
0]
# Now we can see the two face encodings are of the same person with `compare_faces`!
results = face_recognition.compare_faces(
[my_face_encoding], unknown_face_encoding)
if results[0] == True:
sentence = "I can see " + os.path.splitext(filename)[0]
print(sentence)
return question(sentence)
else:
return question("Nobody known was found")
if __name__ == '__main__':
app.run(debug=True, port=5001)