Reputation: 21
I want to change voice in pyttsx3 module to british male voice, which i do have installed since i can see it in language/speech options and in regedit (Microsoft George), and i do have other voices installed, but when i run this code
i dont see all voices that are on my PC, one of those voices is british male. Out of 9 voices i have, pyttsx3 only recognizes 4 Any fix for that?
Thank you
import pyttsx3
engine = pyttsx3.init()
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)
Upvotes: 1
Views: 7291
Reputation: 522
Well it is possible. However you will have to do some changes in registry so proceed below at your own risk. It would be a good practice to backup your registry files or even your system.
STEP 1 Open registry editor:
Press: Windows Key + R
and run regedit as administrator.
STEP 2 Check for all the available languages:
You should follow this path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
and there you will see all installed voices on your system (except the cortana voices).
STEP 3 Export the voices:
Select the one you want and right click on the folder.
For an example:
Right click MSTTS_V110_elGR_Stefanos
and click export.
You can save the file with any name you want but the extension should finish as .reg
STEP 4 Modify the file:
You will need to modify it so that it's values are into two other locations in the registry. Open the file with any text editor of your choice and do the following:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)]
to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\ MSTTS_V110_elGR_Stefanos(Your voice name here)]
(Just change the Speech_OneCore to Speech)
And that goes to attributes location aswell ...\Speech\Voices\Tokens\(your voice name)\Attributes
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)]
and it's attributes with [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\(your voice name)\Attributes
For an example:
Original File:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"
Modified registry file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\MSTTS_V110_elGR_Stefanos]
@="Microsoft Stefanos - Greek (Greece)"
"408"="Microsoft Stefanos - Greek (Greece)"
"CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}"
"LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\
00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\
65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\
00,5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\
4c,00,6f,00,63,00,45,00,6c,00,47,00,52,00,2e,00,64,00,61,00,74,00,00,00
"VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\
70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\
00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\
5c,00,65,00,6c,00,2d,00,47,00,52,00,5c,00,4d,00,31,00,30,00,33,00,32,00,53,\
00,74,00,65,00,66,00,61,00,6e,00,6f,00,73,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens\MSTTS_V110_elGR_Stefanos\Attributes]
"Age"="Adult"
"DataVersion"="11.0.2016.1016"
"Gender"="Male"
"Language"="408"
"Name"="Microsoft Stefanos"
"SayAsSupport"="spell=NativeSupported; alphanumeric=NativeSupported"
"SharedPronunciation"=""
"Vendor"="Microsoft"
"Version"="11.0"
STEP 5 Import the file:
Save the file and double click on it. There will be a warning window press yes and proceed.
STEP 6 Check:
run the following code:
engine = pyttsx3.init()
voices = engine.getProperty("voices")
for voice in voices:
print(voice.id)
Output:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_elGR_Stefanos HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0
Upvotes: 3
Reputation: 19
If you downloaded the language you want to use, it is possible.
Use this way:
Your downloaded languages goes this path in registry: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
Right click to Tokens
node then export these languages from this path, save as lang.reg
file.
Then open lang.reg
file with any text editor then replace text "Speech_OneCore"
to "Speech"
then save and close.
Double click lang.reg
file to import.
In your python file, use it as follows:
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('voice',"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_trTR_Tolga")
engine.say(text="Merhaba dünya")
engine.runAndWait()
# to save to a file
# engine.save_to_file(text="Merhaba dünya", filename="file.mp3")
Upvotes: 0
Reputation:
The Microsoft downloadable voices seem to be limited. If you go to their regedit path you'll see that the extra downloadable voices like Microsoft George from the GB package are saved onto a different path than the one that is accepted by pyttsx3.
On top of this, on further examination, when navigating to the path of these voices (Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens
), I noticed that none of these have a tts attribute, like the default David, Zyra, and Iriana do. This leads me to believe that they cannot be used for tts.
Upvotes: 0