When trying to use pyttsx3 I can only use English voices. I would like to be able to use Dutch as well.
I have already installed the text to speech language package in the windows settings menu. But I can still only use the deafaut english voice.
How can I fix this?
If you want to change a language you need to change to another "voice" that supports your language.
import pyttsx3
engine = pyttsx3.init()
for voice in engine.getProperty('voices'):
print(voice)
engine.setProperty('voice', voice.id)
I personally use this helper function I mentioned here also
# language : en_US, de_DE, ...
# gender : VoiceGenderFemale, VoiceGenderMale
def change_voice(engine, language, gender='VoiceGenderFemale'):
for voice in engine.getProperty('voices'):
if language in voice.languages and gender == voice.gender:
engine.setProperty('voice', voice.id)
return True
raise RuntimeError("Language '{}' for gender '{}' not found".format(language, gender))
And finally, you can use it like this (if language and gender are installed):
import pyttsx3
engine = pyttsx3.init()
change_voice(engine, "nl_BE", "VoiceGenderFemale")
engine.say("Hello World")
engine.runAndWait()