-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled-coach.py
143 lines (106 loc) · 3.76 KB
/
led-coach.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from gtts import gTTS
import pyttsx3
import webbrowser
import smtplib
import random
import speech_recognition as sr
import wikipedia
import datetime
import wolframalpha
import os
import sys
engine = pyttsx3.init()
client = wolframalpha.Client('Your WolframAlpha ID')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[len(voices)-2].id)
def speak(audio):
print('Computer: ' + audio)
engine.say(audio)
engine.runAndWait()
def greetMe():
currentH = int(datetime.datetime.now().hour)
if currentH >= 0 and currentH < 12:
speak('Good Morning!')
if currentH >= 12 and currentH < 18:
speak('Good Afternoon!')
if currentH >= 18 and currentH !=0:
speak('Good Evening!')
greetMe()
speak('Hello, I am your digital assistant LED coach')
speak('How may I assist you?')
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-uk')
print('User: ' + query + '\n')
except sr.UnknownValueError:
speak('Sorry I didn\'t get that! Try typing the command!')
query = str(input('Command: '))
return query
if __name__ == '__main__':
while True:
query = myCommand();
query = query.lower()
if 'open youtube' in query:
speak('okay')
webbrowser.open('www.youtube.com')
elif 'open google' in query:
speak('okay')
webbrowser.open('www.google.com')
elif 'open gmail' in query:
speak('okay')
webbrowser.open('www.gmail.com')
elif "what\'s up" in query or 'how are you' in query:
stMsgs = ['Just doing my job!', 'I am good!', 'Sweet!', 'I feeling great today!']
speak(random.choice(stMsgs))
elif 'email' in query:
speak('Who is the recipient? ')
recipient = myCommand()
if 'me' in recipient:
try:
speak('What should I write? ')
content = myCommand()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("username", 'password')
server.sendmail('user email address', "Recipient_Username", content)
server.close()
speak('Email has been sent!')
except:
speak('Sorry Sir I am unable to send your message at this time!')
elif 'nothing' in query or 'abort' in query or 'stop' in query:
speak('okay')
speak('Bye, have a good day.')
sys.exit()
elif 'hello' in query:
speak('Hello')
elif 'bye' in query:
speak('Goodbye, have a good day.')
sys.exit()
elif 'play music' in query:
music_folder = Your_music_folder_path
music = [music1, music2, music3, music4, music5]
random_music = music_folder + random.choice(music) + '.mp3'
os.system(random_music)
speak('Okay, here is your music! Enjoy!')
else:
query = query
speak('Searching...')
try:
try:
res = client.query(query)
results = next(res.results).text
speak('Here you go.')
speak(results)
except:
results = wikipedia.summary(query, sentences=2)
speak('Here you go.')
speak(results)
except:
webbrowser.open('www.google.com')
speak('Next Command!')