How to change the voice in pyttsx3?

后端 未结 2 766
广开言路
广开言路 2020-12-16 08:53

This code is working but I\'m only able to switch between the voices which came preInstalled in Microsoft Windows. These voices are \"Microsoft David Mobile\" and \"Microsof

相关标签:
2条回答
  • 2020-12-16 09:06

    I have just noticed. To set the language⇓ This is just my default language setting is 'ja_JP'.

    import pyttsx3
    
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    for voice in voices:
        print voice
        if voice.languages[0] == u'en_US':
            engine.setProperty('voice', voice.id)
            break
    
    engine.say('Hello World')
    engine.runAndWait()
    

    or

    voice.name == 'Alex'
    
    0 讨论(0)
  • 2020-12-16 09:09

    You can try this code:

    import pyttsx3
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    for voice in voices:
        print(voice, voice.id)
        engine.setProperty('voice', voice.id)
        engine.say("Hello World!")
        engine.runAndWait()
        engine.stop()
    

    Then instead of the for loop, just pick up your preferred voice.id

    0 讨论(0)
提交回复
热议问题