-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoiceassitent.py
More file actions
67 lines (52 loc) · 1.88 KB
/
voiceassitent.py
File metadata and controls
67 lines (52 loc) · 1.88 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
import speech_recognition as aa
import pyttsx3
import pywhatkit
import datetime
import wikipedia
listener = aa.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def input_instraction():
try:
with aa.Microphone() as origin:
print("listening...")
speech = listener.listen(origin)
instraction = listener.recognize_google(speech)
instraction = instraction.lower()
if "lala" in instraction:
instraction = instraction.replace('lala', "")
print(instraction)
return instraction
except:
return None
def play_lala():
instraction = input_instraction()
if instraction:
print(instraction)
if "play" in instraction:
song = instraction.replace("play", "")
talk("playing " + song)
pywhatkit.playonyt(song)
elif 'time' in instraction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time: ' + time)
elif 'date' in instraction:
date = datetime.datetime.now().strftime('%d/%m/%Y')
talk("Today's date: " + date)
elif 'how are you' in instraction:
talk('I am fine, how about you?')
elif 'what is your name' in instraction:
talk('I am Lala, what can I do for you?')
elif 'who is' in instraction:
human = instraction.replace('who is', "")
info = wikipedia.summary(human, 1)
print(info)
talk(info)
else:
talk('Please repeat.')
else:
print("No instruction received, please try again.")
while True:
play_lala()