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 pathcommand_performer.py
115 lines (69 loc) · 3.39 KB
/
command_performer.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
import os
import arduino_controller
import pyttsx3
import platform
def write_arduino_pin_data(arduino_pin_data):
# Writes the Data of pin numbers and it's state to arduino_previous_pin_state.txt
arduino_pin_data_dict_to_str = str(arduino_pin_data).replace("{'", "").replace("'}","").replace("': '", " : ").replace("', '", "\n")
#print(arduino_pin_data_dict_to_str)
# Write the new data to the text file
arduino_pre_pin_state = open("commands_data/arduino_previous_state.txt", "w")
arduino_pre_pin_state.write(arduino_pin_data_dict_to_str)
#print(arduino_pin_data_dict_to_str)
arduino_pre_pin_state.close()
def init_arduino_func(arduino_command_data):
# Identify if the data belongs to arduino
# if it is for arduino then
# it initiate the arduino to perform the function
arduino_pin_details = arduino_command_data
command_identifier = arduino_pin_details[1]
if command_identifier == "arduino":
arduino_pin_data = arduino_pin_details[0] # Dictionary data for pin state setup
# arduino_pin_data.keys() -> pin number
# arduino_pin_data.values() -> pin state
#arduino_pin_number = arduino_pin_data
# Recognizing the commands as arduino commands
# commiting the pin state
# process the dictionary data
# Example pin_dic = {"3": "1"}
#print(arduino_pin_data)
arduino_controller.init_pin(arduino_pin_data)
def chatbot_response_audio(chatbot_command_data):
chatbot_command_details = chatbot_command_data # list Example -> ["response_from_chat_bot", "chatbot"]
command_identifier = chatbot_command_details[1]
if command_identifier == "chatbot":
chat_bot_reply = chatbot_command_details[0] # Reply from Chat_Bot
# pass the command to chatbot and it will provide a response
#chatbot_response_text = chatbot.chatbot_response(command)
#pyttsx3.speak(chatbot_response_text)
#print(chat_bot_reply)
# Convert the Text to Speech
# So that it seems to be that
# the chatbot is speaking
pyttsx3.speak(chat_bot_reply)
def bot_system_command_performer(bot_system_command_data):
bot_system_command_details = bot_system_command_data # list Example -> ["exit()", "bot_system_command"]
command_identifier = bot_system_command_details[1]
if command_identifier == "bot_system_command":
# System commands can easily set in the bot_commands.txt file
# For Linux or Windows systems of the choice
print("Bot System Command Successfully Performed")
os.system(bot_system_command_details[0]) # perform System commands
pyttsx3.speak("Task Successfully Performed") # Speak the following line after initilizing the command
def clear_screen():
# This function is used to clear the screen
platform_name = platform.system().upper() # Return the name of the system (WINDOWS or LINUX)
if platform_name == "WINDOWS":
# If the system is Windows then
os.system("cls")
elif platform_name == "LINUX":
# If platform is Linux then
os.system("clear")
else:
# If Any other platform is used
# which is not recognized
print("\n"*20) # Prints 20 new line character to let it show like, it clears the screen
def exit_program():
# Print the below line and exit the program
print("Thankyou For Using Me !!!")
exit()