语音合成无法使用SetVoice()。所有都被列为已启用,直到它被尝试,然后失败,非默认的两个被列为'禁用'。
注意:这适用于WPF或控制台应用程序,但作为ASP.NET应用程序失败。 另外:语音是在备用线程上创建的(Task.Run(()=> StartSpeech()),因为它永久锁定ASP.NET应用程序的主线程(有关详细信息,请参阅No response to a HTTP Get request in WebAPI in .NET 4.5 while using SpeechSynthesis for converting text to speech)。但是,SelectVoice ()在备用线程和主线程上都失败了。
想法?
private SpeechSynthesizer speech; //System.Speech.Synthesis
var voices = speech.GetInstalledVoices();
//[0]: "Microsoft David Desktop" ["Enabled"]
//[1]: "IVONA 2 Emma" ["Enabled"]
//[2]: "Microsoft Zira Desktop" ["Enabled"]
try
{
speech.SelectVoice( "Microsoft Zira Desktop" );
}
catch (Exception e)
{
var p = e; //fails (System.ArgumentException: Cannot set voice. No matching voice is installed or the voice was disabled)
}
voices = speech.GetInstalledVoices();
//[0]: "Microsoft David Desktop" ["Disabled"]
//[1]: "IVONA 2 Emma" ["Enabled"]
//[2]: "Microsoft Zira Desktop" ["Disabled"]
speech.SpeakAsync( text );
答案 0 :(得分:0)
事实证明,这甚至可以在Visual Studio IIS Express下运行,但在IIS下失败了。从ApplicationPoolIdentity切换到LocalSystem使其工作。似乎SelectVoice()是一个启用权限的调用,简单地说不是。
答案:将应用程序池的标识(在IIS中)更改为LocalSystem。