def GetText(audio): r = sr.Recognizer() try: # for testing purposes, we're just using the default API key # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")` # instead of `r.recognize_google(audio)` # r.recognize_google( # audio, # key="ya29.Ci-MA2OjZ4mBUqZS6RGtf3i8gUv0M_oLoc15xLHcf5xjbYLTjV0ZykDRYCfsukVEuQ") text = "" text = r.recognize_google(audio) if text != "": GUI.UpdateGuiSpeed(True) #------------------------------------------------------------------------- GUI.UpdateGui(text) print("Text: " + text) except sr.UnknownValueError: GUI.UpdateGuiSpeed(False) print("Engine could not process the speech") except sr.RequestError as e: GUI.UpdateGuiSpeed(False) print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) return text
def RunCommand(com): c = com[0] v = com[1] if c == "search": webhandler.GoogleSearch(v) elif c == "url": webhandler.OpenURL(v) elif c == "app": applicationhandler.OpenApp(v) elif c == "mouseMove": filename = ".screenshot.png" t = GUI.v.get() GUI.UpdateGui("") img = ocrhandler.GetScreenShot(filename) GUI.UpdateGui(t) s = ocrhandler.LocateText(img, v, filename) print s if s: if len(s) == 1: mousehandler.Move(s[0][0], s[0][1]) else: for x in s: mousehandler.Move(x[0], x[1]) if GetConfirmation(): break else: print "\nNOT FOUND\n" VoiceOutput.Say("Sorry, I'm not able to do that") elif c == "mouseClick": mousehandler.Click() elif c == "mouseDoubleClick": mousehandler.DoubleClick() elif c == "mouseScroll": t = 1 if v == "up": t = -1 mousehandler.Scroll(t) elif c == "keyboardType": keyboardhandler.TypeText(v) elif c == "keyboardHold": keyboardhandler.HoldKey(v) elif c == "keyboardRelease": keyboardhandler.ReleaseKey(v) elif c == "music": keyboardhandler.PlayMusic()