StateChangedEventArgs Kelas

Definisi

Mengembalikan data dari StateChanged peristiwa.

public ref class StateChangedEventArgs : EventArgs
public class StateChangedEventArgs : EventArgs
type StateChangedEventArgs = class
    inherit EventArgs
Public Class StateChangedEventArgs
Inherits EventArgs
Warisan
StateChangedEventArgs

Contoh

Contoh berikut membuat pengenal ucapan bersama, lalu membuat dua jenis tata bahasa untuk mengenali kata-kata tertentu dan untuk menerima dikte gratis. Contoh secara asinkron memuat semua tata bahasa yang dibuat ke pengenal. Handler untuk StateChanged peristiwa menggunakan EmulateRecognizeAsync metode untuk menempatkan Windows Recognition dalam mode "mendengarkan".

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognizer recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize a shared speech recognition engine.  
      recognizer = new SpeechRecognizer();  

      // Add a handler for the LoadGrammarCompleted event.  
      recognizer.LoadGrammarCompleted += new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  

      // Add a handler for the SpeechRecognized event.  
      recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

      // Add a handler for the StateChanged event.  
      recognizer.StateChanged += new EventHandler<StateChangedEventArgs>(recognizer_StateChanged);  

      // Create "yesno" grammar.  
      Choices yesChoices = new Choices(new string[] { "yes", "yup", "yah}" });  
      SemanticResultValue yesValue =  
          new SemanticResultValue(yesChoices, (bool)true);  
      Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });  
      SemanticResultValue noValue = new SemanticResultValue(noChoices, (bool)false);  
      SemanticResultKey yesNoKey =  
          new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));  
      Grammar yesnoGrammar = new Grammar(yesNoKey);  
      yesnoGrammar.Name = "yesNo";  

      // Create "done" grammar.  
      Grammar doneGrammar =  
        new Grammar(new Choices(new string[] { "done", "exit", "quit", "stop" }));  
      doneGrammar.Name = "Done";  

      // Create dictation grammar.  
      Grammar dictation = new DictationGrammar();  
      dictation.Name = "Dictation";  

      // Load grammars to the recognizer.  
      recognizer.LoadGrammarAsync(yesnoGrammar);  
      recognizer.LoadGrammarAsync(doneGrammar);  
      recognizer.LoadGrammarAsync(dictation);  

      // Keep the console window open.  
      Console.ReadLine();  
    }  

    // Put the shared speech recognizer into "listening" mode.  
    static void  recognizer_StateChanged(object sender, StateChangedEventArgs e)  
    {  
     if (e.RecognizerState != RecognizerState.Stopped)  
      {  
        recognizer.EmulateRecognizeAsync("Start listening");  
      }  
    }  

    // Write the grammar name and the text of the recognized phrase to the console.  
    static void  recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
     Console.WriteLine("Grammar({0}): {1}", e.Result.Grammar.Name, e.Result.Text);  

      // Add event handler code here.  
    }  

    // Handle the LoadGrammarCompleted event.  
    static void  recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
     string grammarName = e.Grammar.Name;  
      bool grammarLoaded = e.Grammar.Loaded;  
      if (e.Error != null)  
      {  
        Console.WriteLine("LoadGrammar for {0} failed with a {1}.",  
        grammarName, e.Error.GetType().Name);  
      }  

      // Add exception handling code here.  
      Console.WriteLine("Grammar {0} {1} loaded.",  
      grammarName, (grammarLoaded) ? "is" : "is not");  
    }  
  }  
}  

Keterangan

Acara StateChanged ini dinaikkan oleh SpeechRecognizer kelas . StateChangedEventArgs berasal dari EventArgs dan diteruskan ke handler untuk StateChanged peristiwa.

State adalah properti baca-saja. Status pengenal ucapan bersama tidak dapat diubah secara terprogram. Pengguna dapat mengubah status pengenal ucapan bersama menggunakan antarmuka pengguna (UI) Pengenalan Ucapan atau melalui anggota Pengenalan Ucapandari Panel Kontrol Windows.

Pengaturan Aktif dan Tidur di UI Pengenalan Ucapan sesuai dengan status Listening . Pengaturan Nonaktif di UI Pengenalan Ucapan sesuai dengan Stopped.

Properti

RecognizerState

Mendapatkan status mesin pengenalan ucapan bersama saat ini di Windows.

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk

Lihat juga