-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.py
More file actions
66 lines (62 loc) · 2.11 KB
/
Index.py
File metadata and controls
66 lines (62 loc) · 2.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
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
def talk(text):
engine.say(text)
engine.runAndWait()
listener = sr.Recognizer()
engine=pyttsx3.init()
voices=engine.getProperty('voices') #this and the next statements are changing male voice to female voice
engine.setProperty('voice',voices[1].id)
engine.say('I am your alexa')
engine.say('what can i do for you')
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command=command.lower()
if 'alexa' in command:
command=command.replace('alexa','') # in this line we are removing word alexa from the string
print(command)
except:
pass
return command
def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing' + song)
# talk('playing' + song)
print('playing...')
pywhatkit.playonyt(song)
elif 'time' in command:
time=datetime.datetime.now().strftime('%I:%M %p') #it is converting 24 hour clock
print(time)
talk('current time is' + time)
elif 'who is' in command:
person=command.replace('who is','')
information=wikipedia.summary(person,4) #this 4 is telling us the number of lines we want alexa to read
print(information)
talk(information)
elif 'language' in command:
talk('I speak English language')
elif 'where do you live' in command:
talk('I live inside your machine')
elif 'sleep' in command:
talk('I hope you had a good day! good night. sweet dreams. see you tommorow')
elif 'joke' in command:
print(pyjokes.get_joke())
talk(pyjokes.get_joke())
elif 'date' in command:
talk('yes! but you will have to come inside your machine to meet me! haha')
else:
talk('Sorry! Can you please repeat?')
while True:
run_alexa()