Answer the question
In order to leave comments, you need to log in
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
Interface change started
Interface change finished
Voice recognition started
Voice recognition finished
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
Interface change started
Button_1 = wx.Button(self)
self.Bind(wx.EVT_BUTTON, self.eventFunc, Button_1)
config.Button_2.Destroy()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question