示例#1
0
    def online_recognition(self):
        r=self.r
        speak(random.choice(self.randomresp))
        try:
            with sr.Microphone() as source:
                audi1 = r.adjust_for_ambient_noise(source)
                print "----------Listening-------"
                audi1 = r.listen(source)
                print "----------Recognizing-------"
                try:
                    data=r.recognize_google(audi1,key=GOOGLE_API_KEY,language="en-US",show_all=False)
                    voice_queue.put(data.lower())
                    return True
                except IndexError:
                    # the API key didn't work
                    speak("I am sorry sir, could not connect to the internet")
                    print("No internet connection")
                except KeyError:
                    speak("I am afraid,your API key is invalid")
                    print("Invalid API key or quota maxed out")
                except LookupError:
                    print("Could not understand audio")
                except sr.UnknownValueError:
                    pass

        except KeyboardInterrupt:
            sys.exit(0)
示例#2
0
 def get_entry(self):
     voice_queue.put(self.entryVar.get().lower())