Pyttsx3 voice gender (female)
Asked Answered
S

8

6

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()
Senary answered 2/9, 2019 at 4:51 Comment(0)
C
9

The reality is, there is No Female Voice included with the core pyttsx3 package. But there is a solution if you use linux/espeak. You can use one of them to simulate the female voice.

engine.setProperty('voice', 'english+f1')
engine.setProperty('voice', 'english+f2')
engine.setProperty('voice', 'english+f3')
engine.setProperty('voice', 'english+f4')
engine.setProperty('voice', 'english_rp+f3') #my preference
engine.setProperty('voice', 'english_rp+f4')

Also you can play around by adding the +f1 to +f4 with other basic voices. For more info you can check this issue in github : pyttsx female voice.

Chobot answered 17/2, 2021 at 0:24 Comment(0)
H
5

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()
Herriot answered 18/2, 2021 at 18:0 Comment(1)
Worked for me in MacOS tooEnvirons
D
2

You can get the female voice by writing the below 1 line:

engine.setProperty('voice', voices[1].id)  # this is female voice

You can print all voices by writing below lines of code:

voices = engine.getProperty('voices')
for v in voices:
    print(v)

Sample output:

<Voice id=com.apple.speech.synthesis.voice.Alex
          name=Alex
          languages=['en_US']
          gender=VoiceGenderMale
          age=35>
<Voice id=com.apple.speech.synthesis.voice.alice
          name=Alice
          languages=['it_IT']
          gender=VoiceGenderFemale
          age=35>
<Voice id=com.apple.speech.synthesis.voice.alva
          name=Alva
          languages=['sv_SE']
          gender=VoiceGenderFemale
          age=35>
<Voice id=com.apple.speech.synthesis.voice.amelie
          name=Amelie
          languages=['fr_CA']
          gender=VoiceGenderFemale
          age=35>
<Voice id=com.apple.speech.synthesis.voice.anna
          name=Anna....
Doretha answered 16/5, 2021 at 12:1 Comment(0)
B
1

If you run below exert code you will get female voice.. Listen and enjoy!!

import pyttsx3
    
engine = pyttsx3.init()  # object creation
voices = engine.getProperty('voices')  # getting details of current voice
#engine.setProperty('voice', voices[0].id)  # changing index, changes voices. 0 for male
engine.setProperty('voice', voices[1].id)  # changing index, changes voices. 1 for female
    
engine.say("I will speak this text")
engine.runAndWait()

Opps wait wait before you run this code you need install Additional package just copy and paste below text on your powershell or your environment

pip install pyttsx3

Normally windows has built-in voice

print(voices[0].id) # this guy name is David

print(voices[1].id) # beautiful women name ZIRA(hahaha)
Brownlee answered 10/10, 2020 at 8:17 Comment(0)
K
0

Pyttsx gives you an option to change :

engine.setProperty('voice', voices[1].id)

I know it doesn't work. Then I thought to run on Python this:

for voice in voices:
  print("ID: %s" % voice.id)
  print("Name: %s" % voice.name)
  print("Age: %s" % voice.age)
  print("Gender: %s" % voice.gender)
  print("Languages Known: %s" % voice.languages)

When I saw the output there were no female voices. I tried the same library on Windows all fine. So you could change the voice by changing the ID, but not in a female voice, not in Linux and not with the standard packages. Maybe there could be a way to implement a voice package but this could be tricky.

I tried gTTS but it seems not to work anymore. I guess Google is changing something in the translate package and gTTS crashes (worked 6 months ago but not anymore). I found a solution but I don't know if that would satisfy you:

  1. Write a bash script which uses SVOX pico2wave for text to voice (this was the only library I found with a female voice, which I couldn't use in Python but works fine in Bash).
  2. Make your Python project without the voice input/output part just like text input/output.
  3. Make another Bash script for voice to text.
  4. Make another Bash script which uses 3 than 2 than 1. The idea is:
    • Get voice via Bash and the output should be send to the Python code.
    • The Python code should manage the data and give an output.
    • The output should trigger the text to voice Bash script.

Voila you have a female voice. A work around but better than nothing.

Kristykristyn answered 5/11, 2020 at 21:55 Comment(0)
J
0

Just try it:

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('rate', 196)
engine.setProperty('volume', 2.7)
engine.setProperty('voice', voices[1].id)
Jacquez answered 31/8, 2021 at 9:17 Comment(0)
O
0
# print('number of voices',len(voices))
#>75
# uname -a
#>Debian 5.19.11-1kali2 (2022-10-10)

I agree with https://stackoverflow.com/users/453673/nav The TTSX documentation needs an update. Pattern is now something like this:

    <voice id=english
    name=english
    languages=[b'\x02en-gb']
    gender=male
    age=None>

there are 75 lines in my distribution. So my basic python skill would suggest to me if we need an english voice, use something like:

    voices = engine.getProperty('voices') 
    engine.setProperty('voices', voices[13]) <!-- English GB 

That's my preference.

To see this scribble a bit of code:

    import pyttsx3
    
    if __name__ == '__main__':
        engine.pyttsx3.init()
        voices = engine.getProperty('voices')
        for x in voices:
            print(x)

That should print out the list/table and we can choose our favorites there.

Note: in my version of pyttsx3 the docs say: The Voice metadata

class pyttsx3.voice.Voice
Contains information about a speech synthesizer voice.
age - Integer age of the voice in years. Defaults to None if unknown.
gender - String gender of the voice: male, female, or neutral. Defaults to None if unknown.
id - String identifier of the voice. Used to set the active voice via pyttsx3.engine.Engine.setPropertyValue(). This attribute is always defined.
languages - List of string languages supported by this voice. Defaults to an empty list of unknown.
name - Human readable name of the voice. Defaults to None if unknown.

My personal favorite is 13 or 14th in the list which in my opinion is close to batman's Alfred Pennyworth. Of course he would be my choice in computer first fellow for my plans to take over the world!

Overpay answered 6/3, 2023 at 16:54 Comment(0)
J
-1

From the official pypi page for pyttsx3 :

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

Jenness answered 2/9, 2019 at 4:55 Comment(2)
Unfortunately, I'm getting a male voice only. When I tried to print out all the voices available, there were surprisingly only male voices but in different accents such as African, British etc. Is there a way to install some module and implement a female voice?Senary
Same here. Only a male voice is being played. I think it happens because pyttsx3 uses TTS engines pre-installed on the system, and the TTS engines for Windows and Linux are different. print('number of voices',len(voices)) shows that there are 69 voices. Surely there's some better documentation required.Antitrades

© 2022 - 2024 — McMap. All rights reserved.