I'm trying to build a Tkinter GUI that is sort of like a personal assistant, however I've fallen at the fist hurdle :( When I update the GUI and listen with speech_recognition, it freezes and says not responding! I understand that I need to use multi threading however I'm stuck on how to use it!
Here's my code and my failed attempt at using multi-threading.
import tkinter as tk
from subprocess import call as say
import winsound
import speech_recognition as sr
import threading
def cbc(tex):
return lambda : callback(tex)
def callback(tex):
button = "Listen"
tex.insert(tk.END, button)
tex.see(tk.END)# Scroll if necessary
def listen(tex):
def callback(tex):
g = ("Say,,your,,command,,after,,the,,beep")
say('espeak '+ g, shell = True)
winsound.Beep(1000,500)
ltext = 'listening...'
tex.insert(tk.END, ltext)
r = sr.Recognizer()
with sr.Microphone() as source:
damand = r.listen(source)
damandtxt = (recognizer_google(damand))
tex.insert(tk5.END, damandtxt)
tex.see(tk.END)
t3 = threading.Thread(target = callback(tex))
t3.daemon = True
t3.start()
top = tk.Tk()
tex = tk.Text(master=top)
tex.pack(side=tk.RIGHT)
bop = tk.Frame()
bop.pack(side=tk.LEFT)
tk.Button(bop, text='Listen', command=lambda: listen(tex)).pack()
tk.Button(bop, text='Exit', command=top.destroy).pack()
top.mainloop()
I just need to know how to use it correctly. Please
p.s I've read all the documentation and everything on multi-threading but it just doesn't work :'(
Thank you in advance :)