-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
46 lines (38 loc) · 1.21 KB
/
test.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
import string
import speech_recognition as sr
#import nltk
#nltk.download()
'''
r=sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source) # adjusting for ambient noise
print("say something")
audio=r.listen(source)
#stop=r.listen_in_background(m,callback) # theoretically would start a background listener
try:
print("Google thinks you said: "+r.recognize_google(audio))
except sr.UnknownValueError:
print("couldnt recognize your audio")
except sr.RequestError as e:
print("couldnt get results from google; {0}".format(e))
if r.recognize_google(audio)=="hello":
print("HI BRIAN")
elif r.recognize_google(audio)=="show me the time":
#return time
pass
'''
import speech_recognition as sr
def recognizeSpeech():
r=sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio=r.listen(source)
try:
recognized=r.recognize_google(audio)
except sr.UnknownValueError:
print("couldnt recognize your audio")
except sr.RequestError as e:
print("couldnt get results from google; {0}".format(e))
if recognized=="show weather":
print("change mode to weather")
recognizeSpeech()