Я хотел опробовать 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
Кто-нибудь знает, в чем моя проблема?
NullReferenceException
? - person canton7   schedule 19.03.2021new SpeechSynthesizer().SetOutputToDefaultAudioDevice()
куда-то выдает NRE, а это другой вопрос. - person canton7   schedule 19.03.2021