我有一个使用System.Speech将文本转换为WAV文件的ASP.NET Web应用程序。它在本地运行良好,但是当我将其部署到服务器时,出现以下错误消息。这使用的是Windows Server 2012,ASP.NET 4.5和IIS 8.5:
Object reference not set to an instance of an object.
System.Speech
at System.Speech.Internal.ObjectTokens.RegistryDataKey..ctor(String fullPath, RegistryDataKey copyKey)
at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut()
at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference speechSynthesizer)
at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer()
at QuinnSDS.handlerTransform.<>c__DisplayClass6.<ProcessRequest>b__1()
生成此错误消息的代码在服务器上运行:
if (context.Request.ContentLength > 0)
{
string line = new StreamReader(context.Request.InputStream).ReadToEnd();
// ********* generate wav file voicing the response *****************
// Using Microsoft voices
// initiate new instance of speech synthesizer
Thread t = new Thread(() =>
{
try
{
// The object creation works fine
System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();
if (synth != null)
{
// The code breaks at synth.GetInstalledVoices() below. It will break any time I try to do anything with the synth object
foreach (System.Speech.Synthesis.InstalledVoice voice in synth.GetInstalledVoices())
{
System.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo;
string voiceName = info.Name;
ws.WriteLine(voiceName);
}
}
}
catch (Exception e)
{
ws.WriteLine(e.Message);
ws.WriteLine(e.Source);
ws.WriteLine(e.StackTrace);
}
//... code continues...
创建语音合成对象时,它不会中断;每当我尝试以任何方式使用该对象时,它都会中断。
我不确定这是否是访问问题,但是我对ASP.NET和IIS还是很陌生,我无法弄清楚如何使Web应用程序可以访问GAC,或者即使这就是问题所在。在部署应用程序之前,我曾尝试在Visual Studio中将System.Speech引用的属性Local Copy更改为True,但是这没有用。我在线搜索,虽然“对象引用未设置为对象的实例”似乎很常见,但是由于.NET Framework类库,我找不到任何类似的问题...我已经运行了文本到服务器上本地的语音代码,并且运行良好。我尚未在服务器上本地运行整个应用程序,因为Web应用程序需要语音输入,并且服务器上没有麦克风。
任何尝试的想法都将受到欢迎!
从ASP.NET执行时,代码在哪个用户帐户下运行?如果语音API像调用堆栈所建议的那样接触注册表,则它可能具有与您用来手动运行代码的帐户不同的权限。
如果您不能仅使用登录计算机时使用的帐户来使站点的应用程序池运行,我在使用Process Monitor来解决此类问题之前就已经取得了一些成功。基本上,执行Process Monitor运行时失败的代码,然后在“结果”列中查找“访问权限已拒绝”(或其他可疑内容)。但是,快速切换应用程序池以使用您的标准用户帐户将是排除安全性或权限相关问题的最快方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句