Last active
November 26, 2016 01:08
-
-
Save maipatana/17eff765ae2dad68f180f52d46a32b41 to your computer and use it in GitHub Desktop.
Example Python SpeechRecognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import speech_recognition as sr | |
# Record Audio | |
r = sr.Recognizer() | |
m = sr.Microphone() | |
#set threhold level | |
with m as source: r.adjust_for_ambient_noise(source) | |
print("Set minimum energy threshold to {}".format(r.energy_threshold)) | |
# Speech recognition using Google Speech Recognition | |
def checkspeech(r): | |
with sr.Microphone() as source: | |
audio = r.listen(source) | |
try: | |
# for testing purposes, we're just using the default API key | |
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")` | |
# instead of `r.recognize_google(audio)` | |
print("You said: " + r.recognize_google(audio)) | |
return (r.recognize_google(audio)) | |
except sr.UnknownValueError: | |
print("Google Speech Recognition could not understand audio") | |
return ("WW") | |
except sr.RequestError as e: | |
print("Could not request results from Google Speech Recognition service; {0}".format(e)) | |
return ("WW") | |
speech = str(checkspeech(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment