有什么方法可以暂停、恢复和停止 pyttsx3 说话?
我尝试了很多方法,但我找不到解决方案。
这是代码:
from tkinter import *
import pyttsx3
import threading
root = Tk()
def read():
engine.say(text.get(1.0 , END))
engine.runAndWait()
def stop():
# Code to stop pyttsx3 from speaking
pass
def pause():
# Code to pause pyttsx3
pass
def unpause():
# Code to unpause pyttsx3
pass
engine = pyttsx3.init()
text = Text(width = 65 , height = 20 , font = "consolas 14")
text.pack()
text.insert(END , "This is a text widget\n"*10)
read_button = Button(root , text = "Read aloud" , command = lambda: threading.Thread(target=read, daemon=True).start())
read_button.pack(pady = 20)
pause_button = Button(root , text = "Pause" , command = lambda: threading.Thread(target=pause , daemon = True).start())
pause_button.pack()
unpause_button = Button(root , text = "Unpause" , command = unpause)
unpause_button.pack(pady = 20)
stop_button = Button(root , text = "Stop" , command = threading.Thread(target=stop, daemon = True).start())
stop_button.pack()
mainloop()
我想要的是通过单击按钮随时暂停、恢复和停止 pyttsx3。
有没有办法在 tkinter 中实现这一点?
如果有人可以帮助我,那就太好了。