0

So I have been testing pyttsx3 but when I try to bind it with a key such as below, It says works once then crashes the GUI. Any idea how to solve this ? I have tired it with PyQt5 and same result. your help is really appreciated, Thank you. This is the code I have tried -

from tkinter import *
import pyttsx3
import threading


def start_eng(txt):
    engine = pyttsx3.init()
    engine.say(txt)
    engine.runAndWait()
    

def run_msg(key):
    #engine = pyttsx3.init()
    text=txt.get()
    threading.Thread(target=start_eng, args=(text,)).start() 
    print("space clicked")
    

window = Tk()
window.title("Testing")
window.geometry('300x300')
lbl = Label(window, text="Hello")
txt = Entry(window,width=10)


lbl.grid(column=0, row=0)
txt.grid(column=1,row=1)
txt.bind('<space>', run_msg)

window.mainloop()
Attiq Rahman
  • 173
  • 1
  • 6
  • Cannot reproduce the issue in my Python 3.10.8 in Windows 11 with pyttsx3 2.90. The only issue is exception raised when the current text is still speaking and then press space key to start the speaking again. But it does not crash the GUI. – acw1668 Nov 12 '22 at 15:08
  • @acw1668 Hi, sorry to bother you again. I have used the same configuration as yours. but I am facing the same problem. the UI shuts down after running one time. it does not throw any error. I can not even go the the point to press space 2nd time. – Attiq Rahman Nov 12 '22 at 17:26
  • @acw1668 this is the exact same problem I am facing https://stackoverflow.com/questions/64789324/using-pyttsx3-with-tkinter-causes-program-to-stop-and-close-any-ideas. this a post from 2020 but no-one answered or solved it. – Attiq Rahman Nov 12 '22 at 17:32
  • Try running the python file from the command line. That might show an error if `pyttsx3` is crashing python. – TheLizzard Nov 12 '22 at 18:02
  • @TheLizzard I was using it on Mac and it was not working but when I run the same program on windows, it works fine. – Attiq Rahman Nov 12 '22 at 18:35

0 Answers0