首页 > 代码库 > Kinect 2.0&Speech 11 中文语音控制

Kinect 2.0&Speech 11 中文语音控制

Kinect 2.0&Speech 11 中文语音控制相关代码

?

下载 Speech 11 中文语言包

Microsoft Speech Platform - Runtime Languages (Version 11)

?

查找中文语言的RecognizerInfo

  1. private static RecognizerInfo TryGetKinectRecognizer()
  2. ????????{
  3. ????????????IEnumerable<RecognizerInfo> recognizers;
  4. ????????????// This is required to catch the case when an expected recognizer is not installed.
  5. ????????????// By default - the x86 Speech Runtime is always expected.
  6. ????????????try
  7. ????????????{
  8. ????????????????recognizers = SpeechRecognitionEngine.InstalledRecognizers();
  9. ????????????}
  10. ????????????catch (COMException)
  11. ????????????{
  12. ????????????????return null;
  13. ????????????}
  14. ????????????foreach (RecognizerInfo recognizer in recognizers)
  15. ????????????{
  16. ????????????????string value;
  17. ????????????????recognizer.AdditionalInfo.TryGetValue("Kinect", out value);
  18. ????????????????if ("True".Equals(value, StringComparison.OrdinalIgnoreCase) && "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
  19. ????????????????{
  20. ???????????????????//return recognizer;
  21. ????????????????}
  22. ????????????????if ("zh-CN".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
  23. ????????????????{
  24. ????????????????????return recognizer;
  25. ????????????????}
  26. ????????????}
  27. ????????????return null;
  28. ????????}

构建中文指令

  1. RecognizerInfo ri = TryGetKinectRecognizer();
  2. this.speechEngine = new SpeechRecognitionEngine(ri.Id);
  3. var directions = new Choices();
  4. directions.Add(new SemanticResultValue("", "FORWARD"));
  5. directions.Add(new SemanticResultValue("前进", "FORWARD"));
  6. ?directions.Add(new SemanticResultValue("前移", "FORWARD"));
  7. ?directions.Add(new SemanticResultValue("", "BACKWARD"));
  8. ?directions.Add(new SemanticResultValue("后退", "BACKWARD"));
  9. ??directions.Add(new SemanticResultValue("后移", "BACKWARD"));
  10. ??directions.Add(new SemanticResultValue("", "LEFT"));
  11. ??directions.Add(new SemanticResultValue("", "RIGHT"));
  12. ?var gb = new GrammarBuilder { Culture = ri.Culture };
  13. gb.Append(directions);
  14. var g = new Grammar(gb);
  15. ? this.speechEngine.LoadGrammar(g);

?

官方Demo下载

Kinect 2.0&Speech 11 中文语音控制