0

I am actually the member of NLI(Novitatis Locus Industries) and our team seems to get some issues. While designing a voice enabled program with GUI, tkinter's mainloop seems to be giving us some issues. See our code-

//this function defines the gui//
def gui():
gui_kurooto = Tk()
txt_dsply_var = StringVar()
AUTHN_LBL = Label(gui_kurooto, text=txt_dsply_var)
AUTHN_LBL.pack()
gui_kurooto.mainloop()

//this code defines the microphone input// 
def takeCommand():
#It takes microphone input from the user and returns string output
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Listening...")
    txt_dsply_var = StringVar()
    txt_dsply_var.set('Listening')//display listening on gui//

    r.pause_threshold = 1
    r.energy_threshold = 10000
    audio = r.listen(source)
try:
    print("Recognizing...")
    txt_dsply_var = StringVar()
    txt_dsply_var.set('Recognizing')//display recognizing//

    query = r.recognize_google(audio, language='en-en')
    print(f"User said: {query}\n")
    txt_dsply_var = StringVar()
    txt_dsply_var.set(f"User said: {query}\n")//display input//
except Exception as e:
    # print(e)
    print("Say that again please...")
    return "None"
return query

//to run//
if __name__ == "__main__":
gui()
    while True:
# if 1:
    query = takeCommand().lower()

Now when I try to run this, the code never reaches the while loop. I know the mainloop is an infinite loop but is there a substitute present their so I can let it reach other functions. Keeping the function out of function also dosen't work. Can I place it after the query command?

Also I have other question, is there a way by which I can spectra according to the voice input like Google and Siri have bars which move when we speak?

Any help would be appreciated.

  • 2
    Read [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop), [use threads to preventing main event loop from “freezing”](https://stackoverflow.com/a/16747734/7414759) and [While Loop Locks Application](https://stackoverflow.com/questions/28639228/python-while-loop-locks-application) – stovfl Jan 02 '20 at 13:17
  • Thanks, I apologize for being too late but yes reading these articles worked, I would like to thank you a lot – Novitatis Locus Industries Feb 27 '20 at 15:17
  • Adding the your_window_name.upateidletasks() and your_window_name.upate() worked by inserting them into the function instead on mainloop() before the while loop. Thanks. – Novitatis Locus Industries Feb 27 '20 at 15:19

0 Answers0