Pyttsx3 voice gender (female)

jelly_bean picture jelly_bean · Sep 2, 2019 · Viewed 8.5k times · Source

I tested out the text-to-speech module i.e pyttsx3 and it worked fine however I'm not getting a female voice when printing out a text. Any suggestions in changing the gender from male to female? By the way, I'm on raspberry pi and am using a Linux OS.

Thank you in advance

tts.py

engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
   engine.setProperty('voice', voice.id)
   engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

Answer

Carlos Bazilio picture Carlos Bazilio · Feb 18, 2021

I've found some acceptable female voices (in my case) using pyttsx3. I'm using MacOS High Sierra, Python 3.7.3 and Pyttsx3 2.90. I've run this code below for using this Samantha voice id:

import pyttsx3
engine = pyttsx3.init()
engine.setProperty('voice', 'com.apple.speech.synthesis.voice.samantha')

I've found many female voices looking for the gender attribute ('VoiceGenderFemale'). However, most of them were strange and this one above was the most acceptable. I've found it running this code:

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
voiceFemales = filter(lambda v: v.gender == 'VoiceGenderFemale', voices)
for v in voiceFemales:
    engine.setProperty('voice', v.id)
    engine.say('Hello world from ' + v.name)
    engine.runAndWait()