-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGOBOT.py
72 lines (59 loc) · 1.85 KB
/
GOBOT.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
import speech_recognition as speech
import pyjokes
import pyttsx3
import pywhatkit
import datetime
import wikipedia
listener = speech.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
#using default version of voice (male voice) :
#You can change this voice to a female voice by using
#this code:
#engine.setProperty('voice', voices[0].id)
engine.say('Hello Sunshine ')
engine.say('Myself Go-Bot')
engine.say('Any command?')
engine.runAndWait()
def communicate(txt):
engine.say(txt)
engine.runAndWait()
def commanding():
try :
with speech.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
#If you want to only print command
# when you say go-bot in your txt, here is one line code
#if 'Go-Bot' in command:
print(command)
communicate(command)
except:
pass
return command
def gobot_run():
command = commanding()
print(command )
if 'play' in command:
song = command.replace('play', '')
communicate('playing' + song)
pywhatkit.playonyt(song)
elif 'time' in command :
time = datetime.datetime.now().strftime('%H : %M')
#time = datetime.datetime.now().strftime('%I : %M %p')
#Output of time is in AM/PM form
communicate('Current time is ' + time)
elif 'tell me about' in command:
person = command.replace('tell me about', '')
info = wikipedia.summary(person, 1)
print(info)
communicate(info)
elif 'joke' in command:
communicate(pyjokes.get_joke())
else:
communicate('Please say the command again.')
while True :
gobot_run()