Created
December 2, 2014 02:26
-
-
Save sakamer71/13d8983bf78133ac0c40 to your computer and use it in GitHub Desktop.
speech recognition
This file contains hidden or 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
__author__ = 'skamer' | |
import speech_recognition as sr | |
from os import system | |
r = sr.Recognizer() | |
def talk(x): | |
phrase = "say -v samantha \"{}\"".format(x) | |
return system(phrase) | |
def listen(x): | |
output = '' | |
while not output: | |
with sr.Microphone() as source: | |
audio = r.listen(source) | |
try: | |
output = r.recognize(audio) | |
return output | |
except LookupError: | |
talk("I didn't catch that, try again") | |
talk(x) | |
# recognize speech using Google Speech Recognition | |
getname = "Good morning, what is your name?" | |
talk(getname) | |
name = listen(getname) | |
getbreakfast = "Hi {}, what would you like for breakfast\?".format(name) | |
talk(getbreakfast) | |
breakfast = listen(getbreakfast) | |
accept = "Well {}, I don't have {}, but how would you like some fried monkey brains instead\?".format(name,breakfast) | |
talk(accept) | |
choice = listen(accept) | |
choice = choice.split() | |
for word in choice: | |
if word in ['sure', 'ok', 'fine','yes','alright']: | |
talk("Great, monkey brains it is\!") | |
exit() | |
else: | |
talk("Too bad, I make a mean monkey brains. If you insist on {}, you are on your own\!".format(breakfast)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment