I'm writing a program were you can talk to it and it responds like siri. I'm using Googles speech recognition and espeak
to listen and talk. the conversation is then printed to a text box.
When ever the program is asked to listen using speech recognition it freezes and clicking on the GUI again then it says 'not responding', am I running this wrong or is it just impossible to run speech recognition in tkinter
?
Why is it freezing?
Here's the whole code that I've written so far:
import tkinter as tk
from subprocess import call as say
import winsound
import speech_recognition as sr
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):
say('espeak '+"Say,,your,,command,,after,,the,,beep", shell=True)
winsound.Beep(1000,500)
ltext = 'listening...'
tex.insert(tk.END, ltext)
tex.see(tk.END)
r = sr.Recognizer()
with sr.Microphone() as source:
damand = r.listen(source)
damandtxt = (recognizer_google(damand))
tex.insert(tk.END, damandtxt)
tex.see(tk.END)
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()