public void recognizer_StateChanged(object sender, StateChangedEventArgs e) { if (e.RecognizerState != RecognizerState.Stopped) { recognizer.EmulateRecognizeAsync("Start listening"); } }
public void StartRecognition(bool emulate) { if (emulate) { Thread.Sleep(500); rec.EmulateRecognizeAsync("include io_stream"); Thread.Sleep(500); rec.EmulateRecognizeAsync("include charconv"); Thread.Sleep(500); rec.EmulateRecognizeAsync("include charconv"); Thread.Sleep(500); rec.EmulateRecognizeAsync("using_namespace standard"); Thread.Sleep(500); rec.EmulateRecognizeAsync("function void main"); Thread.Sleep(500); rec.EmulateRecognizeAsync("print_line string This string is going to be printed"); Thread.Sleep(500); rec.EmulateRecognizeAsync("print_line string This string is going to be printed"); } else { recognising = true; rec.RecognizeAsync(RecognizeMode.Multiple); window.ToggelButton.Background = new SolidColorBrush(Color.FromArgb(255, 64, 192, 117)); window.status.Text = "Listening..."; } }
private static void TestRecognizeAsync(SpeechRecognitionEngine recognizer, string input) // Send emulated input to the recognizer for asynchronous recognition. { completed = false; Debug.WriteLine("TestRecognizeAsync(\"{0}\")...", input); recognizer.EmulateRecognizeAsync(input); while (!completed) // Wait for the operation to complete. { Thread.Sleep(333); } Debug.WriteLine(" Done."); }
public void StartRecognition(bool emulate) { if (emulate) { Thread.Sleep(500); rec.EmulateRecognizeAsync("include io_stream"); Thread.Sleep(500); rec.EmulateRecognizeAsync("using_namespace standard"); Thread.Sleep(500); rec.EmulateRecognizeAsync("function void main"); Thread.Sleep(500); rec.EmulateRecognizeAsync("print_line string This string is going to be printed"); Thread.Sleep(800); rec.EmulateRecognize("add "); } else { //Start recognizer rec.RecognizeAsync(RecognizeMode.Multiple); recognizing = true; } }
static void Main(string[] args) { // Create an in-process speech recognizer. using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new CultureInfo("en-US"))) { // Create a grammar for choosing commandChoices for a flight. Choices commandChoices = new Choices(new string[] { "Lights On", "Lights Off", "All Off", "Say Time"}); GrammarBuilder gb = new GrammarBuilder(); gb.Append(Properties.Settings.Default.AssistantName); gb.Append(commandChoices); // Construct a Grammar object and load it to the recognizer. Grammar commandChooser = new Grammar(gb); commandChooser.Name = ("Command Chooser"); recognizer.LoadGrammarAsync(commandChooser); // Attach event handlers. recognizer.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(SpeechDetectedHandler); recognizer.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(SpeechHypothesizedHandler); recognizer.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(SpeechRecognitionRejectedHandler); recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler); recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(RecognizeCompletedHandler); // Assign input to the recognizer and start asynchronous recognizer.SetInputToDefaultAudioDevice(); _completed = false; Console.WriteLine("Starting asynchronous recognition..."); //recognizer.RecognizeAsync(RecognizeMode.Multiple); recognizer.EmulateRecognizeAsync("Nigel Lights On"); // Wait 30 seconds, and then cancel asynchronous recognition. Thread.Sleep(TimeSpan.FromSeconds(30)); recognizer.RecognizeAsyncCancel(); // Wait for the operation to complete. while (!_completed) { Thread.Sleep(333); } Console.WriteLine("Done."); } Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }