使用非默认语音时,Pyttsx未能朗读所有文本

2 投票
1 回答
2796 浏览
提问于 2025-04-16 00:59

我创建了一个小模块,可以把发送给它的文字读出来。如果我不使用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 个回答

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

这段代码最初来自于这个页面

撰写回答