Share via


SemanticResultKey コンストラクター

定義

SemanticResultKey のインスタンスを構築し、文法コンポーネントにキーを関連付けます。

オーバーロード

SemanticResultKey(String, GrammarBuilder[])

音声認識文法を作成するために使用される 1 つ以上の GrammarBuilder オブジェクトにセマンティクス キーを割り当てます。

SemanticResultKey(String, String[])

音声認識文法を作成するために使用される 1 つ以上の String インスタンスにセマンティクス キーを割り当てます。

注釈

SemanticResultKey コンストラクターは、音声認識文法に追加するテキスト タグ (セマンティック キー) と一連の文法コンポーネントを指定します。

文法コンポーネントは、オブジェクトの配列として、またはインスタンスのGrammarBuilderString配列として指定できます。

認識で文法コンポーネントが使用されている場合は、 のコンストラクターSemanticResultKeyに提供されるテキスト タグをセマンティック キーとして使用して、返された SemanticValue にアクセスできます。 インスタンスの SemanticValue プロパティはValue、 の定義SemanticResultKeyで使用される文法コンポーネントによって決定されます。

SemanticResultKey(String, GrammarBuilder[])

ソース:
SemanticResultKey.cs
ソース:
SemanticResultKey.cs
ソース:
SemanticResultKey.cs

音声認識文法を作成するために使用される 1 つ以上の GrammarBuilder オブジェクトにセマンティクス キーを割り当てます。

public:
 SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ builders);
public SemanticResultKey (string semanticResultKey, params System.Speech.Recognition.GrammarBuilder[] builders);
new System.Speech.Recognition.SemanticResultKey : string * System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray builders As GrammarBuilder())

パラメーター

semanticResultKey
String

builders 引数が指定する SemanticValue オブジェクトによって関連付けられた GrammarBuilder インスタンスにアクセスするためにセマンティクス キーとして使用するタグ。

builders
GrammarBuilder[]

semanticResultKey で定義されているタグでアクセス可能な SemanticValue オブジェクトに関連付けられる文法コンポーネントの配列。

次の例では、"My password is ..." という形式のパスワード入力を認識する を作成 Grammar します。ここで、実際の入力はワイルドカードと一致します。

ワイルドカードは、キー値が "Password" である によってタグ付けされます SpeechRecognizer 。 ハンドラーは SpeechRecognized 、このタグの存在を確認し、パスワードのオーディオ入力を取得し、パスワードを検証します。

private void pwdGrammar()
{
  GrammarBuilder pwdBuilder = new GrammarBuilder("My Password is");
  GrammarBuilder wildcardBuilder = new GrammarBuilder();
  wildcardBuilder.AppendWildcard();
  SemanticResultKey wildcardKey= new SemanticResultKey("Password", wildcardBuilder);
  pwdBuilder+=wildcardKey;
  Grammar grammar = new Grammar(pwdBuilder);
  grammar.Name = "Password input";

  grammar.SpeechRecognized +=
    delegate(object sender, SpeechRecognizedEventArgs eventArgs)
    {
      SemanticValue semantics = eventArgs.Result.Semantics;
      RecognitionResult result=eventArgs.Result;

      if (!semantics.ContainsKey("Password"))
      {
        SpeechUI.SendTextFeedback(eventArgs.Result, "No Password Provided", false);
      }
      else
      {
        RecognizedAudio pwdAudio = result.GetAudioForWordRange(
                  result.Words[3],
                  result.Words[result.Words.Count - 1]);
                  MemoryStream pwdMemoryStream = new MemoryStream();
                  pwdAudio.WriteToAudioStream(pwdMemoryStream);
        if (!IsValidPwd(pwdMemoryStream))
        {
          string badPwd = System.IO.Path.GetTempPath() + "BadPwd" + (new Random()).Next().ToString() + ".wav";
          FileStream waveStream = new FileStream(badPwd, FileMode.Create);
          pwdAudio.WriteToWaveStream(waveStream);
          waveStream.Flush();
          waveStream.Close();
          SpeechUI.SendTextFeedback(eventArgs.Result, "Invalid Password", false);
        }
      }
    };

  grammar.Enabled = true;
  _recognizer.LoadGrammar(grammar);
  UpdateGrammarTree(_grammarTreeView, _recognizer);

}

注釈

暗黙的な変換のため、 引数はbuilders、、SemanticResultKeyChoicesおよび String オブジェクトもサポートしていますSemanticResultValue。 暗黙的な変換の詳細については、「」を参照してください Implicit

認識操作を実行する場合、 GrammarBuilder 引数に builders 指定されたオブジェクトはシーケンシャルとして扱われます。 たとえば、次 SemanticResultValue の を使用して を構築 Grammarする場合、認識エンジンへの入力には、認識される順番に "速い茶色のキツネ" という単語が含まれている必要があります。

SemanticResultKey stringTest=new SemanticResultKey(
    "stringTest", new GrammarBuilder[] {
    new GrammarBuilder("the"),
    new GrammarBuilder("quick"),
    new GrammarBuilder("brown"),
    new GrammarBuilder("fox")});

引数には semanticResultKey 、返される可能性がある にアクセス SemanticValue するために使用されるタグが含まれています。

SemanticValueValue、 パラメーターによってGrammarBuilder提供されるインスタンスによってbuilders決定されます。

オブジェクトに GrammarBuilder の定義インスタンス SemanticResultValueが含まれない場合、 の SemanticValue 値は です null

パラメーターに指定されたGrammarBuilderオブジェクトが、認識ロジックでbuilders使用されるタグなし (オブジェクトに関連付SemanticResultKeyけられていない) SemanticResultValue インスタンスを提供する場合、 のSemanticResultValueインスタンスによって生成される のSemanticValueプロパティが定義Valueされます。

パラメーターでbuilders指定されたオブジェクトには、タグなしSemanticResultValueインスタンスGrammarBuilderが 1 つだけ存在する必要があります。 タグなしの複数のインスタンスが に SemanticResultValue 関連付 SemanticResultKeyけられている場合、それぞれが認識結果で生成された の値を SemanticValue 設定しようとします。 これは許可されておらず、このようなインスタンスを使用して作成された を使用 Grammar しようとすると、認識エンジンによって例外が SemanticResultKey 生成されます。

SemanticResultValueパラメーターでbuilders指定され、既にGrammarBuilderSemanticResultKeyの オブジェクトに関連付けられている のインスタンスは、現在SemanticResultKeyのインスタンスには影響しません。

適用対象

SemanticResultKey(String, String[])

ソース:
SemanticResultKey.cs
ソース:
SemanticResultKey.cs
ソース:
SemanticResultKey.cs

音声認識文法を作成するために使用される 1 つ以上の String インスタンスにセマンティクス キーを割り当てます。

public:
 SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::String ^> ^ phrases);
public SemanticResultKey (string semanticResultKey, params string[] phrases);
new System.Speech.Recognition.SemanticResultKey : string * string[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray phrases As String())

パラメーター

semanticResultKey
String

phrases 引数が指定する String オブジェクトによって関連付けられた SemanticValue インスタンスにアクセスするために使用するタグ。

phrases
String[]

連結されたテキストが semanticResultKey で定義されているタグでアクセス可能な String オブジェクトに関連付けられている、1 つ以上の SemanticValue オブジェクト。

次の例では、 Grammar オブジェクトのGrammarBuilder配列Stringによって定義される をSemanticResultKey使用する オブジェクトから を作成します。

作成された を使用する Grammar 認識エンジンは、"赤い緑の青 0" という語句を認識します。 認識によって返される のRecognizedPhraseセマンティクスには、"赤い緑色の青" の がValue含まれますSemanticValue。 には、"code" タグを使用してアクセス SemanticValue できます。

SemanticResultValue("zero", 5)GrammarBuilderが追加されているため、 のルート SemanticValue オブジェクトRecognizedPhraseの値は 5 になります。

private void keyTest()
{
  // Say "color red green blue zero"
  GrammarBuilder gb = new GrammarBuilder("color") +
                        new SemanticResultKey("code",
                          (new string[] {"red", "green", "blue"})) +
                        new SemanticResultValue("zero", 5);
  Grammar g = new Grammar(gb);
  g.Name = "keyTest";
  _recognizer.LoadGrammar(g);
}

注釈

認識操作を実行する場合、 パラメーターでphrases使用されるStringオブジェクトはシーケンシャルとして扱われます。 たとえば、次 SemanticResultValue の を使用して を構築 Grammarする場合、認識エンジンへの入力には、認識される順番に "速い茶色のキツネ" という単語が含まれている必要があります。

SemanticResultKey stringTest=new SemanticResultKey("stringTest",
                                new string[] {
                                               "the",
                                               "quick",
                                               "brown",
                                               "fox"});

引数は semanticResultKey 、返される可能性がある にアクセス SemanticValue するために使用されるキーを決定します。

文字列オブジェクトのGrammar配列をGrammarBuilder持つセマンティック キーを含む オブジェクトを使用して を構築する場合、SemanticValueValue認識操作によって生成される の は、認識で使用される文字列になります。 前の例では、これは Value "速い茶色のキツネ" であることを意味します。

適用対象