-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
139 lines (108 loc) · 4.18 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
import os
import pyautogui as him2
import pyttsx3
import pywhatkit as him
import speech_recognition as him1
import wikipedia
import webbrowser
import smtplib
import datetime
import folium
import cv2
import pytube
from pytube import YouTube
import numpy as np
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def greet():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning Himanshu Sir, Have Your Tea Or Coffee!")
elif hour>=12 and hour<18:
speak("Good Afternoon Himanshu Sir, Have Your Lunch or not!")
else:
speak("Good Evening Himanshu Sir ,Have Your Snacks or not!")
speak("I am MALGO Your Personal Assistant Sir. How may I help you")
def Command():
r = him1.Recognizer()
with him1.Microphone() as source:
r.adjust_for_ambient_noise(source,duration=4)
print("Listening You Sir......")
speak("Listening You Sir......")
r.pause_threshold = 0.6
audio = r.listen(source)
try:
print("Trying to understand...")
speak("Trying to understand...")
query = r.recognize_google(audio, language='en-in').lower()
print("Ok Sir :-)\n")
speak("Ok Sir \n")
except Exception as e:
print(e)
print("Please Say That Again Sir...")
speak("Please Say That Again Sir...")
return "None"
return query
def Email(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('[email protected]', 'password')
server.sendmail('[email protected]', to, content)
server.close()
if __name__ == "__main__":
greet()
while (True):
query = Command().lower()
if 'Tell Me About ' in query:
speak('Searching From Internet...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("As Internet Says...")
print(results)
speak(results)
elif 'open my google' in query:
webbrowser.open("www.google.com")
print("Opening Google")
speak("Opening Google")
elif 'send whatsapp to me' in query:
him.sendwhatmsg("+919634470602","Hi sir how are you?",17,40)
print("Sending Whatsapp Message")
speak("Sending Whatsapp Message")
elif 'Map current location' in query:
curr_map=folium.Map(location=[27.1843328,77.98784]).save("E:\\TEST\\him.html")
webbrowser.open("E:\\TEST\\him.html")
print("Done Sir")
speak("Done Sir")
elif 'open my youtube' in query:
webbrowser.open("www.youtube.com")
print("Done Sir")
speak("Done Sir")
elif 'open my github ' in query:
webbrowser.open("www.github.com")
print("Done Sir")
speak("Done Sir")
elif 'open image MALGO' in query:
image_dir = "C:\\Users\\GOLASHBOY\\Pictures\\Camera Roll"
image = os.listdir(image_dir)
print(image)
os.startfile(os.path.join(image_dir, image[0]))
print("Done Sir")
speak("Done Sir")
elif 'Tell me the current time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak("Sir, the time is {strTime}")
elif 'email to Sir' in query:
try:
speak("What should be in email Sir ?")
content = Command()
to = "[email protected]"
Email(to, content)
speak("Email has been sent Successfully to You Sir!")
except Exception as e:
print(e)
speak("Sorry Sir. I am not able to send this email to anyone.")