Created
April 23, 2019 22:03
-
-
Save femoru/0b70d6cccce0b8de7ad0a15de6833a9b to your computer and use it in GitHub Desktop.
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
############################################## | |
# Instalar las dependencias | |
# pip install pyaudio | |
# pip install SpeechRecognition | |
############################################## | |
import speech_recognition as sr | |
# Record Audio | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
r.adjust_for_ambient_noise(source, duration=1) | |
print("Say something!") | |
audio = r.listen(source,phrase_time_limit=5) | |
# Speech recognition using Google Speech Recognition | |
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)` | |
response = r.recognize_google(audio) | |
print("I think you said '" + response + "'") | |
except sr.UnknownValueError: | |
print("Google Speech Recognition could not understand audio") | |
except sr.RequestError as e: | |
print("Could not request results from Google Speech Recognition service; {0}".format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment