-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech_recog.py
executable file
·36 lines (29 loc) · 1.08 KB
/
speech_recog.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
#! /usr/bin/python -tt
import os
import speech_recognition as sr
def main():
print "hello starting the program now!"
re = sr.Recognizer()
with sr.Microphone() as source:
print 'Say something buddy:'
audio = re.listen(source)
# try to recognize using google
# try:
# APIkey = os.environ["key"]
# print APIkey
# print 'Google thinks that you said: ', re.recognize_google(audio, APIkey)
# print 'google thinks that you said: ', re.recognize_google(audio)
# except sr.UnknownValueError:
# print "Google did not understand what you just said"
# except sr.RequestError as e:
# print "Could not request result from Google's speech recognition API", format(e)
# try to recognize using bing
BING_KEY = os.environ["bing_key"]
try:
print 'Bing speech recognition thinks you said:', re.recognize_bing(audio, key=BING_KEY)
except sr.UnknownValueError:
print "Bing did not understand what you just said"
except sr.RequestError as e:
print "Could not request result from Bing's speech recognition API", format(e)
if __name__ == '__main__':
main()