-
Notifications
You must be signed in to change notification settings - Fork 1
/
error and mistakes.py
219 lines (162 loc) · 6.03 KB
/
error and mistakes.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
207
208
209
210
211
212
213
214
215
216
217
218
219
import speech_recognition as sr
import playsound
from gtts import gTTS
import random
import webbrowser
import os
import pyautogui
import pyttsx3
import datetime
import pywhatkit
import wikipedia
import pyjokes
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
class person:
name = ''
def setName(self, name):
self.name = name
class asis:
name = ''
def setName(self, name):
self.name = name
def talk(text):
text = str(text)
engine.say(text)
engine.runAndWait()
def talk(audio_string):
audio_string = str(audio_string)
tts = gTTS(text=audio_string, lang='en')
r = random.randint(1, 20000000)
audio_file = 'audio' + str(r) + '.mp3'
tts.save(audio_file)
playsound.playsound(audio_file)
print(asis_obj.name + ":", audio_string)
os.remove(audio_file)
def take_command():
try:
with sr.Microphone() as source:
print('How may i help ?')
talk('How may i help ?')
voice = listener.listen(source)
command =listener.recognize_google(voice)
command = command.lower(voice)
if 'Tess' in command:
command = command.replace('Tess', '')
print(command)
except:
pass
return command
def run_Tess():
command = take_command()
print(command)
# play music on youtube
if'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
print('playing ' + song)
pywhatkit.playonyt(song)
# what is the time ?
elif 'time' in command:
time = datetime.datetime.now().strftime('%I %M %p')
talk('Current time is ' + time)
print(time)
# wikipedia
elif 'what is' in command:
meaning = command.replace('what is', '')
info = wikipedia.summary(meaning, 1)
print(info)
talk(info)
# Need some Computer eng. Jokes
elif 'joke' in command:
talk(pyjokes.get_joke())
# Greeting
elif ('hey', 'hi', 'hello', 'hai', 'yo', 'Tess') in command:
greetings = ["hey, how can i help out" + person_obj.name, "Hey, what's up?" + person_obj.name,
"I'm all ears" + person_obj.name, "How can i help you?" + person_obj.name,
"Hello" + person_obj.name]
greet = greetings[random.randint(0, len(greetings) - 1)]
talk(greet)
# Greeting 2
elif(["how are you", "how are you doing"]) in command:
talk("I'm very well, thanks for asking " + person_obj.name)
# Google Search
elif(["search for"]) in command and 'youtube' not in command:
search_term = command.split("search for")[-1]
url = "https://google.com/search?q=" + search_term
webbrowser.get().open(url)
talk("Here is what I found for" + search_term + "on google")
# Know the stocks
elif(["price of"]) in command:
search_term = command.split("for")[-1]
url = "https://google.com/search?q=" + search_term
webbrowser.get().open(url)
talk("Here is what I found for " + search_term + " on google")
# Want some IG
elif(["open instagram", "want to have some fun time"]) in command:
search_term = command.split("for")[-1]
url = "https://www.instagram.com/"
webbrowser.get().open(url)
talk("opening instagram")
# What's the weather
elif(["weather", "tell me the weather report", "whats the condition outside"]) in command:
search_term = command.split("for")[-1]
url = "https://www.google.com/search?sxsrf=ACYBGNSQwMLDByBwdVFIUCbQqya-ET7AAA%3A1578847393212&ei=oUwbXtbXDN-C4-EP-5u82AE&q=weather&oq=weather&gs_l=psy-ab.3..35i39i285i70i256j0i67l4j0i131i67j0i131j0i67l2j0.1630.4591..5475...1.2..2.322.1659.9j5j0j1......0....1..gws-wiz.....10..0i71j35i39j35i362i39._5eSPD47bv8&ved=0ahUKEwiWrJvwwP7mAhVfwTgGHfsNDxsQ4dUDCAs&uact=5"
webbrowser.get().open(url)
talk("Here is what I found for on google")
# Let's see some mails
elif (["open my mail", "gmail", "check my email"]) in command:
search_term = command.split("for")[-1]
url = "https://mail.google.com/mail/u/0/#inbox"
webbrowser.get().open(url)
talk("here you can check your gmail")
# Want a game to play
elif (["game"]):
command = take_command("choose among rock paper or scissor")
moves = ["rock", "paper", "scissor"]
cmove = random.choice(moves)
pmove = command
talk("The computer chose " + cmove)
talk("You chose " + pmove)
# engine_speak("hi")
if pmove == cmove:
talk("the match is draw")
elif pmove == "rock" and cmove == "scissor":
talk("You wins")
elif pmove == "rock" and cmove == "paper":
talk("I won")
elif pmove == "paper" and cmove == "rock":
talk("You wins")
elif pmove == "paper" and cmove == "scissor":
talk("I won")
elif pmove == "scissor" and cmove == "paper":
talk("You wins")
elif pmove == "scissor" and cmove == "rock":
talk("I won")
# Toss a coin Tess
elif(["toss", "flip", "coin"]) in command:
moves = ["head", "tails"]
cmove = random.choice(moves)
talk("The computer chose " + cmove)
# Calculate Tess
elif (["plus", "minus", "multiply", "divide", "power", "+", "-", "*", "/"]):
opr = command.split()[1]
if opr == '+':
talk(int(command.split()[0]) + int(command.split()[2]))
elif opr == '-':
talk(int(command.split()[0]) - int(command.split()[2]))
elif opr == 'multiply':
talk(int(command.split()[0]) * int(command.split()[2]))
elif opr == 'divide':
talk(int(command.split()[0]) / int(command.split()[2]))
elif opr == 'power':
talk(int(command.split()[0]) ** int(voice_data.split()[2]))
else:
talk("Wrong Operator")
person_obj = person()
asis_obj = asis()
asis_obj.name = 'TESS'
engine = pyttsx3.init()
run_Tess()