-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj2.py
More file actions
78 lines (64 loc) · 2.01 KB
/
j2.py
File metadata and controls
78 lines (64 loc) · 2.01 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
68
69
70
71
72
73
74
75
76
77
78
from gtts import gTTS
import speech_recognition as sr
import os
import re
import webbrowser
import smtplib
import requests
def talkToMe(audio):
"speaks audio passed as argument"
print(audio)
for line in audio.splitlines():
os.system("say " + audio)
def myCommand():
"listens for commands"
r = sr.Recognizer()
with sr.Microphone() as source:
print('Ready...')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
command = r.recognize_google(audio).lower()
print('You said: ' + command + '\n')
#loop back to continue to listen for commands if unrecognizable speech is received
except sr.UnknownValueError:
print('Your last command couldn\'t be heard')
command = myCommand();
return command
def assistant(command):
"if statements for executing commands"
if 'open reddit' in command:
reg_ex = re.search('open reddit (.*)', command)
url = 'https://www.reddit.com/'
if reg_ex:
sub = reg_ex.group(1)
url = url + 'r/' + sub
webbrowser.open(url)
print('Done!')
if 'open youtube' in command:
reg_ex = re.search('open youtube (.*)', command)
url = 'https://www.youtube.com/'
if reg_ex:
sub = reg_ex.group(1)
url = url + 'r/' + sub
webbrowser.open(url)
print('Done!')
if 'open gmail' in command:
reg_ex = re.search('open gmail (.*)', command)
url = 'https://www.gmail.com/'
if reg_ex:
sub = reg_ex.group(1)
url = url + 'r/' + su
webbrowser.open(url)
print('Done!')
elif 'what\'s up' in command:
talkToMe('Just doing my thing')
elif 'Hii, how are you' in command:
talkToMe('I am great , how are you')
elif "What's your name" in command:
talkToMe('My name is Erica')
#loop to continue executing multiple commands
while True:
assistant(myCommand())
`