I have a UI program that records audio from microphone and speakers with a loop in another thread that writes to file what is recorded, everything goes well until I try to close the GUI, but the thread doesn't stop, as Sublime doesnt show '[Finished in Xs.]'. The thread stops when I click the button 'Stop' tho. This is the main code on the problem:
thread = Thread(target=self.record_and_recognize, args=(args, callback))
thread.start()
def record_and_recognize(self, args, callback_func):
self.labeltext.set('Recording...')
with sf.SoundFile(args.filename, mode='w', samplerate=args.samplerate,
channels=args.channels, subtype=args.subtype) as file:
with sd.InputStream(samplerate=args.samplerate, device=args.device,
channels=args.channels, callback=callback_func):
# Thread loop that writes sound to file until stopped
while self.recording:
file.write(self.progression.get())
What can I do?