C# Speech Recognition - Is this what the user said?

后端 未结 11 964
感动是毒
感动是毒 2020-11-28 19:49

I have need to write an application which uses a speech recognition engine -- either the built in vista one, or a third party one -- that can display a word or phrase, and r

11条回答
  •  孤城傲影
    2020-11-28 20:07

    Before this add 'Speech' reference

    System.Speech

    Found that the code example posted by Kyralessa on Oct 22nd didn't work for me but a slightly revised version did. When adding strings into the Choices object use full text English words not numbers. Seems the MS speech recognition engine can't recognize numbers by themselves.

    I have marked these modifications with some commenting added to the previous example.

    public partial class Form1 : Form
    {
      SpeechRecognizer rec = new SpeechRecognizer();
    
      public Form1()
      {
        InitializeComponent();
        rec.SpeechRecognized += rec_SpeechRecognized;
      }
    
      void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
      {
        lblLetter.Text = e.Result.Text;
      }
    
      void Form1_Load(object sender, EventArgs e)
      {
        var c = new Choices();
    
        // Doens't work must use English words to add to Choices and
        // populate grammar.
        //
        //for (var i = 0; i <= 100; i++)
        //  c.Add(i.ToString());
    
        c.Add("one");
        c.Add("two");
        c.Add("three");
        c.Add("four");
        // etc...
    
        var gb = new GrammarBuilder(c);
        var g = new Grammar(gb);
        rec.LoadGrammar(g);
        rec.Enabled = true;
      }
    

提交回复
热议问题