-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalex.py
105 lines (89 loc) · 2.74 KB
/
alex.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
import datetime
import speech_recognition as sr
import pyttsx3
import pywhatkit
import wikipedia
from datetime import date
import webbrowser
listner=sr.Recognizer()
engine=pyttsx3.init()
voices=engine.getProperty('voices')
engine.setProperty("voice", voices[0].id)
voicerate=150
engine.setProperty('rate',voicerate)
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print("listening...")
talk('listening')
voice=listner.listen(source)
command=listner.recognize_google(voice)
command=command.lower()
if "alexa" in command:
command=command.replace("alexa","")
#print(command)
#talk(command)
return command
except:
pass
def run_alex():
command =take_command()
try:
if "play" in command:
song=command.replace("play","")
talk("playing")
print(song)
talk(song)
pywhatkit.playonyt(song)
elif 'who is' in command:
infom=command.replace('who is','')
talk("searching for "+infom)
res=wikipedia.summary(infom)
print(res)
talk(res)
elif 'date' in command:
d=date.today()
talk("to day's date is ")
talk(d)
print(d)
elif 'time' in command:
e=datetime.datetime.now()
t="%s:%s:%s" % (e.hour, e.minute, e.second)
talk("the time is ")
talk(t)
print(t)
elif"dateandtime" in command:
td=datetime.datetime.now()
talk("the time and date is ")
talk(td)
print(td)
elif"quit" in command:
talk("thank you sir")
quit()
elif "go away" in command:
talk("thank you sir")
quit()
elif "browse" in command:
talk('opening browser')
search_term=command.replace("browse", "")
new = "https://www.google.com.tr/search?q={}".format(search_term)
webbrowser.open(new)
elif "define" in command:
talk("searching")
command=command.replace("define","")
search_term = "define:"+command+""
new = "https://www.google.com.tr/search?q={}".format(search_term)
webbrowser.open(new)
elif "where do i find" in command:
talk("searching")
command=command.replace("define","")
search_term = "inurl:"+command+""
new = "https://www.google.com.tr/search?q={}".format(search_term)
webbrowser.open(new)
except:
pass
while True:
run_alex()