SetOutputToDefaultAudioDevice () получает исключение NullException

Я хотел опробовать 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

Кто-нибудь знает, в чем моя проблема?


person benni1913    schedule 19.03.2021    source источник
comment
Какая трассировка стека на NullReferenceException?   -  person canton7    schedule 19.03.2021
comment
Всем, кто думает о закрытии как о дублировании классической публикации NullReferenceException, подумайте еще раз. Похоже, дело в том, почему new SpeechSynthesizer().SetOutputToDefaultAudioDevice() куда-то выдает NRE, а это другой вопрос.   -  person canton7    schedule 19.03.2021
comment
Думаю, потребуется полная трассировка стека. Как говорит @ canton7, это не нормальный NRE. Я считаю, что настоящая причина кроется в нескольких слоях исключений.   -  person Neil    schedule 19.03.2021
comment
Извините за поздний ответ. Я добавил подробный журнал ошибок, это помогает?   -  person benni1913    schedule 22.03.2021