有没有办法暂停、恢复和阻止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有没有办法做到这一点
如果有人能帮我,那就太好了
pyttsx3
没有提供暂停和恢复功能,但您可以通过将句子拆分成单词,然后逐字说话来模拟这些功能。在单词之间,您可以检查是否单击了暂停、取消暂停或停止按钮,并执行相应的操作:更新:使用
pygame
作为播放器:相关问题 更多 >
编程相关推荐