Last active
June 15, 2016 16:26
-
-
Save porthunt/e6b2ba7deaf2bd43ca6a06e4b57e40c1 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
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