以 Kinect SDK 的示例为模型
private static RecognizerInfo GetKinectRecognizer()
{
foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers())
{
string value;
recognizer.AdditionalInfo.TryGetValue("Kinect", out value);
if ("True".Equals(value, StringComparison.OrdinalIgnoreCase) && "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
{
return recognizer;
}
}
return null;
}
在窗口加载
RecognizerInfo ri = GetKinectRecognizer();
if (null != ri)
{
this.speechEngine = new SpeechRecognitionEngine(ri.Id);
var directions = new Choices();
directions.Add(new SemanticResultValue("forward", "FORWARD"));
directions.Add(new SemanticResultValue("backward", "BACKWARD"));
directions.Add(new SemanticResultValue("turn left", "LEFT"));
directions.Add(new SemanticResultValue("turn right", "RIGHT"));
var gb = new GrammarBuilder { Culture = ri.Culture };
gb.Append(directions);
var g = new Grammar(gb);
speechEngine.SpeechRecognized += SpeechRecognized;
speechEngine.SpeechRecognitionRejected += SpeechRejected;
speechEngine.SetInputToAudioStream(
kinect.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
speechEngine.RecognizeAsync(RecognizeMode.Multiple);
}
错误:
Microsoft.Speech.dll 中出现“System.InvalidOperationException”类型的未处理异常
附加信息:在进行识别之前,必须至少加载一种语法。
我能做什么?