StateChangedEventArgs StateChangedEventArgs StateChangedEventArgs StateChangedEventArgs Class

定義

StateChanged イベントからのデータを返します。Returns data from the StateChanged event.

public ref class StateChangedEventArgs : EventArgs
public class StateChangedEventArgs : EventArgs
type StateChangedEventArgs = class
    inherit EventArgs
Public Class StateChangedEventArgs
Inherits EventArgs
継承
StateChangedEventArgsStateChangedEventArgsStateChangedEventArgsStateChangedEventArgs

次の例では、共有音声認識エンジンを作成し、文法および自由発話のディクテーションを受け入れるための特定の単語を認識するための 2 種類が作成されます。The following example creates a shared speech recognizer, and then creates two types of grammars for recognizing specific words and for accepting free dictation. 例は、認識エンジンに作成されたすべての文法を非同期で読み込みます。The example asynchronously loads all the created grammars to the recognizer. ハンドラーをStateChangedイベントを使用して、 EmulateRecognizeAsync 「リッスン」モードで Windows の認識を配置するメソッド。A handler for the StateChanged event uses the EmulateRecognizeAsync method to put Windows Recognition in "listening" mode.

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");  
    }  
  }  
}  

注釈

StateChangedイベントは、SpeechRecognizerクラス。The StateChanged event is raised by the SpeechRecognizer class. StateChangedEventArgs 派生したEventArgsのハンドラーに渡されるとStateChangedイベント。StateChangedEventArgs derives from EventArgs and is passed to handlers for StateChanged events.

State 読み取り専用プロパティです。State is a read-only property. 共有音声認識エンジンの状態をプログラムで変更することはできません。A shared speech recognizer's state cannot be changed programmatically. ユーザーが音声認識のユーザー インターフェイス (UI) を使用して、共有音声認識エンジンの状態を変更または、音声認識メンバーは、Windows のコントロール パネルの します。Users can change a shared speech recognizer's state using the Speech Recognition user interface (UI) or through the Speech Recognition member of the Windows Control Panel.

両方のスリープ音声認識の UI での設定に対応して、Listening状態。Both the On and Sleep settings in the Speech Recognition UI correspond to the Listening state. オフ音声認識の UI での設定に対応してStoppedします。The Off setting in the Speech Recognition UI corresponds to Stopped.

プロパティ

RecognizerState RecognizerState RecognizerState RecognizerState

Windows の共有音声認識エンジンの現在の状態を取得します。Gets the current state of the shared speech recognition engine in Windows.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください