次の方法で共有


GrammarBuilder.Append メソッド

定義

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

オーバーロード

名前 説明
Append(String, Int32, Int32)

文法要素の現在のシーケンスに繰り返しフレーズを追加します。

Append(GrammarBuilder, Int32, Int32)

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

Append(String)

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

Append(String, SubsetMatchingMode)

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

Append(SemanticResultKey)

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

Append(SemanticResultValue)

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

Append(GrammarBuilder)

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

Append(Choices)

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

注釈

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

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

Important

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

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

Append(String, Int32, Int32)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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の値以下である必要があります。

Important

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

こちらもご覧ください

適用対象

Append(String)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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 は "three four five" という語句を認識しますが、"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();
}

注釈

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

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

こちらもご覧ください

適用対象

Append(SemanticResultKey)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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

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

次の例は、フライトの出発地と目的地を選択するためのコンソール アプリケーションの一部です。 アプリケーションは、"マイアミからシカゴに飛びたい" などの語句を認識します。 SpeechRecognized イベントのハンドラーは、 SemanticResultKey を使用して、出発地と目的地の都市の 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 は、現在の要素シーケンスの末尾に追加されます。

Important

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

こちらもご覧ください

適用対象

Append(SemanticResultValue)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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

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

次の例は、フライトの出発地と目的地を選択するためのコンソール アプリケーションの一部です。 アプリケーションは、"マイアミからシカゴに飛びたい" などの語句を認識します。 SpeechRecognized イベントのハンドラーは、 SemanticResultKey を使用して、出発地と目的地の都市の 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 は、現在の要素シーケンスの末尾に追加されます。

Important

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

こちらもご覧ください

適用対象

Append(GrammarBuilder)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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 は、文法要素の現在のシーケンスの末尾に追加されます。

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

こちらもご覧ください

適用対象

Append(Choices)

ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
GrammarBuilder.cs
ソース:
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 は、現在の要素シーケンスの末尾に追加されます。

Important

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

適用対象