问题描述
我想尝试 SSML,但每次我尝试运行我的代码时,我都会在 SetoutputToDefaultAudioDevice() 处得到一个空异常。
我正在使用 Microsoft 的示例代码:
using System;
using System.Speech.Synthesis;
namespace SSML_Test
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the speech synthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the synthesizer to send output to the default audio device.
synth.SetoutputToDefaultAudioDevice();
// Speak a phrase.
synth.Speak("This is sample text-to-speech output.");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
我使用的是 .NET Core 2.0,并且我已将 System.Speech 正确添加到我的参考文献中。
完整的错误日志:
System.NullReferenceException
HResult=0x80004003
Nachricht = Object reference not set to an instance of an object.
Quelle = System.Speech
Stapelüberwachung:
at
System.Speech.Internal.ObjectTokens.RegistryDataKey.HKEYfromregKey
(RegistryKey regKey)
at System.Speech.Internal.ObjectTokens.RegistryDataKey.RootHKEYFromregPath
(String rootPath)
at System.Speech.Internal.ObjectTokens.RegistryDataKey.Open(String
registryPath,Boolean fCreateIfNotExist)
at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut()
at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference
speechSynthesizer)
at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer()
at System.Speech.Synthesis.SpeechSynthesizer.SetoutputToNull()
at System.Speech.Synthesis.SpeechSynthesizer.SetoutputStream(Stream stream,SpeechAudioFormatInfo formatInfo,Boolean headerInfo,Boolean
closeStreamOnExit)
at System.Speech.Synthesis.SpeechSynthesizer.SetoutputToDefaultAudioDevice()
at SSML_Test.Program.Main(String[] args) in C:\Users\User\source\repos\SSML
Test\SSML Test\Program.cs:line 15
有人知道我的问题是什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)