2010-07-08 27 views
2

我創建了一個小模塊來說出發送給它的文本。 它工作正常,如果我不使用engine.setProperty設置語音,但如果我設置語音,它將只播放第一個命令。Pyttsx在使用非默認語音時不會說出所有文本

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

回答

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

相關問題