码迷,mamicode.com
首页 > 其他好文 > 详细

Kinect 2.0&Speech 11 中文语音控制

时间:2014-12-10 10:28:43      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   sp   for   strong   

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 中文语音控制

标签:style   http   io   ar   color   os   sp   for   strong   

原文地址:http://www.cnblogs.com/linweifu/p/4154753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!