-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
47 lines (40 loc) · 1.68 KB
/
core.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
from recognize import Recognizer
from ai import AI
from voice import Voice
from speech_recognition import UnknownValueError, RequestError
from commands.cmds import voca_commands
import string
class Core:
def __init__(self):
self.voice = Voice()
self.brain = AI()
self.recognizer = Recognizer()
def run(self):
while True:
try:
is_command = False
heard = self.recognizer.listen_and_understand().lower()
if "shutdown" in heard:
self.voice.emit("Ok I will turn OFF myself")
exit()
for cmd in voca_commands.keys():
if heard.startswith(cmd):
is_command = True
if heard.strip() == cmd:
print("hear")
voca_commands[cmd].execute(self,
self.voice.emit, self.recognizer.listen_and_understand)
else:
print(heard[len(cmd):])
voca_commands[cmd].execute(self,
self.voice.emit, self.recognizer.listen_and_understand, heard[len(cmd):])
continue
if not is_command :
response = self.brain.generate_response(heard)
self.voice.emit(response)
except UnknownValueError:
#voca_say("What you mean I dont really understood that")
continue
except RequestError:
self.voice.emit(
"Seems like there is an issue with my internet connection")