我想停止 pyttsx3。我尝试杀死多进程但响应时间变慢我不知道为什么。这是代码:
import pyttsx3
from multiprocessing import Process
def speakfunc(audio):
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.setProperty('rate', 140)
engine.say(audio)
engine.runAndWait()
def speak(audio):
p = Process(target=speakfunc, args=(audio,))
p.start()
while p.is_alive():
if keyboard.is_pressed('q'):
p.terminate()
else:
continue
p.join()
是否有任何选项或替代方法可以在中间停止讲话?