-1
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print (voice)
    if voice.languages[-1] == u'en_us':
        engine.setProperty('voice', voice.id)

engine.say('Hello World')
engine.runAndWait()

#the list docent have Siri included 
Zephyr
  • 11,891
  • 53
  • 45
  • 80
  • there are only 2 voices `Microsoft David Desktop - English (United States)` and `Microsoft Zira Desktop - English (United States)` no Siri – Just for fun Aug 13 '20 at 06:37

1 Answers1

0

You set the voice like this:

engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[i].id)

where i is an integer, pointing at one of your installed Siri-voices.

You can test the different voices with this for example:

import pyttsx3

text = "Greetings Professor Falken"
engine = pyttsx3.init()
voices = engine.getProperty('voices')

while True:
    try:
        user_input = input()
        i = int(user_input)
        engine.setProperty('voice', voices[i].id)
        engine.say(text)
        engine.runAndWait()
        print(user_input+") "+engine.getProperty('voice'))
    except Exception as e:
        print(e)

Type in an integer and press enter to hear the voice.

Or if you want to run through all installed voices, you can do it like this:

import pyttsx3

text = "Greetings Professor Falken"
engine = pyttsx3.init()
voices = engine.getProperty('voices')

for voice in voices:
    try:
        i = voices.index(voice)
        engine.setProperty('voice', voices[i].id)
        engine.say(text)
        engine.runAndWait()
        print(str(i)+") "+engine.getProperty('voice'))
    except Exception as e:
        print(e)
thomin
  • 81
  • 5