Skip to content

Instantly share code, notes, and snippets.

@femoru
Created April 23, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save femoru/0b70d6cccce0b8de7ad0a15de6833a9b to your computer and use it in GitHub Desktop.
Save femoru/0b70d6cccce0b8de7ad0a15de6833a9b to your computer and use it in GitHub Desktop.
##############################################
# 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