Я использую C# SpeechSynthesizer в проекте Unity, как в этом примере:
https://docs.microsoft.com/en-us/dotnet/api/system.speech.synthesis.speechsynthesizer?view=netframework-4.8
Я получаю эту ошибку:
NullReferenceException: Object reference not set to an instance of an object
System.Speech.Internal.ObjectTokens.RegistryDataKey.HKEYfromRegKey (Microsoft.Win32.RegistryKey regKey) (at [...])
System.Speech.Internal.ObjectTokens.RegistryDataKey.RootHKEYFromRegPath (System.String rootPath) (at [...])
System.Speech.Internal.ObjectTokens.RegistryDataKey.Open (System.String registryPath, System.Boolean fCreateIfNotExist) (at [...])
System.Speech.Internal.ObjectTokens.ObjectTokenCategory.Create (System.String sCategoryId) (at [...])
System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut () (at [...])
System.Speech.Internal.Synthesis.VoiceSynthesis..ctor (System.WeakReference speechSynthesizer) (at [...])
System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer () (at [...])
System.Speech.Synthesis.SpeechSynthesizer.SelectVoiceByHints (System.Speech.Synthesis.VoiceGender gender, System.Speech.Synthesis.VoiceAge age, System.Int32 voiceAlternate, System.Globalization.CultureInfo culture) (at [...])
System.Speech.Synthesis.SpeechSynthesizer.SelectVoiceByHints (System.Speech.Synthesis.VoiceGender gender) (at [...])
Это мой класс:
using System;
using System.Speech.Synthesis;
using UnityEngine;
public class Speaker : MonoBehaviour
{
private SpeechSynthesizer synth = new SpeechSynthesizer();
void Start() {
synth.SetOutputToDefaultAudioDevice();
synth.SelectVoiceByHints(VoiceGender.Female);
}
}
Любые идеи приветствуются.