最近有一个语音识别的功能,C#项目又是内网没法联各大厂商的云API,因此打算使用微软的语音识别引擎Speech To Text;但是最终发现它在实现设置好关键词的前提下识别率倒还行,真正做语音识别几乎无法识别。做为命令控制似乎行得通,但是语音检索,就不可能先设置关键词了。在海量数据中检索数据,比如上千万、亿万条记录中检索数据,是不可能将所有关键词提前准备好的。所以最终没用用上~
贴一下大概代码,作为笔记…

private SRecognition sr;
 public SpeechRecognitionEngine recognizer = null;//语音识别引擎  
 public DictationGrammar dictationGrammar = null; //自然语法  
 
 //初始化一个引擎关键词的数组
 string[] msg = { "中华人民共和国",  "4211811995","北京时间","注销登录",
                "罗永浩", "人人都说江南好",  "春暖花开","a123" ,  "A123" , "武汉加油" ,"结束" };
            //List<String> list1 = new List<String>();
            //for (int i = 0; i < 2000; i++)
            //{
            //    list1.Add("A"+i);

            //}
            //String [] ss= list1.ToArray();
            sr = new SRecognition(msg);
             button2.Enabled = false;

    public void button1_Click(object sender, EventArgs e)
    {
            sr.BeginRec(textBox1);
    }
    
  public void BeginRec(Control tbResult)//关联窗口控件  
    {
      TurnSpeechRecognitionOn();
      TurnDictationOn();
      cDisplay = tbResult;
    }



  private void TurnSpeechRecognitionOn()//启动语音识别函数  
    {
      if (recognizer != null)
      {
        recognizer.RecognizeAsync(RecognizeMode.Multiple);
                //识别模式为连续识别  异步调用识别引擎,允许多次识别
            }
            else
      {
        MessageBox.Show("创建语音识别失败");
      }
    }


 private void TurnDictationOn()
    {
      if (recognizer != null)
      {
        //recognizer.LoadGrammar(dictationGrammar);
        //加载自然语法  
      }
      else
      {
        MessageBox.Show("创建语音识别失败");
      }
    }


public SRecognition(string[] fg) //创建关键词语列表  
    {
        bool bJapan = false;
        if (!bJapan)
        {
            CultureInfo myCIintl = new CultureInfo("zh-CN");
            foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())//获取所有语音引擎  
            {
                if (config.Culture.Equals(myCIintl) && config.Id == "MS-2052-80-DESK")
                {
                    recognizer = new SpeechRecognitionEngine(config);
                    break;
                }//选择识别引擎
            }
        }
        else
        {
            CultureInfo myCIintl = new CultureInfo("ja-JP");
            foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())//获取所有语音引擎  
            {
                if (config.Culture.Equals(myCIintl) && config.Id == "MS-1041-80-DESK")
                {
                    recognizer = new SpeechRecognitionEngine(config);
                    break;
                }//选择识别引擎
            }
        }
      if (recognizer != null)
      {
        InitializeSpeechRecognitionEngine(fg);//初始化语音识别引擎  
        dictationGrammar = new DictationGrammar();
      }
      else
      {
        MessageBox.Show("创建语音识别失败");
      }
    }


private void InitializeSpeechRecognitionEngine(string[] fg)
	{
      recognizer.SetInputToDefaultAudioDevice();//选择默认的音频输入设备  
      Grammar customGrammar = CreateCustomGrammar(fg);
      //根据关键字数组建立语法  
      recognizer.UnloadAllGrammars();
      recognizer.LoadGrammar(customGrammar);
      //加载语法  
      recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs> (recognizer_SpeechRecognized);
      //recognizer.SpeechHypothesized += new EventHandler <SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);  
    }

  //停止语音识别引擎  
 public void over()
    {
      TurnSpeechRecognitionOff();
  }

public virtual Grammar CreateCustomGrammar(string[] fg) //创造自定义语法  
    {
      GrammarBuilder grammarBuilder = new GrammarBuilder();
      grammarBuilder.Append(new Choices(fg));
      return new Grammar(grammarBuilder);
    }

//启动语音识别函数  
private void TurnSpeechRecognitionOn()
    {
      if (recognizer != null)
      {
        recognizer.RecognizeAsync(RecognizeMode.Multiple);
                //识别模式为连续识别  异步调用识别引擎,允许多次识别
            }
            else
      {
        MessageBox.Show("创建语音识别失败");
      }
    }
    
 //关闭语音识别函数 
 private void TurnSpeechRecognitionOff() 
    {
      if (recognizer != null)
      {
        recognizer.RecognizeAsyncStop();
        TurnDictationOff();
      }
      else
      {
        MessageBox.Show("创建语音识别失败");
      }
    }

 private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      //识别出结果完成的动作,通常把识别结果传给某一个控件  
      string text = e.Result.Text;
      switch (text)
      {
         case "结束":
         //根据关键词不同,进行不同的操作或者跳转
        
         //然后改变引擎所关注的关键词,进行下一步的识别
         //sr.ChangeKeywords(new string[] { "XXX,AAA" });
         break;

         case "注销登录":
         //sr.ChangeKeywords(new string[] { "xxx" });
         break;
         default:
         MessageBox.Show("。。。");
         break;

            }
            cDisplay.Text += text;
    }

过程中借鉴了网上某篇文章但是没找到了,侵删。。