-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.py
133 lines (109 loc) · 4.68 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
import pyttsx3
import pyaudio
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
from random import randint
engine = pyttsx3.init('sapi5')
voice = engine.getProperty('voices')
# print(voice)
engine.setProperty('voice', voice[1].id)
engine.setProperty('rate', 150)
# Making the speak function so that our Jarvis can speak
def speak(text, pr=1):
if pr==1:
print(text)
engine.say(text)
engine.runAndWait()
# speak('Hello World')
def wish():
date = datetime.datetime.now().hour
# print(date)
if date<12:
speak('Good Morning sir.')
elif date<18:
speak('Good Afternoon sir.')
elif date<24:
speak('Good Evening sir.')
speak("I am Jarvis. How may I help you?")
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-us')
print(f'User said : {query}')
except Exception as e:
print('Say that again please...')
return 'None'
return query
if __name__ == "__main__":
wish()
# Wring the logic of the program
while True:
query = takeCommand().lower()
if 'tell me' in query or 'wikipedia' in query:
speak('Searching in wikipedia...')
query = query.replace('tell me', '')
try:
results = wikipedia.summary(query, sentences=5)
speak(f'\nAccroding to wikipedia, {results}')
except Exception as e:
speak("Sorry, couldn't find any result..")
elif 'search in google' in query or 'google search' in query or 'search google' in query or 'google search' in query :
speak('What should I search for you...')
googleSearchQuery = takeCommand().lower()
if googleSearchQuery != 'none':
speak('Searching in google about this topic...')
webbrowser.open(f"https://www.google.com/search?q={googleSearchQuery}")
elif 'open google' in query or 'go to google' in query:
speak('Opening Google')
webbrowser.open('https://google.com/')
elif 'open facebook' in query or 'go to facebook' in query:
speak('Opening Facebook')
webbrowser.open('https://facebook.com/')
elif 'open stack overflow' in query or 'go to stack overflow' in query:
speak('Opening Stackoverflow')
webbrowser.open('https://stackoverflow.com/')
elif 'open git hub' in query or 'go to git hub' in query or 'git hub' in query:
speak('Opening Github')
webbrowser.open('https://github.com/')
elif 'open youtube' in query or 'go to youtube' in query:
speak('Opening Youtube')
webbrowser.open('https://youtube.com/')
elif 'open code with harry' in query or 'go to code with harry' in query or 'code with harry' in query:
speak('Opening Your Favourate Channel')
webbrowser.open('https://youtube.com/')
elif 'open messenger' in query or 'go to messenger' in query:
speak('Opening Messenger')
webbrowser.open('https://www.facebook.com/messages/')
elif "open fn's club" in query or "go to fn's club" in query or "fn's club" in query or "club" in query:
speak("Opening Fn'sclub")
webbrowser.open('https://club.fnsoftwares.com/')
elif 'open google activity' in query or 'google activity' in query or 'open my activity' in query or 'my activity.google' in query or 'my activity.google.com' in query or 'my activity' in query or 'check my google activity' in query :
speak('Opening Your ')
webbrowser.open('https://myactivity.google.com/')
elif "go now" in query or "ok stop now" in query or "ok stop" in query or "stop" in query or "you can stop" in query or "stop now" in query:
speak('Thank you sir.\nCall me anytime you need.')
exit()
else:
n = randint(1, 5)
if n == 1:
speak("Sir, should I stop?")
elif n == 2:
speak("Sir, what should I do now?")
elif n == 2:
speak("Sir, should I do anything more?")
elif n == 3:
speak("What else I have to do sir?")
elif n == 4:
speak("Anything else sir?")
elif n == 5:
speak("Please give me an order sir")
elif n == 6:
speak("Sir, Should I go now?")
# https://www.google.com/search?q=myactivity