This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome-ai.py
206 lines (118 loc) · 6 KB
/
home-ai.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import os
import time
import json
import pyttsx3
import speech_recognizer
import arduino_controller
import chatbot
import commands_creater
import command_performer
# Environmental Commands
# Arduino Commands Control
arduino_commands = commands_creater.Arduino_commands() # Only returns two items
arduino_commands_names = arduino_commands[0] # List of Arduino Commands
arduino_key_value_dict = arduino_commands[1] # List of Arduino Commands and Key Values
# Chatbot Commands
bot_commands = commands_creater.Bot_commands() # Only returns three items
bot_commands_names = bot_commands[0] # List of supported bot Commands
bot_system_commands_names = bot_commands[1] # List of all system commands that the bot can perform
bot_key_value_dict = bot_commands[2] # List of Bot Commands and system_command Values
# Load json data
#command_data = json.loads(json_command_data)
# Load Arduino commands data
#arduino_command_data = json.loads(json_arduino_command_data)
# Load Chatbot commands data
#chatbot_command_data = json.loads(json_chatbot_command_data)
#################
def filter_command():
#while True:
command = speech_recognizer.speech_2_text().upper() # For recognizing the voice to perform task
#command = "Hey Friday, off port three".upper() #testing for aurdino
#command = "Hey Friday, How are you".upper() # Testing for chat_bot
#command = "Hey Friday, Open Explorer".upper()
print(f"{commands_creater.user_name()} --> {command}")
ai_name_calling_lst = commands_creater.AI_name_calling_lst() # AI Names list
# Sample Command -> Hey Friday, on port three
if command == "NONE":
# if nothing is said to it
#print("none command initilized")
return ["Not Hearing", "nothing"]
for ai_call_name in ai_name_calling_lst:
if (ai_call_name.upper() in command) == True:
#print("ai_call_name",ai_call_name)
#if (("OK FRIDAY" in command.upper()) == True) or (("HELLO FRIDAY" in command.upper()) == True):
#print("PLEASE PROVIDE A COMMAND TO CONTINUE\nTalk")
#command = speech_recognizer.speech_2_text()
#command = "on port eight"
#command =
if arduino_controller.arduino_connection_checker() == "NOT_CONNECTED":
# If Arduino is not connected with the system then
# it skips the Arduino functions
pass
elif arduino_controller.arduino_connection_checker() == "CONNECTED":
# If Arduino is connected then it checks the Arduino functions
for saved_arduino_command in arduino_commands_names:
#print(command)
## Arduino Command Area
if (saved_arduino_command.upper() in command) == True:
# return pin_number and pin_state to initilize
#print("Arduino command")
return [arduino_key_value_dict[saved_arduino_command], "arduino"] # format -> [{03:1}, "arduino"]
else:
continue
## *****************************************************************
# For bot command Action
for saved_bot_command in bot_commands_names:
if (saved_bot_command.upper() in command) == True:
#print(bot_key_value_dict[saved_bot_command])
return [bot_key_value_dict[saved_bot_command], "bot_system_command"] # Format -> ["exit()", "bot_system_command"]
else:
continue
#################################################################################
# If both of the above doesn't work then it will be
# redirected to Chatbot, and the chatbot will result
# the output if any.
## Chatbot command area
# return command to initilize in chatbot
#command = command.replace(ai_call_name, "") # Removes the AI Calling Name
response = chatbot.chatbot_response(command.replace(ai_call_name, "")) # Removes the First ai calling command from the string
return [response, "chatbot"] # format -> ["response_from_chat_bot", "chatbot"]
else:
# return command to initilize in chatbot
#response = chatbot.chatbot_response(command.replace(ai_call_name, "")) # Removes the First ai calling command from the string
#return [response, "chatbot"]
continue
#return ["nothing", "NONE"]
# print("Time over, thanks")
else:
return ["Not Hearing", "nothing"]
def main():
try :
while True:
command_performer.clear_screen() # Clears the Screen after every command
commands_creater.banner() # Create the banner for this project
# The Data that are to be returned
# Example:
# For Arduino it Would be : [{03:1}, "arduino"]
# For bot_for system functions : ["exit()", "bot_system_command"]
# For Chat_bot it would be : ["response_from_chat_bot", "chatbot"]
# For not hearing it would be : ["Not Hearing", "nothing"]
#
command_data = filter_command()
if command_data[1] == "arduino":
command_performer.init_arduino_func(command_data)
elif command_data[1] == "bot_system_command":
command_performer.bot_system_command_performer(command_data)
elif command_data[1] == "chatbot":
command_performer.chatbot_response_audio(command_data)
elif command_data[1] == "nothing":
continue
else:
print("none heard")
#exit()
except KeyboardInterrupt:
# Exit the program if Keyboad Interupt occur
# Usually Keyboard Interrupt is given with "CTRL+C" key function
command_performer.exit_program()
if __name__ == "__main__":
main()