-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoiceb.py
59 lines (49 loc) · 1.74 KB
/
voiceb.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
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_instruction():
global instruction
try:
with aa.Microphone() as origin:
print("listening")
speech = listener.listen(origin)
instruction = listener.recognize_google(speech) # Fix: Changed recognize_goggle to recognize_google
instruction = instruction.lower()
if "dude" in instruction:
instruction = instruction.replace('dude', ' ') # Fix: Typo in variable name
print(instruction)
except:
pass
return instruction
def play_dude():
instruction = input_instruction()
print(instruction)
if "play" in instruction:
song = instruction.replace('play', "")
talk("playing " + song)
pywhatkit.playonyt(song) # Fix: Changed playsong to playonyt
elif 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p') # Fix: Added space before %p for proper formatting
talk('Current time is ' + time)
elif 'date' in instruction:
date = datetime.datetime.now().strftime('%d/%m/%Y') # Fix: Removed spaces before and after '/'
talk("Today's date is " + date)
elif 'how are you' in instruction:
talk('I am fine, how about you?')
elif 'what is your name' in instruction:
talk('I am dude. What can I do for you?')
elif 'who is' in instruction:
human = instruction.replace('who is', " ")
info = wikipedia.summary(human, 1)
print(info)
talk(info)
else:
talk('Please repeat')
play_dude()