-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjarvis.py
154 lines (143 loc) · 6.24 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
145
146
147
148
149
150
151
152
153
154
import speech_recognition as sr
import datetime
import wikipedia
import pyttsx3
import webbrowser
import random
import os
#Text To Speech
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print(voices)
engine.setProperty('voice',voices[0].id)
def speak(audio): #here audio is var which contain text
engine.say(audio)
engine.runAndWait()
def wish():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour<12:
speak("good morning sir i am virtual assistent jarvis")
elif hour>=12 and hour<18:
speak("good afternoon sir i am virtual assistent jarvis")
else:
speak("good night sir i am virtual assistent jarvis")
#now convert audio to text
#
def takecom():
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
print("Listning....")
audio = r.listen(source)
try:
print("Recognising.....")
text = r.recognize_google(audio,language='en-in')
print(text)
except Exception: #For Error handling
speak("error...")
print("Network connection error")
return "none"
return text
#for main function
if __name__ == "__main__":
wish()
while True:
query = takecom().lower()
if "wikipedia" in query:
speak("searching details....Wait")
query.replace("wikipedia","")
results = wikipedia.summary(query,sentences=2)
print(results)
speak(results)
elif 'open youtube' in query or "open video online" in query:
webbrowser.open("www.youtube.com")
speak("opening youtube")
elif 'open github' in query:
webbrowser.open("https://www.github.com")
speak("opening github")
elif 'open facebook' in query:
webbrowser.open("https://www.facebook.com")
speak("opening facebook")
elif 'open instagram' in query:
webbrowser.open("https://www.instagram.com")
speak("opening instagram")
elif 'open google' in query:
webbrowser.open("https://www.google.com")
speak("opening google")
elif 'open yahoo' in query:
webbrowser.open("https://www.yahoo.com")
speak("opening yahoo")
elif 'open gmail' in query:
webbrowser.open("https://mail.google.com")
speak("opening google mail")
elif 'open snapdeal' in query:
webbrowser.open("https://www.snapdeal.com")
speak("opening snapdeal")
elif 'open amazon' in query or 'shop online' in query:
webbrowser.open("https://www.amazon.com")
speak("opening amazon")
elif 'open flipkart' in query:
webbrowser.open("https://www.flipkart.com")
speak("opening flipkart")
elif 'open whatsapp' in query:
webbrowser.open("https://web.whatsapp.com/")
speak("opening whatsapp")
elif 'open ebay' in query:
webbrowser.open("https://www.ebay.com")
speak("opening ebay")
elif 'music from pc' in query or "music" in query:
speak("ok i am playing music")
music_dir = 'Music'
musics = os.listdir(music_dir)
os.startfile(os.path.join(music_dir,musics[0]))
elif 'video from pc' in query or "video" in query:
speak("ok i am playing videos")
video_dir = './video'
videos = os.listdir(music_dir) ##give your directories
os.startfile(os.path.join(video_dir,videos[0]))
elif 'good bye' in query:
speak("good bye")
exit()
elif "shutdown" in query:
speak("shutting down")
os.system('shutdown -s')
elif "what\'s up" in query or 'how are you' in query:
stMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!', 'I am nice and full of energy','i am okey ! How are you']
ans_q = random.choice(stMsgs)
speak(ans_q)
ans_take_from_user_how_are_you = takecom()
if 'fine' in ans_take_from_user_how_are_you or 'happy' in ans_take_from_user_how_are_you or 'okey' in ans_take_from_user_how_are_you:
speak('okey..')
elif 'not' in ans_take_from_user_how_are_you or 'sad' in ans_take_from_user_how_are_you or 'upset' in ans_take_from_user_how_are_you:
speak('oh sorry..')
elif ' who make you' in query or 'created you' in query or 'who is your devloper' in query:
ans_m = " For your information Pranjul mangal Created me ! I give Lot of Thannks to Him "
print(ans_m)
speak(ans_m)
elif "who are you" in query or "about you" in query or "your details" in query:
about = "I am Jarvis an A I based computer program but i can help you lot like a your close friend ! i promise you ! Simple try me to give simple command ! like playing music or video from your directory i also play video and song from web or online ! i can also entain you i so think you Understand me ! ok Lets Start "
print(about)
speak(about)
elif "hello" in query or "hello Jarvis" in query:
hel = "Hello Hemant Sir ! How May i Help you.."
print(hel)
speak(hel)
elif "your name" in query or "sweat name" in query:
na_me = "Thanks for Asking my name my self ! Jarvis"
print(na_me)
speak(na_me)
elif "you feeling" in query:
print("feeling Very sweet after meeting with you")
speak("feeling Very sweet after meeting with you")
elif query == 'none':
continue
elif 'exit' in query or 'abort' in query or 'stop' in query or 'bye' in query or 'quit' in query :
ex_exit = 'I feeling very sweet after meeting with you but you are going! i am very sad'
speak(ex_exit)
exit()
else:
temp = query.replace(' ','+')
g_url="https://www.google.com/search?q="
res_g = 'sorry! i cant understand but i search from internet to give your answer ! okay'
print(res_g)
speak(res_g)
webbrowser.open(g_url+temp)