-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax.py
68 lines (63 loc) · 1.96 KB
/
max.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
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import sys
listener = sr.Recognizer()
engine = pyttsx3.init()
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
talk('Hey, I am Max, your virtual voice assistant, what can I do for you now?')
print("Listening.....")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'max' in command:
command=command.replace('max','')
print(command)
elif 'max' not in command:
talk('Please say a valid command and try again')
sys.exit(2)
except SystemExit:
sys.exit(2)
except:
sys.exit(2)
return command
def run_max():
try:
command = take_command()
if 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk(time)
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'search' in command:
to_serach = command.replace('search', '')
talk('seacrhing' + to_serach)
pywhatkit.search(to_serach)
elif 'play' in command:
song = command.replace('play', '')
talk('playing' + song)
pywhatkit.playonyt(song)
talk('Now the time is' + time)
elif 'who is' or 'what is' in command:
to_check = command.replace('what is', '')
to_check = command.replace('who is', '')
info = wikipedia.summary(to_check, 2)
talk('From wikipedia, ' + info)
elif 'quit' in command:
sys.exit(2)
else:
talk('Please say a valid command and do try again')
except SystemExit:
sys.exit(2)
except:
sys.exit(2)
while True:
run_max()