Created
August 5, 2017 12:28
-
-
Save 0x48piraj/d07bd7609ceb6739e507c4a8c5902c6d to your computer and use it in GitHub Desktop.
A simple wit.ai script modification asked at Quora [https://www.quora.com/How-do-I-use-speech-to-answer-input-in-Python]
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
https://www.quora.com/How-do-I-use-speech-to-answer-input-in-Python | |
import speech_recognition as sr | |
import webbrowser | |
import os | |
# obtain audio from the microphone | |
r = sr.Recognizer() | |
def confirmSpeech(command): | |
response = input("Did you say " + command + "?") | |
if response == == "Yes" or "yes" or "Yes!" or "yes!" : #add more itteration(s) if you want to ! | |
#Do whatever ! command is correct !! Yay !! | |
#elif : #you can use for a "No", or "Oops! Didn't catch that command !" | |
# recognize speech using http://Wit.ai | |
WIT_AI_KEY = "apiHere" | |
while True: | |
print("Say something!") | |
with sr.Microphone() as source: audio = r.listen(source) #seems new ? Learn ! | |
print("Got it! Now to recognize it...") | |
try: | |
command = r.recognize_wit(audio, key=WIT_AI_KEY) | |
confirmSpeech(command) | |
except sr.UnknownValueError: | |
print("Wit.ai could not understand audio") | |
except sr.RequestError as e: | |
print("Could not request results from Wit.ai service; {0}".format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment