How can i make the python to wait till i complete speaking? -
i writing program recognise speech microphone , code process accordingly. code wrote purpose below.
import speech_recognition sr import webbrowser import pyttsx time import sleep engine = pyttsx.init() engine.setproperty('rate', 70) r = sr.recognizer() def recognize(audio): try: return r.recognize(audio) except lookuperror, e: print e return '' sr.microphone() source: while true: engine.say("hi how can ?") sleep(0.15) print "start speaking" audio = r.listen(source) words = recognize(audio) print("you said " + words) if words == "facebook": engine.say("shall open facebook page ?") engine.runandwait() audio = r.listen(source) words = recognize(audio) if words == "yes": webbrowser.open('https://www.facebook.com') elif words == "stop": break
here tried sleep before engine speaks can see text start speaking getting printed. instead of sleep, there nice way capture speech in microphone , wait till or long silence?
this method:
engine.runandwait()
waits speech complete. need use not after engine.say("shall open facebook page ?")
, after engine.say("hi how can ?")
instead of sleep
Comments
Post a Comment