0

I want pyttsx3 and tkinter-text go synchronically. I mean, I want to see what I told in a text like the subtitles However I could not manage that. It is possible when it is not in a while loop.... but when I use it in while loop it shows the the whole dialogue after the speech is done. Do you guys have any idea how to make them go synchronically when in a while loop? Thank you for your help.

       with sr.Microphone() as source:
            while True:
                r.adjust_for_ambient_noise(source, duration=1)

                voice = r.listen(source)
                text_punk = r.recognize_google(voice, language="en-US")
                text_punk = text_punk.lower()
                punk_screen = "You---> " + text_punk
                txt.insert(END, "\n" + punk_screen)

                

                if text_punk != '':
                    test=testpy.Testing()
                    res = test.response(text_punk)
                    txt.insert(END, "\n" + 'Bot---> ' + res)
                    talk(res)
Ozzz
  • 29
  • 5
  • 1
    Since running a while loop in your tkinter application loop will freeze your application, you need to use python's [threading](https://docs.python.org/3/library/threading.html) module or multiprocessing module to run the tasks in separate threads or processes. – Billy Apr 30 '22 at 15:34
  • thanks for the answer, threading solved the problem. – Ozzz Apr 30 '22 at 20:38

0 Answers0