2

送信されるテキストを話すための小さなモジュールを作成しました。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")
4

1 に答える 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()

もともとこのページからです

于 2011-06-15T12:42:54.537 に答える