SHARE
TWEET

Untitled

a guest Feb 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private SpeechRecognitionEngine rec;
  2.  
  3. private void voice()    
  4. {
  5.     rec = new SpeechRecognitionEngine();
  6.     rec.SetInputToDefaultAudioDevice();
  7.     Choices choice = new Choices("apple","Orange","Onion");
  8.     GrammarBuilder gr = new GrammarBuilder(choice);
  9.     Grammar grammar = new Grammar(gr);
  10.     rec.LoadGrammar(grammar);
  11.     rec.SpeechRecognized +=
  12.         new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecogonized);
  13.     rec.RecognizeAsync(RecognizeMode.Multiple);
  14. }
  15.  
  16. void rec_SpeechRecogonized(object sender, SpeechRecognizedEventArgs e)
  17. {
  18.     foreach (RecognizedWordUnit word in e.Result.Words)
  19.     {
  20.          textBox1.Text = word.Text;
  21.     }
  22. }
  23.    
  24. private SpeechRecognitionEngine rec;
  25.  
  26. private void voice()    
  27. {
  28.     rec = new SpeechRecognitionEngine();
  29.     rec.SetInputToDefaultAudioDevice();
  30.     Choices choice = new Choices("apple","Orange","Onion", "next");
  31.     GrammarBuilder gr = new GrammarBuilder(choice);
  32.     Grammar grammar = new Grammar(gr);
  33.     rec.LoadGrammar(grammar);
  34.     rec.SpeechRecognized +=
  35.         new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecogonized);
  36.     rec.RecognizeAsync(RecognizeMode.Multiple);
  37. }
  38.  
  39. private TextBox currentInput;
  40. void rec_SpeechRecogonized(object sender, SpeechRecognizedEventArgs e)
  41. {
  42.     if (currentInput == null) currentInput = textBox1;
  43.  
  44.     foreach (RecognizedWordUnit word in e.Result.Words)
  45.     {
  46.          if (word.Text = "next") { currentInput = textBox2; }
  47.          else { currentInput.Text = word.Text; }
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top