GrammarBuilder.Append メソッド

定義

文法要素の現在のシーケンスに文法要素を追加します。

オーバーロード

Append(String, Int32, Int32)

文法要素の現在のシーケンスに繰り返される語句を追加します。

Append(GrammarBuilder, Int32, Int32)

文法要素の現在のシーケンスに繰り返される文法要素を追加します。

Append(String)

文法要素の現在のシーケンスに語句を追加します。

Append(String, SubsetMatchingMode)

文法要素の現在のシーケンスに、語句のサブセットの要素を追加します。

Append(SemanticResultKey)

文法要素の現在のシーケンスにセマンティクス キーを追加します。

Append(SemanticResultValue)

文法要素の現在のシーケンスにセマンティクス値を追加します。

Append(GrammarBuilder)

文法要素の現在のシーケンスに文法要素を追加します。

Append(Choices)

文法要素の現在のシーケンスに代替のセットを追加します。

注釈

既存 GrammarBuilderの に文法要素を追加するには、これらのメソッドを使用します。 文法要素を作成するときに、既存のビルダーに追加して、音声認識文法の制約を段階的に開発できます。 各要素は、現在の要素シーケンスの末尾に追加されます。

このメソッドには、、SemanticResultKeyStringChoicesおよび SemanticResultValue オブジェクトをGrammarBuilder追加するためのオーバーロードがあります。

重要

同じキー名を持つ重複するセマンティック要素または同じセマンティック要素の値を繰り返し変更できる複数のセマンティック要素を含む音声認識文法を使用すると、音声認識エンジンは例外をスローできます。

音声認識文法の構築と使用の詳細については、「 音声認識」を参照してください。

Append(String, Int32, Int32)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに繰り返される語句を追加します。

public:
 void Append(System::String ^ phrase, int minRepeat, int maxRepeat);
public void Append (string phrase, int minRepeat, int maxRepeat);
member this.Append : string * int * int -> unit
Public Sub Append (phrase As String, minRepeat As Integer, maxRepeat As Integer)

パラメーター

phrase
String

追加する繰り返される言葉のシーケンス。

minRepeat
Int32

phrase と一致する入力が、一致を構成するために発生する必要がある最小回数。

maxRepeat
Int32

phrase と一致する入力が、一致を構成するために発生できる最大回数。

次の例では、"Call James at work" や "Call Anne on her cell phone" などの語句の音声認識文法を作成します。ここで、"phone" という単語は省略可能です。 GrammarBuilder および Choices オブジェクトは、文法を構築するために使用されます。 この例では、 メソッドの使用が Append 強調表示されています。

public static Grammar CreatePhonePhrase()
{
  // Create alternatives for person names, locations, devices, and pronouns.
  Choices personChoice = new Choices(new string[] {"Anne", "James", "Mary", "Sam"});
  Choices locationChoice = new Choices(new string[] {"home", "work"});
  Choices deviceChoice = new Choices(new string[] {"home", "work", "cell"});
  Choices pronounChoice = new Choices(new string[] {"his", "her"});

  // Create a phrase for the receiving device, which optionally contains the word "phone".
  GrammarBuilder devicePhrase = new GrammarBuilder(pronounChoice);
  devicePhrase.Append(deviceChoice);
  devicePhrase.Append("phone", 0, 1);

  // Create alternatives for phrases specifying a device or a location.
  GrammarBuilder atLocation = new GrammarBuilder("at");
  atLocation.Append(locationChoice);

  GrammarBuilder onDevice = new GrammarBuilder("on");
  onDevice.Append(devicePhrase);

  Choices howChoice = new Choices(new GrammarBuilder[] {atLocation, onDevice});

  // Build the final phrase.
  GrammarBuilder callWho = new GrammarBuilder("Call");
  callWho.Append(personChoice);
  callWho.Append(howChoice);

  // Create the Grammar object.
  Grammar callGrammar = new Grammar(callWho);
  callGrammar.Name = "Call Grammar";

  return callGrammar;
}

注釈

minRepeat 値は、0 以上で、 の値 maxRepeat以下である必要があります。

こちらもご覧ください

適用対象

Append(GrammarBuilder, Int32, Int32)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに繰り返される文法要素を追加します。

public:
 void Append(System::Speech::Recognition::GrammarBuilder ^ builder, int minRepeat, int maxRepeat);
public void Append (System.Speech.Recognition.GrammarBuilder builder, int minRepeat, int maxRepeat);
member this.Append : System.Speech.Recognition.GrammarBuilder * int * int -> unit
Public Sub Append (builder As GrammarBuilder, minRepeat As Integer, maxRepeat As Integer)

パラメーター

builder
GrammarBuilder

追加する繰り返される文法要素。

minRepeat
Int32

builder によって定義される要素と一致する入力が、一致を構成するために発生する必要がある最小回数。

maxRepeat
Int32

builder によって定義される要素と一致する入力が、一致を構成するために発生できる最大回数。

次の例では、"Call James at work" や "Call Anne on her cell phone" などの語句の音声認識文法を作成します。ここで、"phone" という単語は省略可能です。 GrammarBuilder および Choices オブジェクトは、文法を構築するために使用されます。 この例では、 メソッドの使用が Append 強調表示されています。

public static Grammar CreatePhonePhrase()
{
  // Create alternatives for person names, locations, devices, and pronouns.
  Choices personChoice = new Choices(new string[] {"Anne", "James", "Mary", "Sam"});
  Choices locationChoice = new Choices(new string[] {"home", "work"});
  Choices deviceChoice = new Choices(new string[] {"home", "work", "cell"});
  Choices pronounChoice = new Choices(new string[] {"his", "her"});

  // Create a phrase for the receiving device, which optionally contains the word "phone".
  GrammarBuilder devicePhrase = new GrammarBuilder(pronounChoice);
  devicePhrase.Append(deviceChoice);
  devicePhrase.Append("phone", 0, 1);

  // Create alternatives for phrases specifying a device or a location.
  GrammarBuilder atLocation = new GrammarBuilder("at");
  atLocation.Append(locationChoice);

  GrammarBuilder onDevice = new GrammarBuilder("on");
  onDevice.Append(devicePhrase);

  Choices howChoice = new Choices(new GrammarBuilder[] {atLocation, onDevice});

  // Build the final phrase.
  GrammarBuilder callWho = new GrammarBuilder("Call");
  callWho.Append(personChoice);
  callWho.Append(howChoice);

  // Create the Grammar object.
  Grammar callGrammar = new Grammar(callWho);
  callGrammar.Name = "Call Grammar";

  return callGrammar;
}

注釈

minRepeat 値は、0 以上で、 の値 maxRepeat以下である必要があります。

重要

または SemanticResultKey インスタンスを含むSemanticResultValueオブジェクトをオブジェクトにGrammarBuilder追加GrammarBuilderするときは、同じキー名またはオブジェクトのプロパティを繰り返し変更できる複数のSemanticValueセマンティック要素を使用して重複するセマンティック要素をValue作成しないようにしてください。 このような状況が発生した場合、音声認識エンジンは例外をスローできます。

こちらもご覧ください

適用対象

Append(String)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに語句を追加します。

public:
 void Append(System::String ^ phrase);
public void Append (string phrase);
member this.Append : string -> unit
Public Sub Append (phrase As String)

パラメーター

phrase
String

追加する言葉のシーケンス。

注釈

phrase は、現在の要素シーケンスの末尾に追加されます。

こちらもご覧ください

適用対象

Append(String, SubsetMatchingMode)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに、語句のサブセットの要素を追加します。

public:
 void Append(System::String ^ phrase, System::Speech::Recognition::SubsetMatchingMode subsetMatchingCriteria);
public void Append (string phrase, System.Speech.Recognition.SubsetMatchingMode subsetMatchingCriteria);
member this.Append : string * System.Speech.Recognition.SubsetMatchingMode -> unit
Public Sub Append (phrase As String, subsetMatchingCriteria As SubsetMatchingMode)

パラメーター

phrase
String

追加する言葉のシーケンス。

subsetMatchingCriteria
SubsetMatchingMode

句を認識するために文法が使用する一致モード。

次の例では、値ごとに SubsetMatchingMode 音声認識文法を作成します。 たとえば、生成された文法 OrderedSubset では、"3 つの 4 つの 5" と "1 つの 3 つの 5" という語句が認識され、文法 Subsequence は "3 つの 4 つの 5" という語句を認識しますが、"1 つの 3 つの 5" という語句は認識しません。

private Grammar[] CreateSubsetMatchTest()
{
  List<Grammar> grammars = new List<Grammar>(4);

  string phrase = "one two three four five six";
  foreach (SubsetMatchingMode mode in
    Enum.GetValues(typeof(SubsetMatchingMode)))
  {
    GrammarBuilder gb = new GrammarBuilder();
    gb.Append(phrase, mode);

    Grammar grammar = new Grammar(gb);
    grammar.Name = mode.ToString();
    grammars.Add(grammar);
  }

  return grammars.ToArray();
}

注釈

subset 要素は、現在の要素シーケンスの末尾に追加されます。 文字列を使用した音声認識文法の構築の詳細については、「文字列を 使用した GrammarBuilder 文法の作成」を参照してください。

サブセット一致モードの使用の詳細については、「」を参照してください System.Speech.Recognition.SubsetMatchingMode

こちらもご覧ください

適用対象

Append(SemanticResultKey)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスにセマンティクス キーを追加します。

public:
 void Append(System::Speech::Recognition::SemanticResultKey ^ key);
public void Append (System.Speech.Recognition.SemanticResultKey key);
member this.Append : System.Speech.Recognition.SemanticResultKey -> unit
Public Sub Append (key As SemanticResultKey)

パラメーター

key
SemanticResultKey

追加するセマンティクス キー。

次の例は、フライトの出発地と目的地の都市を選択するためのコンソール アプリケーションの一部です。 アプリケーションは、"マイアミからシカゴに飛びたい" などのフレーズを認識します。イベントのハンドラーは、 SpeechRecognizedSemanticResultKey 使用して、出発地と目的地の都市に対して で SemanticResultValue 指定された空港コードを抽出します。

using System;
using System.Speech.Recognition;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize an in-process speech recognition engine.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine())
      {

        // Create a Choices object and add  cities and airport codes
        // using SemanticResultValue objects.
        Choices cities = new Choices();
        cities.Add(new SemanticResultValue("Chicago", "ORD"));
        cities.Add(new SemanticResultValue("Boston", "BOS"));
        cities.Add(new SemanticResultValue("Miami", "MIA"));
        cities.Add(new SemanticResultValue("Dallas", "DFW"));

        // Build the phrase and add SemanticResultKeys.
        GrammarBuilder chooseCities = new GrammarBuilder();
        chooseCities.Append("I want to fly from");
        chooseCities.Append(new SemanticResultKey("origin", cities));
        chooseCities.Append("to");
        chooseCities.Append(new SemanticResultKey("destination", cities));

        // Build a Grammar object from the GrammarBuilder.
        Grammar bookFlight = new Grammar(chooseCities);
        bookFlight.Name = "Book Flight";

        // 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);

        // Configure the input to the recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        // Load the grammar object and start recognition.
        recognizer.LoadGrammarAsync(bookFlight);
        recognizer.RecognizeAsync();

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

    // Handle the LoadGrammarCompleted event.
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
    {
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
      Console.WriteLine();
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Speech recognized:  " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);
    }
  }
}

注釈

key は、現在の要素シーケンスの末尾に追加されます。

重要

オブジェクトに インスタンスまたは SemanticResultKey インスタンスをGrammarBuilder追加SemanticResultValueするときは、同じキー名またはオブジェクトのプロパティを繰り返し変更できる複数のSemanticValueセマンティック要素を使用して重複するセマンティック要素をValue作成しないようにしてください。 このような状況が発生した場合、音声認識エンジンは例外をスローできます。

こちらもご覧ください

適用対象

Append(SemanticResultValue)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスにセマンティクス値を追加します。

public:
 void Append(System::Speech::Recognition::SemanticResultValue ^ value);
public void Append (System.Speech.Recognition.SemanticResultValue value);
member this.Append : System.Speech.Recognition.SemanticResultValue -> unit
Public Sub Append (value As SemanticResultValue)

パラメーター

value
SemanticResultValue

追加するセマンティクス値。

次の例は、フライトの出発地と目的地の都市を選択するためのコンソール アプリケーションの一部です。 アプリケーションは、"マイアミからシカゴに飛びたい" などのフレーズを認識します。イベントのハンドラーは、 SpeechRecognizedSemanticResultKey 使用して、出発地と目的地の都市に対して で SemanticResultValue 指定された空港コードを抽出します。

using System;
using System.Speech.Recognition;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize an in-process speech recognition engine.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine())
      {

        // Create GrammarBuilder objects and append SemanticResultValue objects
        // that contain cities and airport codes.

        GrammarBuilder chicago = new GrammarBuilder();
        chicago.Append(new SemanticResultValue("Chicago", "ORD"));

        GrammarBuilder boston = new GrammarBuilder();
        boston.Append(new SemanticResultValue("Boston", "BOS"));

        GrammarBuilder miami = new GrammarBuilder();
        miami.Append(new SemanticResultValue("Miami", "MIA"));

        GrammarBuilder dallas = new GrammarBuilder();
        dallas.Append(new SemanticResultValue("Dallas", "DFW"));

        // Create a Choices object and add the cities using implicit conversion from
        // SemanticResultValue to GrammarBuilder.
        Choices cities = new Choices();
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

        // Build the phrase and add SemanticResultKeys.
        GrammarBuilder chooseCities = new GrammarBuilder();
        chooseCities.Append("I want to fly from");
        chooseCities.Append(new SemanticResultKey("origin", cities));
        chooseCities.Append("to");
        chooseCities.Append(new SemanticResultKey("destination", cities));

        // Build a Grammar object from the GrammarBuilder.
        Grammar bookFlight = new Grammar(chooseCities);
        bookFlight.Name = "Book Flight";

        // 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);

        // Configure the input to the recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        // Load the grammar object and start recognition.
        recognizer.LoadGrammarAsync(bookFlight);
        recognizer.RecognizeAsync();

        // Keep the console window open.
        Console.ReadLine();
      }
    }
    // Handle the LoadGrammarCompleted event.
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
    {
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
      Console.WriteLine();
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Speech recognized:  " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);
    }
  }
}

注釈

value は、現在の要素シーケンスの末尾に追加されます。

重要

オブジェクトに インスタンスまたは SemanticResultKey インスタンスをGrammarBuilder追加SemanticResultValueするときは、同じキー名またはオブジェクトのプロパティを繰り返し変更できる複数のSemanticValueセマンティック要素を使用して重複するセマンティック要素をValue作成しないようにしてください。 このような状況が発生した場合、音声認識エンジンは例外をスローできます。

こちらもご覧ください

適用対象

Append(GrammarBuilder)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに文法要素を追加します。

public:
 void Append(System::Speech::Recognition::GrammarBuilder ^ builder);
public void Append (System.Speech.Recognition.GrammarBuilder builder);
member this.Append : System.Speech.Recognition.GrammarBuilder -> unit
Public Sub Append (builder As GrammarBuilder)

パラメーター

builder
GrammarBuilder

追加する文法要素。

次の例では、"Call James at work" や "Call Anne on her cell phone" などの語句の音声認識文法を作成します。ここで、"phone" という単語は省略可能です。 GrammarBuilder および Choices オブジェクトは、文法を構築するために使用されます。 この例では、 メソッドの使用が Append 強調表示されています。

public static Grammar CreatePhonePhrase()
{
  // Create alternatives for person names, locations, devices, and pronouns.
  Choices personChoice = new Choices(new string[] {"Anne", "James", "Mary", "Sam"});
  Choices locationChoice = new Choices(new string[] {"home", "work"});
  Choices deviceChoice = new Choices(new string[] {"home", "work", "cell"});
  Choices pronounChoice = new Choices(new string[] {"his", "her"});

  // Create a phrase for the receiving device, which optionally contains the word "phone".
  GrammarBuilder devicePhrase = new GrammarBuilder(pronounChoice);
  devicePhrase.Append(deviceChoice);
  devicePhrase.Append("phone", 0, 1);

  // Create alternatives for phrases specifying a device or a location.
  GrammarBuilder atLocation = new GrammarBuilder("at");
  atLocation.Append(locationChoice);

  GrammarBuilder onDevice = new GrammarBuilder("on");
  onDevice.Append(devicePhrase);

  Choices howChoice = new Choices(new GrammarBuilder[] {atLocation, onDevice});

  // Build the final phrase.
  GrammarBuilder callWho = new GrammarBuilder("Call");
  callWho.Append(personChoice);
  callWho.Append(howChoice);

  // Create the Grammar object.
  Grammar callGrammar = new Grammar(callWho);
  callGrammar.Name = "Call Grammar";

  return callGrammar;
}

注釈

builder は、文法要素の現在のシーケンスの末尾に追加されます。

注意

または SemanticResultKey インスタンスを含むSemanticResultValueオブジェクトをオブジェクトにGrammarBuilder追加GrammarBuilderするときは、同じキー名またはオブジェクトのプロパティを繰り返し変更できる複数のSemanticValueセマンティック要素を使用して重複するセマンティック要素をValue作成しないようにしてください。 このような状況が発生した場合、音声認識エンジンは例外をスローできます。

こちらもご覧ください

適用対象

Append(Choices)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

文法要素の現在のシーケンスに代替のセットを追加します。

public:
 void Append(System::Speech::Recognition::Choices ^ alternateChoices);
public void Append (System.Speech.Recognition.Choices alternateChoices);
member this.Append : System.Speech.Recognition.Choices -> unit
Public Sub Append (alternateChoices As Choices)

パラメーター

alternateChoices
Choices

追加する代替のセット。

次の例では、"Call James at work" や "Call Anne on her cell phone" などの語句の音声認識文法を作成します。ここで、"phone" という単語は省略可能です。 この例では、 メソッドの使用が Append 強調表示されています。

public static Grammar CreatePhonePhrase()
{
  // Create alternatives for person names, locations, devices, and pronouns.
  Choices personChoice = new Choices(new string[] {"Anne", "James", "Mary", "Sam"});
  Choices locationChoice = new Choices(new string[] {"home", "work"});
  Choices deviceChoice = new Choices(new string[] {"home", "work", "cell"});
  Choices pronounChoice = new Choices(new string[] {"his", "her"});

  // Create a phrase for the receiving device, which optionally contains the word "phone".
  GrammarBuilder devicePhrase = new GrammarBuilder(pronounChoice);
  devicePhrase.Append(deviceChoice);
  devicePhrase.Append("phone", 0, 1);

  // Create alternatives for phrases specifying a device or a location.
  GrammarBuilder atLocation = new GrammarBuilder("at");
  atLocation.Append(locationChoice);

  GrammarBuilder onDevice = new GrammarBuilder("on");
  onDevice.Append(devicePhrase);

  Choices howChoice = new Choices(new GrammarBuilder[] {atLocation, onDevice});

  // Build the final phrase.
  GrammarBuilder callWho = new GrammarBuilder("Call");
  callWho.Append(personChoice);
  callWho.Append(howChoice);

  // Create the Grammar object.
  Grammar callGrammar = new Grammar(callWho);
  callGrammar.Name = "Call Grammar";

  return callGrammar;
}

注釈

alternateChoices は、現在の要素シーケンスの末尾に追加されます。

重要

または SemanticResultKey インスタンスを含むSemanticResultValueオブジェクトをオブジェクトにGrammarBuilder追加Choicesするときは、同じキー名またはオブジェクトのプロパティを繰り返し変更できる複数のSemanticValueセマンティック要素を使用して重複するセマンティック要素をValue作成しないようにしてください。 このような状況が発生した場合、音声認識エンジンは例外をスローできます。

適用対象