F
F
freakssha2019-12-12 23:49:22
Python
freakssha, 2019-12-12 23:49:22

How to perform actions with widgets and then perform speech recognition using concurrent.futures.thread?

The goal is to first perform widget actions (create Button_1 and delete Button_2), then enable speech recognition.
I'm using the concurrent.futures.thread module, which did a great job of creating the asynchronous code needed to perform some tasks before implementing speech recognition.
In this attempt, the compiler goes through each line - this is indicated by the output of lines marked with '#for test' comments. Problem: Buttons are not created or deleted, but speech recognition works:

def someFunc(self, event):
        print('Interface change started') #for test
        #creates Button_1
        #deletes config.Button_2 (from another func)
        print('Interface change finished') #for test

        with ThreadPoolExecutor(max_workers=5) as executor:
            fut = executor.submit(self.voiceRecognition)
            fut.result()

    def voiceRecognition (self):
        print('Voice recognition was started') #for test
        r = sr.Recognizer()
        with sr.Microphone(device_index=1) as sourse:
            audio = r.listen(sourse)
            query = r.recognize_google(audio) 
            print(query.lower())
       print('Voice recognition was finished') #for test

Output :
Interface change started
Interface change finished
Voice recognition started
Voice recognition finished

I tried to make a separate function 'ProcessCallManagement' and wrap actions with buttons in a separate function ' interfaceChanges ', but ... Problem : neither actions with buttons nor speech recognition are performed:
def processCallManagement(self, event):
        with ThreadPoolExecutor(max_workers=5) as executor:
            fut1 = executor.submit(self.interfaceChanges)
            fut1.result()
        
            fut2 = executor.submit(self.voiceRecognition)
            fut2.result()

    def interfaceChanges(self):
        print('Interface change started') #for test
        #creates Button_1
        #deletes config.Button_2 (from another func)
        print('Interface change finished') #for test

    def voiceRecognition(self):
        print('Voice recognition was started') #for test
        r = sr.Recognizer()
        with sr.Microphone(device_index=1) as sourse:
            audio = r.listen(sourse)
            query = r.recognize_google(audio)
            print(query.lower())
       print('Voice recognition was finished') #for test

Output data:
Interface change started
Here is how and what with the buttons specifically (separately from the context they work , and they work fine):
Button_1 = wx.Button(self)
        self.Bind(wx.EVT_BUTTON, self.eventFunc, Button_1)
        config.Button_2.Destroy()

Help to understand the causes of problems and their practical solution, if possible using the concurrent.futures.thread module. If possible, of course. Thank you.

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