Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how i do convert a sqlserver table to grammar in C# recognition ?
for example:
C#
var db = new DataClasses1DataContext();
        var word = from c in db.Englishes select c;
                   comboBox1.DataSource = word;
         comboBox1.DisplayMember = "English_Word";
           comboBox1.ValueMember = "English_Word";

           string[]  conv=new string[100000];

           for (int a = 0; a < comboBox1.Items.Count; a++)  conv[a] = comboBox1.Items[a].ToString();
           Choices comands = new Choices();
           comands.Add(conv);
           GrammarBuilder gbuilder = new GrammarBuilder();
           gbuilder.Append(comands);
           Grammar grammar = new Grammar(gbuilder);

           recEngine.LoadGrammarAsync(grammar);
           recEngine.SetInputToDefaultAudioDevice();
           recEngine.RecognizeAsync(RecognizeMode.Multiple); //Error here


is error in

recEngine.RecognizeAsync(RecognizeMode.Multiple);

( {"At least one grammar must be loaded before doing a recognition."} ) is error


please help me thank you
Posted
Updated 26-Aug-15 4:14am
v2
Comments
Sergey Alexandrovich Kryukov 26-Aug-15 10:30am    
Where is your declaration of recEngine? What is your thread apartment model?
—SA

1 solution

You are loading the Grammar asynchronously, so it might happen that it isn't fully loaded yet when you start recognizing.

There are two options to avoid that:

  1. Load the grammar synchronously, using LoadGrammar instead of LoadGrammarAsync.
  2. If you load it async, only start the recognizer once the loading is complete. Add a LoadGrammarCompleted event handler which starts the recognizer:
    C#
    recEngine.LoadGrammarCompleted += delegate(EventHandler<LoadGrammarCompletedEventArgs> e)
    {
        recEngine.SetInputToDefaultAudioDevice();
        recEngine.RecognizeAsync(RecognizeMode.Multiple);
    };
    recEngine.LoadGrammarAsync(grammar);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900