pyttsx3
pyttsx3 copied to clipboard
pyttsx3.voice.Voice Invalid.
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.
pyttsx3.voice.Voice.age = 5 #No effect pyttsx3.voice.Voice.gender = 'male' #No effect
As far as I know, that's not how you would use it and they are currently undefined in the SAPI5 and espeak engine files under setProperty, while the getProperty is defined in espeak.
Generally, you would change to a female voice, instead of a male voice.
You can check, if you have multiple voices installed by adding these lines to your code:
voices = engine.getProperty('voices')
print(voices)
Then, if you have at least two voices, you can switch to the second voice by entering the following line:
engine.setProperty('voice', voices[1].id)
Any changes you make need to be made through the engine. Not directly through the pyttsx3 module itself. Full Example:
import pyttsx3
# Initialize the Speech Engine
engine = pyttsx3.init()
# Get the voice objects and print them. (This is just to see, if you have more than one voice.)
voices = engine.getProperty('voices')
print(voices)
# Set the voice to the second voice. (voices[0].id would be the first voice)
engine.setProperty('voice', voices[1].id)
# Set the words per minute rate of the Speech engine
engine.setProperty('rate', 105)
# Tell the engine what you want it to say.
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
# Tell the engine to start saying what you wanted it to and stop when it reaches the end of the queued sayings.
engine.runAndWait()
How can I install another language (example : Vietnamese) and make it as the default voice for pyttsx3?
You need to download/install an SAPI5 compatible language. I would suggest looking here: https://support.microsoft.com/en-us/help/14236/language-packs#lptabs=win10
For it to be the default, you'd have to set that as the default in Windows. Which I wouldn't recommend, unless you're fluent in Vietnamese. Otherwise, you can use the example I provided earlier to change the voice to the one you want. After you've installed the language pack.
You should have started a new issue, instead of hijacking this thread.
I've tried to install like the tutorial of Microsoft but the TTS voicde pack appear in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_viVN_An
but it does not appear in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
So when i run the TTS, it still using English voice.
I've noted that issue with the enGB language pack. It comes with 2 voices, but only one shows up in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
I assumed, it meant that one was an SAPI4 voice and the other was an SAPI5 voice.
Hmm..., this list seems to show that Vietnamese isn't available as a Text-to-Speech language on Windows 10. https://support.office.com/en-us/article/How-to-download-Text-to-Speech-languages-for-Windows-10-d5a6b612-b3ae-423f-afa5-4f6caf1ec5d3
But i found Vietnamese in the voices text to speech option in Windows settings
I've tried to install like the tutorial of Microsoft but the TTS voicde pack appear in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_viVN_An
but it does not appear in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
So when i run the TTS, it still using English voice.
You can register manually the voices found in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
by copying them to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
- Open Windows Registry Editor, regedit.exe
- Export the entire Speech_oneCore voices tokens branch,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
, to a file with the extension .reg, for instance export.reg - Open export.reg with a text editor and replace all occurrences of
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
withHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\**Speech**\Voices\Tokens
- Save the modified export.reg and double click on it to register the voices.
Voilà ! Now pyttsx3 can utilize all Windows 10 TTS voices.
`import pyttsx3 engine = pyttsx3.init()
tr_voice_id ='HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_TR-tr_Tolga_11.0' engine.setProperty('voice',tr_voice_id) engine.say("Merhaba Dünya ") engine.runAndWait()
voices = engine.getProperty('voices') for voice in voices: print("Voice:") print(" - ID: %s" % voice.id) print(" - Name: %s" % voice.name) print(" - Languages: %s" % voice.languages) print(" - Gender: %s" % voice.gender) print(" - Age: %s" % voice.age)`
Hi all. Same issue here. I added the Speech_OneCore reg to Speech reg but still the Turkish Voice is not working. Even if I add the .reg it wont show up in my print commands too. Checked the reg data but could not find why its not working. Any other suggestions?
I have this: https://bit.ly/319Z8yw and after doing what is aid above I now have this: https://bit.ly/2D9naBI A bunch of voices did not copy over. Anyone know why
If you want to add voices other than single voice given in pyttsx3, Follow these steps to add additional voices given in your windows .
Open Windows Registry Editor, regedit.exe Export the entire Speech_oneCore voices tokens branch, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens, to a file with the extension .reg, for instance export.reg
Open export.reg with a text editor and replace all occurrences of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens with HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens
Save the modified export.reg and double click on it to register the voices.
This let me add total 3 voices- 1 given in pyttsx3 2 given voice in windows( 1 male and 1 female)
This actually worked for me after lot of research!!
But i found Vietnamese in the voices text to speech option in Windows settings You can find solutions in this video: https://youtu.be/qVMHoCtjLag?t=1031