Skip to content

Commit

Permalink
Better error checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Uberi committed Oct 2, 2015
1 parent 269e483 commit 8373e9a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions examples/background_listening.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def callback(recognizer, audio):
print("Google Speech Recognition thinks you said " + recognizer.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError:
print("Could not request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

r = sr.Recognizer()
m = sr.Microphone()
Expand Down
4 changes: 2 additions & 2 deletions examples/calibrate_energy_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError:
print("Could not request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
16 changes: 8 additions & 8 deletions examples/extended_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
pprint(r.recognize_google(audio, show_all=True)) # pretty-print the recognition result
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError:
print("Could not request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

# recognize speech using Wit.ai
WIT_AI_KEY = "INSERT WIT.AI API KEY HERE" # Wit.ai keys are 32-character uppercase alphanumeric strings
Expand All @@ -32,8 +32,8 @@
pprint(r.recognize_wit(audio, key=WIT_AI_KEY, show_all=True)) # pretty-print the recognition result
except sr.UnknownValueError:
print("Wit.ai could not understand audio")
except sr.RequestError:
print("Could not request results from Wit.ai service")
except sr.RequestError as e:
print("Could not request results from Wit.ai service; {0}".format(e))

# recognize speech using IBM Speech to Text
IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Expand All @@ -44,8 +44,8 @@
pprint(r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD, show_all=True)) # pretty-print the recognition result
except sr.UnknownValueError:
print("IBM Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from IBM Speech to Text service")
except sr.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))

# recognize speech using AT&T Speech to Text
ATT_APP_KEY = "INSERT AT&T SPEECH TO TEXT APP KEY HERE" # AT&T Speech to Text app keys are 32-character lowercase alphanumeric strings
Expand All @@ -54,5 +54,5 @@
print("AT&T Speech to Text thinks you said " + r.recognize_att(audio, app_key=ATT_APP_KEY, app_secret=ATT_APP_SECRET))
except sr.UnknownValueError:
print("AT&T Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from AT&T Speech to Text service")
except sr.RequestError as e:
print("Could not request results from AT&T Speech to Text service; {0}".format(e))
16 changes: 8 additions & 8 deletions examples/microphone_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError:
print("Could not request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

# recognize speech using Wit.ai
WIT_AI_KEY = "INSERT WIT.AI API KEY HERE" # Wit.ai keys are 32-character uppercase alphanumeric strings
try:
print("Wit.ai thinks you said " + r.recognize_wit(audio, key=WIT_AI_KEY))
except sr.UnknownValueError:
print("Wit.ai could not understand audio")
except sr.RequestError:
print("Could not request results from Wit.ai service")
except sr.RequestError as e:
print("Could not request results from Wit.ai service; {0}".format(e))

# recognize speech using IBM Speech to Text
IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Expand All @@ -37,8 +37,8 @@
print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
except sr.UnknownValueError:
print("IBM Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from IBM Speech to Text service")
except sr.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))

# recognize speech using AT&T Speech to Text
ATT_APP_KEY = "INSERT AT&T SPEECH TO TEXT APP KEY HERE" # AT&T Speech to Text app keys are 32-character lowercase alphanumeric strings
Expand All @@ -47,5 +47,5 @@
print("AT&T Speech to Text thinks you said " + r.recognize_att(audio, app_key=ATT_APP_KEY, app_secret=ATT_APP_SECRET))
except sr.UnknownValueError:
print("AT&T Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from AT&T Speech to Text service")
except sr.RequestError as e:
print("Could not request results from AT&T Speech to Text service; {0}".format(e))
16 changes: 8 additions & 8 deletions examples/wav_transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError:
print("Could not request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

# recognize speech using Wit.ai
WIT_AI_KEY = "INSERT WIT.AI API KEY HERE" # Wit.ai keys are 32-character uppercase alphanumeric strings
try:
print("Wit.ai thinks you said " + r.recognize_wit(audio, key=WIT_AI_KEY))
except sr.UnknownValueError:
print("Wit.ai could not understand audio")
except sr.RequestError:
print("Could not request results from Wit.ai service")
except sr.RequestError as e:
print("Could not request results from Wit.ai service; {0}".format(e))

# recognize speech using IBM Speech to Text
IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Expand All @@ -38,8 +38,8 @@
print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
except sr.UnknownValueError:
print("IBM Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from IBM Speech to Text service")
except sr.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))

# recognize speech using AT&T Speech to Text
ATT_APP_KEY = "INSERT AT&T SPEECH TO TEXT APP KEY HERE" # AT&T Speech to Text app keys are 32-character lowercase alphanumeric strings
Expand All @@ -48,5 +48,5 @@
print("AT&T Speech to Text thinks you said " + r.recognize_att(audio, app_key=ATT_APP_KEY, app_secret=ATT_APP_SECRET))
except sr.UnknownValueError:
print("AT&T Speech to Text could not understand audio")
except sr.RequestError:
print("Could not request results from AT&T Speech to Text service")
except sr.RequestError as e:
print("Could not request results from AT&T Speech to Text service; {0}".format(e))
4 changes: 2 additions & 2 deletions speech_recognition/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
print("You said {}".format(value))
except sr.UnknownValueError:
print("Oops! Didn't catch that")
except sr.RequestError:
print("Uh oh! Couldn't request results from Google Speech Recognition service")
except sr.RequestError as e:
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))
except KeyboardInterrupt:
pass

0 comments on commit 8373e9a

Please sign in to comment.