-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
161 lines (138 loc) · 4.65 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
import datetime
import os
import random
import smtplib
import webbrowser
from pygame import mixer
import time
import speech_recognition as sr
import pyttsx3
import wikipedia
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def sendEmail(to, content):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login("[email protected]", 'abcde&12345')
server.sendmail('[email protected]', to, content)
server.close()
return
def marvel_jarvisVoice():
# p = vlc.MediaPlayer('')
# p.play()
mixer.init()
mixer.music.load('marvel_voice.mp3')
mixer.music.play()
time.sleep(20)
return
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wish_me():
# optional
marvel_jarvisVoice()
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 12:
speak("Good Morning!")
elif 12 <= hour < 18:
speak("Good Afternoon")
else:
speak("Good Evening")
speak("I am apex at you Service Sir!!,How can i help you ?")
return
def take_command():
# take input from upper microphone and change that to a string
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"user said: {query} \n")
except Exception as e:
print(e)
print("say that Again Please...")
return "None"
return query
def googleSearch():
new = 2
tabUrl = "https://www.google.com/search?q="
term = take_command()
repeat = False
if term == "None":
speak("Sorry,i was unable to hear ")
speak("will you repeat ?")
whetherRepeat = take_command()
if whetherRepeat == "no":
return
else:
googleSearch()
else:
webbrowser.open(tabUrl + term, new=new)
if __name__ == '__main__':
wish_me()
while True:
query = take_command().lower()
# logic for executing task based upon query
if 'wikipedia' in query:
speak('Seaching Wikipedia....')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print(results)
speak("According to wikipedia")
speak(results)
elif 'open youtube' in query:
webbrowser.open("youtube.com")
elif 'open google' in query:
webbrowser.open("google.com")
elif 'open stackoverflow' in query:
webbrowser.open("stackoverflow.com")
elif 'open stack overflow' in query:
webbrowser.open("stackoverflow.com")
elif 'music' in query:
music_dir = 'C:\\Users\\adars\\Music\\Playlists'
songs = os.listdir(music_dir)
print(songs)
n = random.choice(songs)
os.startfile(os.path.join(music_dir, n))
elif 'time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
elif 'opera' in query:
codePath = "C:\\Users\\adars\\AppData\\Local\\Programs\\Opera\\launcher.exe"
os.startfile(codePath)
elif 'what is your name' in query:
str = "My name's ,Jarvis your personal voice assistant."
speak(str)
str = "I just wish that ,everyone had a nickname ,as cool as mine."
speak(str)
elif 'send mail' in query:
try:
speak("What should i send ?")
content = take_command()
to = "[email protected]"
sendEmail(to, content)
speak("Email has been send, Sir")
except Exception as e:
print(e)
speak("Sorry Sir , I am unable to send this mail")
elif 'quit' in query:
break
elif 'search' in query:
speak("Sure To find info about Something")
speak("Just say")
googleSearch()
break
elif 'wait' in query:
speak("No rush! Take your time")
elif 'hello' in query:
speak("hii it's good to hear from you.")
speak("I hope you and your loved ones are staying safe and healthy during this difficult time.")
elif 'how are you' in query:
speak("i'm fine,thanks for asking")
speak("This is a challenging time for us.")
speak("I hope you and your loved ones are staying safe and healthy")