gpt4 book ai didi

python - Pyttsx "run"但没有 "wait"

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:05 25 4
gpt4 key购买 nike

我正在使用 pyttsx在我的游戏中,但我遇到了一个问题 - 方法 runAndWait() 导致它停止一小段时间来说出排队的文本。这是个问题,因为它打乱了我的时间计算。是否可以说一段文字而不停止所有其他事件?或者在 python/pygame 中是否有任何其他文本到语音转换器?

def say(text):
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('rate', 250)
engine.say(text)
engine.runAndWait()

最佳答案

Pyttsx 没有像 runAndNoWait() 这样的方法,但您可以将 say(text) 函数作为单独的线程运行以停止阻塞主游戏线程。

import threading
text = 'Hello world'
threading.Thread(target=say, args=(text,)).start()

关于python - Pyttsx "run"但没有 "wait",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47995938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com