Skip to content

Instantly share code, notes, and snippets.

@porthunt
Last active June 15, 2016 16:26
Show Gist options
  • Save porthunt/e6b2ba7deaf2bd43ca6a06e4b57e40c1 to your computer and use it in GitHub Desktop.
Save porthunt/e6b2ba7deaf2bd43ca6a06e4b57e40c1 to your computer and use it in GitHub Desktop.
import speech_recognition as sr
'''
Installation:
pip install SpeechRecognition
On OSX: brew install portaudio && brew link portaudio
pip install pyaudio
Check for more info: https://pypi.python.org/pypi/SpeechRecognition/
How to Use:
> speech = listen('en-US') # or any other ISO639-1 language
> print(speech) # prints what you said
> parse(speech) # splits every word that you said, gives you a list
'''
def listen(language):
record = sr.Recognizer()
with sr.Microphone() as source:
audio = record.listen(source)
try:
speech = record.recognize_google(audio, language=language)
return speech
except sr.UnknownValueError:
print("Could not understand what you said")
except sr.RequestError as e:
print("Could not request results from Recognition service; {0}"
.format(e))
def parse(speech):
return speech.split()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment