-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
215 lines (182 loc) · 5.67 KB
/
main.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
#importing all requried Libary
import pyttsx3
import speech_recognition as sr
import AppOpener
import webbrowser
import time
import pywhatkit
import datetime
import Recommendationmovie
import jokes
import whatapp
from playsound import playsound
import wikipedia
# from pywinauto import application
from news import Technology,science,sports,business,Entertainment,Health,headLine
#getting the voice from the system
Assistant = pyttsx3.init('sapi5')
voice = Assistant.getProperty('voices')
Assistant.setProperty('voice', voice[0].id)
Assistant.setProperty('rate',200)
# app = application.Application()
#speaking function
def speak(audio):
Assistant.say(audio)
print("\n")
print(audio)
Assistant.runAndWait()
#recognition voice function
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"You said: {query}\n")
except Exception as e:
return "None"
return query
#greeting Function
def greeting():
current_time = datetime.datetime.now()
if current_time.hour < 12:
speak("Good Morning")
elif 12 <= current_time.hour < 18:
speak("Good Afternoon")
else:
speak("Good Evening")
#opening site function
def site():
speak("Which site to open?")
query = takeCommand()
if 'Instagram' in query:
query = query.replace("open", "")
webbrowser.open("http://Instagram.com")
elif 'Facebook' in query:
query = query.replace("open", "")
webbrowser.open("http://www.Facebook.com")
elif 'Twitter' in query:
query = query.replace("open", "")
webbrowser.open("http://www.Twitter.com")
else:
query = query.replace("open", "")
query = query.replace(" ", "")
webbrowser.open(f"http://{query}.com")
# Opening Application Function
def openApps(query):
try:
AppOpener.open(query)
except FileNotFoundError as e:
print("The system cannot find the file")
# closing Application Function
def closeApp(query):
try:
AppOpener.close(query)
except FileNotFoundError as e:
print("The system cannot find the file")
#Google search function
def googleSearch(query):
pywhatkit.search(query)
speak("Done")
#displaying news Function
def TopHeadLines(query):
try:
if ('business') in query:
business()
elif('health') in query:
Health()
elif ('sports') in query:
sports()
elif ('technology') in query:
Technology()
elif ('science') in query:
science()
elif ('entertainment') in query:
Entertainment()
else:
headLine()
except:
print("Error")
#wikipidea
def wiki(query):
speak(wikipedia.summary(query,sentences = 2))
#Get the Movie
def recomMovie():
Recommendationmovie.movie()
#WhatsApp command
def whatsApp(query):
whatapp.data(query)
#Jokes Command
def Jokes():
jokes.joke()
#byee
def bye():
speak("Thanks for Using me")
speak("Bye , Take care")
quit()
#taking input form users to do task respectively
def task():
while True:
query = takeCommand()
if ('hey Jarvis how are you') in query:
speak("I am all Good")
speak("What about You? How are you?")
elif ('take rest') in query:
speak("OK , Just say Hey when u needed me")
break
elif ('I am good') in query:
speak("Good to know , How can i Help u?")
elif ('search') in query.lower():
query = query.replace("google search", "")
googleSearch(query)
speak("What else I should do for u?")
elif ('open a website') in query:
site()
speak("What else I should do for u?")
elif ('open') in query:
query = query.replace("open", "")
openApps(query)
speak("What else I should do for u?")
elif('close') in query:
query = query.replace("close", "")
closeApp(query)
speak("What else I should do for u?")
elif ('top headline') in query:
TopHeadLines(query)
speak("What else I should do for u?")
elif ('recommend a good movie') in query:
recomMovie()
speak("What else I should do for u?")
elif ('tell me a joke') in query:
Jokes()
speak("What else I should do for u?")
elif ('send message') in query:
query =query.replace('send message','')
query =query.replace('to','')
query =query.replace(' ', '')
print(query)
whatsApp(query)
speak("What else I should do for u?")
elif ('who is') in query:
query = query.replace('who is',"")
query = query.replace('what is ',"")
wiki(query)
elif ('bye') in query:
speak("Thanks for Using me")
speak("Bye , Take care")
bye()
else:
speak("Say that again please..")
#main Function
def main():
greeting()
playsound('audio.MP3')
time.sleep(2)
speak("All ready to go!")
speak("Hey")
task()
if __name__ == '__main__':
main()