-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jarvis.py
144 lines (124 loc) · 4.71 KB
/
Jarvis.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
#this code is property of mr. ansh singhal©
import speech_recognition as sr
import pyttsx3
import datetime
import webbrowser
import pywhatkit
import wikipedia
time = int(datetime.datetime.now().hour)
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source, duration=2) # Adjust for ambient noise
r.energy_threshold = 2000 # Adjust the energy threshold
print("listening....")
audio = r.listen(source)
r.pause_threshold = 2
try:
print("recognising....")
query = r.recognize_google(audio, language="en-in")
print(query)
except:
print(e)
query = ""
print("voice not recognised ...... please try again!")
return str(query)
def say(str):
engine.say(str)
engine.runAndWait()
def wishme():
if time > 4 and time < 12:
say("Good morning user!")
elif time >= 12 and time < 17:
say("Good Afternoon User!")
elif time >= 17 and time < 24:
say("Good evening ")
if __name__ == '__main__':
wishme()
say("I am JARVIS made by mr. Ansh Singhal how may I help you?")
query = str(listen()).lower()
# print(query)
if "open youtube" == query:
webbrowser.open("www.youtube.com")
elif "flipkart" in query:
webbrowser.open("www.flipkart.com")
elif "instagram" in query:
webbrowser.open("www.instagram.com")
elif "facebook" in query:
webbrowser.open("www.facebook.com")
elif "open google" == query:
webbrowser.open("www.google.com")
elif "stackoverflow" in query:
webbrowser.open("www.stackoverflow.com")
elif "github" in query:
webbrowser.open("www.github.com")
elif "microsoft" in query:
webbrowser.open("www.microsoft.com")
elif "send" in query and "whatsapp" in query:
try:
number = "+91"
say("enter the number I have to send message")
number += str(listen())
say("okay, now what should I send?")
msg = listen()
minute = int(datetime.datetime.now().strftime("%M"))+2
pywhatkit.sendwhatmsg(number, msg, time, minute, 10) # type: ignore
except Exception as e:
print(e)
say("I can't send that")
elif "mail" in query or "email" in query:
say("please enter sender's email address in terminal")
sender = input()
say("enter your password in terminal , it is needed, dont worry it is safe")
password = input()
say("please tell the subject of email")
sub = listen()
say("please speak the message")
content = listen()
say("please enter reciever's email in terminal")
reciever = input()
pywhatkit.send_mail(sender, password, str(sub), str(content), reciever) #type: ignore
elif "wikipedia" in query:
query = query.replace("on wikipedia","")
query = query.replace("wikipedia","")
query = query.replace("search","")
say(f"searching {query} on wikipedia")
results = wikipedia.summary(query,sentences = 2)
say("here are the results")
print(results)
say(results)
elif "search" in query and "youtube" in query :
query = query.replace("search","")
query = query.replace("on youtube","")
query = query.replace("youtube","")
string = query.split()
search = ""
for i in string:
search += i
search += "+"
webbrowser.open(f"https://www.youtube.com/results?search_query={search}")
elif "search" in query and "google" in query:
query = query.replace("search","")
query = query.replace("on google","")
query = query.replace("google","")
string = query.split()
search = ""
for i in string:
search += i
search += "+"
webbrowser.open(f"https://www.google.com/search?q={search}&oq={search}&aqs=chrome.0.69i59j0i22i30l9.3639j0j15&sourceid=chrome&ie=UTF-8")
# elif "open code" == query or "vs code" in query:
# path = "path of app"
#path = path.replace("\","/")
#webbrowser.open(path)
else:
string = query.split()
search = ""
for i in string:
search += i
search += "+"
webbrowser.open(f"https://www.google.com/search?q={search}&oq={search}&aqs=chrome.0.69i59j0i22i30l9.3639j0j15&sourceid=chrome&ie=UTF-8")
#copyright© Mr.Ansh singhal