-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code of VIRTUAL ASSISTANT
102 lines (48 loc) · 1.45 KB
/
Code of VIRTUAL ASSISTANT
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
import speech_recognition as sr
import pyttsx3
import datetime
import pywhatkit
import wikipedia
import pyjokes
listener = sr.Recognizer()
alexa = pyttsx3.init()
voices = alexa.getProperty('voices')
alexa.setProperty('voice',voices[1].id)
def talk(text):
alexa.say(text)
alexa.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:
print(command)
except:
pass
return command
def run_alexa():
command = take_command()
if 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
talk('current time is' + time)
elif 'play' in command:
song = command.replace('play', '')
talk('playing ' +song)
pywhatkit.playonyt(song)
elif 'tell me about' in command:
look_for = command.replace('tell me about', '')
info = wikipedia.summary(look_for, 1)
talk(info)
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'date' in command:
talk('yes i want to go with you in a date')
else:
talk('please say it again i cannot understand')
pywhatkit.search(command)
while True:
run_alexa()