3

I am using the pyttsx3 module for text-to-speech in one of my python projects, but I am not able to choose a male/female option for voices. I read the documentation given on https://pypi.org/project/pyttsx3/ where it says use voices[0].id/voices[1].id for male and female voices respectively. However, that does not seem to work as there is no significant difference between the 2 voices.

My code:

import pyttsx3
engine = pyttsx3.init()

voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

engine.say("Hello World!")
engine.runAndWait()

Any idea how to change the voice and also is there a way to change the language of text-to-speech...something similar to auto-translate?

Ameya Uppina
  • 131
  • 1
  • 3
  • 13

2 Answers2

4
voices = engine.getProperty('voices')       #getting details of current voice
#engine.setProperty('voice', voices[0].id)  #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id)   #changing index, changes voices. 1 for female

this worked for me.

David Buck
  • 3,752
  • 35
  • 31
  • 35
2

To change the voice to either female or male, use

import pyttsx3 as p
engine = p.init()
voice = engine.getProperty('voice')
#for female
engine.setProperty(voice, "!v/f1")
#for male
engine.setProperty(voice, "!v/m1")
engine.runAndWait()
Ekure Edem
  • 310
  • 2
  • 10