未显示所有“文字转语音”安装的声音

时间:2020-04-18 09:09:48

标签: c# .net visual-studio text-to-speech multilingual

尽管显示了所有已安装的语言,但我无法获得多语言“文本到语音”解决方案的所有安装声音。我知道以前曾问过类似的问题,但除了一些注册表调整外,似乎还没有任何答案。代码如下:

        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);
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。如您所说,我们必须修改注册表以获取所有

成功发声。

但是,我们不需要手动修改它。您可以在

中运行以下powershell代码

windows powershell。(别忘了以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
}

运行此命令后,可以再次运行当前的winform应用程序。您可以看到所有

已安装的声音。

这是我的测试结果:

enter image description here