使用非默认语音时 Pyttsx 不会说出所有文本

发布于 2024-09-08 07:43:44 字数 585 浏览 3 评论 0原文

我创建了一个小模块来朗读发送给它的文本。 如果我不使用engine.setProperty设置语音,它工作正常,但如果我设置语音,它只会播放第一个命令。

import pyttsx

def speak( text ):
    if text != "":
        engine = pyttsx.init()
        engine.setProperty('voice', "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\VW Kate") #if I don't do this line then it says both the commands
        engine.say( text )
        engine.runAndWait()

    else:
        print "you didnt enter anything"

    if __name__ == "__main__":
        speak("Hello")
        speak("This one won't play unless I use the default voice")

I created a small module to speak the text that is sent to it.
It works fine if I don't use engine.setProperty to set the voice, but if I set the voice it will only play the first command.

import pyttsx

def speak( text ):
    if text != "":
        engine = pyttsx.init()
        engine.setProperty('voice', "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\VW Kate") #if I don't do this line then it says both the commands
        engine.say( text )
        engine.runAndWait()

    else:
        print "you didnt enter anything"

    if __name__ == "__main__":
        speak("Hello")
        speak("This one won't play unless I use the default voice")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2024-09-15 07:43:44

我认为您应该尝试以下代码片段:

import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

最初来自 此页面

I think you should try the following code snippet :

import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

which is originally from this page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文