Reputation: 41
I am unable to get all the INSTALLED voices for a multi-lingual Text-to-Speech solution, although all installed languages are showing up. I know similar questions have been asked before but there don't seem to be any answers even yet except for some registry tweaks. The code is as under:
foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
{
txtText.AppendText(Environment.NewLine + Environment.NewLine + lang.Culture.EnglishName);
using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
{
var voiceCollection = synthesizer.GetInstalledVoices(new CultureInfo(lang.Culture.Name));
foreach (InstalledVoice voice in voiceCollection)
{
VoiceInfo info = voice.VoiceInfo;
txtText.AppendText(Environment.NewLine + "Name: " + info.Name);
txtText.AppendText(Environment.NewLine + "Gender: " + info.Gender);
txtText.AppendText(Environment.NewLine + "Culture: " + info.Culture + Environment.NewLine);
}
}
}
Upvotes: 3
Views: 2050
Reputation: 5986
I have found the solution. As you said, we have to modify the registry to get all the
voices successfully.
However, we don't need to modify it manually. You can run the following powershell code in
windows powershell.(Don't forget run as administrator for powershell)
$sourcePath = 'HKLM:\software\Microsoft\Speech_OneCore\Voices\Tokens' #Where the OneCore voices live
$destinationPath = 'HKLM:\SOFTWARE\Microsoft\Speech\Voices\Tokens' #For 64-bit apps
$destinationPath2 = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens' #For 32-bit apps
cd $destinationPath
$listVoices = Get-ChildItem $sourcePath
foreach($voice in $listVoices)
{
$source = $voice.PSPath #Get the path of this voices key
copy -Path $source -Destination $destinationPath -Recurse
copy -Path $source -Destination $destinationPath2 -Recurse
}
After running this, you can run your current winform app again. You can see all the
installed voices.
Here is my tested result:
Upvotes: 4