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

时间:2010-07-08 10:58:20

标签: python text-to-speech

我创建了一个小模块来说出发送给它的文本。 如果我不使用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")

1 个答案:

答案 0 :(得分:3)

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

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()

最初来自this page