Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I am doing speech recognition in c# and using this code every thing is fine but


C#
private void Form1_Load(object sender, EventArgs e)
                {
              Choices commands = new Choices();
              GrammarBuilder gb = new GrammarBuilder();
 

 
   
           
   
            commands.Add(new string[] { "red", "blue", "green" ,"meantime","transmit","harvest","consecutive","coordinate","spy","slot","riot","nutrient","citizenship","severely","sovereignty","ridge","brave","lighting","specify","contributor","frustrate","articulate","importantly","transit","dense","seminar","electronics","sunny","shorts","swell","accusation","soften","straighten","terribly","cue","bride","biography","hazard","compelling","seldom","tile","economically","honestly","troubled","twentieth","balanced","foreigner","convenience","delight","weave","timber","till","accurately","plea","bulb","flying","sustainable","devil","bolt","cargo","spine","seller","skilled","managing","marine","dock","organized","fog","diplomat","boring","sometime","summary","missionary","epidemic","fatal","trim","warehouse","accelerate","butterfly","bronze","drown","inherent","nationwide","spit","kneel","vacuum","selected","dictate"});
            
 

            
            gb.Append(commands);
          
            Grammar grammar = new Grammar(gb);
 
            recEngine.LoadGrammarAsync(grammar);
            recEngine.SetInputToDefaultAudioDevice();
 
            recEngine.SpeechRecognized+=recEngine_SpeechRecognized;
 
            recEngine.RecognizeAsync(RecognizeMode.Multiple);
}
 

void recEngine_SpeechRecognized(object sender,SpeechRecognizedEventArgs e)
      {
 
          switch(e.Result.Text){
 
              case "red":
                  textBox1.Text += "red ";
                  break;
 
            //.....cases for each and every word ......\
            //............................................

 
          }<pre>
 

but the efficiency is not so good can you help me how to improve it...
Posted

1 solution

You don't need a switch statement here to run through all words. The word you append to the textbox is the same as the recognized word, so just append e.Result.Text to your textbox:
C#
void recEngine_SpeechRecognized(object sender,SpeechRecognizedEventArgs e)
{
    textBox1.Text += e.Result.Text;
}
 
Share this answer
 

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