当我尝试运行程序时,它会抛出这个错误:对象引用未设置为对象的实例。代码有问题吗?帮助!
private void InitSpeechRecognition()
{
_audioSource = new KinectAudioSource
{
FeatureMode = true,
AutomaticGainControl = false,
SystemMode = SystemMode.OptibeamArrayOnly
};
var ri =
SpeechRecognitionEngine.InstalledRecognizers().
Where(r => r.Id == RecognizerId).FirstOrDefault();
_engine = new SpeechRecognitionEngine(ri.Id);
var gb = new GrammarBuilder { Culture = new CultureInfo("en-US") };
gb.Append(CommandMessage.Choices);
var g = new Grammar(gb);
_engine.LoadGrammar(g);
_engine.SpeechRecognized += SreSpeechRecognized;
_audioStream = _audioSource.Start();
_engine.SetInputToAudioStream(_audioStream,
new SpeechAudioFormatInfo(
EncodingFormat.Pcm, 16000, 16, 1,
32000, 2, null));
_engine.RecognizeAsync(RecognizeMode.Multiple);
}
private void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (CommandMessage.Commands.ContainsKey(e.Result.Text))
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(() =>
Messenger.Default.Send(
new CommandMessage { Command = CommandMessage.Commands[e.Result.Text] })));
}
}