L
L
lessstreng2019-07-09 01:49:01
Google
lessstreng, 2019-07-09 01:49:01

Does speech recognition occur before -standing commands?

I have been struggling with a problem for several days: using speech_recognition from google, the command to record and output what the user said, now the On_VoiceAssistent function, is executed before the command to create and delete a button, now the On_Assistent function. Tried to resolve it in different ways. Below, for example, before creating-destroying buttons, I set the value of the checking variable to False, after - True, but this also does not work. Please help with ideas.

def On_VoiceAssistent(self):
        try:
            while config.Check_On_VoiceAssistent == True:

                r = sr.Recognizer()
                with sr.Microphone(device_index=1) as sourse:
                    audio = r.listen(sourse)
                query = r.recognize_google(audio, language="ru-RU")
                print(query.lower())
                print(query)
        except sr.UnknownValueError:
            print ("ne ponyal")
            self.On_VoiceAssistent()

 def On_Assistent(self, event):
        config.Check_On_VoiceAssistent = False

        config.Btn_Off_Assistent = wx.Button(self, -1, label="Выключить")
        self.Bind(wx.EVT_BUTTON, self.Off_Assistent, config.Btn_Off_Assistent)

        config.Btn_On_Assistent.Destroy()

        config.Check_On_VoiceAssistent = True

        if config.Check_On_VoiceAssistent == True: self.On_VoiceAssistent()

Other view:
def On_Assistent(self, event):
        config.Btn_Off_Assistent = wx.Button(self, -1, label="Выключить")
        self.Bind(wx.EVT_BUTTON, self.Off_Assistent, config.Btn_Off_Assistent)

        config.Btn_On_Assistent.Destroy()

        config.Check_On_VoiceAssistent = True

        try:
            while config.Check_On_VoiceAssistent == True:

                r = sr.Recognizer()
                with sr.Microphone(device_index=1) as sourse:
                    audio = r.listen(sourse)
                query = r.recognize_google(audio, language="ru-RU")
                print(query.lower())
                print(query)
        except sr.UnknownValueError:
            print ("ne ponyal")
            self.On_VoiceAssistent()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question