I have made a function to read the text using pyttsx3 and i have created a stop button using tkinter so when i click it , it will call another function which will stop the reading function to stop reading the text i am not able to do it , i used sys.exit() and it did not work
def stop_voice():
sys.exit(talk)
def talk():
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say(details.get(1.0, END))
engine.runAndWait()
Button(infoframe,text='Stop',command=stop_voice,bg='red',width=15,activebackground='blue').place(x=200,y=660)
#used threading so both text and talk can run
t1=Thread(target=talk)
t1.start()