-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVirtual-assistant.py
More file actions
162 lines (102 loc) · 3.11 KB
/
Virtual-assistant.py
File metadata and controls
162 lines (102 loc) · 3.11 KB
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
162
import pyttsx3
import speech_recognition as sr
import webbrowser
import datetime
import wikipedia
import pywhatkit
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening')
r.pause_threshold = 0.7
audio = r.listen(source)
try:
print("Recognizing")
Query = r.recognize_google(audio, language='en-in')
print("the command is printed=", Query)
except Exception as e:
print(e)
print("Say that again sir")
return "None"
return Query
def speak(audio):
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.say(audio)
engine.runAndWait()
def tellDay():
day = datetime.datetime.today().weekday() + 1
Day_dict = {1: 'Monday', 2: 'Tuesday',
3: 'Wednesday', 4: 'Thursday',
5: 'Friday', 6: 'Saturday',
7: 'Sunday'}
if day in Day_dict.keys():
day_of_the_week = Day_dict[day]
print(day_of_the_week)
speak("The day is " + day_of_the_week)
def tellTime():
time = str(datetime.datetime.now())
print(time)
hour = time[11:13]
min = time[14:16]
speak(self, "The time is sir" + hour + "Hours and" + min + "Minutes")
def Hello():
speak("hello sir I am moxa, your desktop assistant.Tell me how may I help you")
def Take_query():
Hello()
while(True):
query = takeCommand().lower()
if "open geeksforgeeks" in query:
speak("Opening GeeksforGeeks ")
webbrowser.open("www.geeksforgeeks.com")
continue
elif "open google" in query:
speak("Opening Google ")
webbrowser.open("www.google.com")
continue
elif "which day it is" in query:
tellDay()
continue
elif "open news" in query:
speak("Opening news ")
webbrowser.open("https://indianexpress.com/")
continue
elif "tell me the time" in query:
tellTime()
continue
elif "take me to hacktoberfest" in query:
speak("Opening Hacktoberfest ")
webbrowser.open("https://hacktoberfest.digitalocean.com")
continue
elif "open hacktoberfest discussion thread in twitter" in query:
speak("Opening Hacktoberfest Discussion thread in Twitter.")
webbrowser.open("https://twitter.com/search?q=%23hacktoberfest")
continue
elif "First time Contributors can contribute to vinitshahdeo Github" in query:
speak("First time Contributors in Hacktoberfest.")
webbrowser.open("https://github.com/vinitshahdeo")
continue
elif "bye" in query:
speak("Bye for now...stay safe , stay happy , stay healthy")
exit()
elif "from wikipedia" in query:
speak("Checking the wikipedia ")
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=4)
speak("According to wikipedia")
speak(result)
elif 'play' in query:
song = query.replace('play', '')
print('playing '+ song)
speak('playing'+ song)
pywhatkit.playonyt(song)
continue
elif "tell me your name" in query:
speak("I am moxa. Your deskstop Assistant")
continue
elif "your favourite programming language" in query:
speak("I love python the most ")
continue
if __name__ == '__main__':
Take_query()