GrammarBuilder.Append GrammarBuilder.Append GrammarBuilder.Append GrammarBuilder.Append Method

定義

文法要素の現在のシーケンスに文法要素を追加します。Appends a grammar element to the current sequence of grammar elements.

オーバーロード

Append(String, Int32, Int32) Append(String, Int32, Int32) Append(String, Int32, Int32) Append(String, Int32, Int32)

文法要素の現在のシーケンスに繰り返される語句を追加します。Appends a repeated phrase to the current sequence of grammar elements.

Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32)

文法要素の現在のシーケンスに繰り返される文法要素を追加します。Appends a repeated grammar element to the current sequence of grammar elements.

Append(String) Append(String) Append(String) Append(String)

文法要素の現在のシーケンスに語句を追加します。Appends a phrase to the current sequence of grammar elements.

Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode)

文法要素の現在のシーケンスに、語句のサブセットの要素を追加します。Appends an element for a subset of a phrase to the current sequence of grammar elements.

Append(SemanticResultKey) Append(SemanticResultKey) Append(SemanticResultKey) Append(SemanticResultKey)

文法要素の現在のシーケンスにセマンティクス キーを追加します。Appends a semantic key to the current sequence of grammar elements.

Append(SemanticResultValue) Append(SemanticResultValue) Append(SemanticResultValue) Append(SemanticResultValue)

文法要素の現在のシーケンスにセマンティクス値を追加します。Appends a semantic value to the current sequence of grammar elements.

Append(GrammarBuilder) Append(GrammarBuilder) Append(GrammarBuilder) Append(GrammarBuilder)

文法要素の現在のシーケンスに文法要素を追加します。Appends a grammar element to the current sequence of grammar elements.

Append(Choices) Append(Choices) Append(Choices) Append(Choices)

文法要素の現在のシーケンスに代替のセットを追加します。Appends a set of alternatives to the current sequence of grammar elements.

注釈

これらのメソッドを使用すると、既存の文法要素を追加するGrammarBuilderします。Use these methods to append grammar elements to an existing GrammarBuilder. 文法要素を作成するときは、音声認識文法の制約を段階的に開発する既存のビルダーに追加できます。As you create grammar elements, you can append them to the existing builder to progressively develop the constraints for a speech recognition grammar. 各要素は、要素の現在のシーケンスの末尾に追加されます。Each element is added to the end of the current sequence of elements.

このメソッドに追加するためのオーバー ロードはGrammarBuilderStringChoicesSemanticResultKey、およびSemanticResultValueオブジェクト。This method has overloads for appending GrammarBuilder, String, Choices, SemanticResultKey, and SemanticResultValue objects.

重要

同じキー名の重複するセマンティック要素または繰り返し同じ意味を持つ要素の値を変更する複数のセマンティック要素が含まれている音声認識文法を使用する場合、音声認識エンジンは例外をスローできます。The speech recognizer can throw an exception when using a speech recognition grammar that contains duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the value of the same semantic element.

ビルドと音声認識文法の使用に関する詳細については、次を参照してください。音声認識GrammarBuilder 文法の作成です。For more information about building and using speech recognition grammars, see Speech Recognition and Creating GrammarBuilder Grammars.

Append(String, Int32, Int32) Append(String, Int32, Int32) Append(String, Int32, Int32) Append(String, Int32, Int32)

文法要素の現在のシーケンスに繰り返される語句を追加します。Appends a repeated phrase to the current sequence of grammar elements.

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 String String String

追加する繰り返される言葉のシーケンス。The repeated sequence of words to append.

minRepeat
Int32 Int32 Int32 Int32

phrase と一致する入力が、一致を構成するために発生する必要がある最小回数。The minimum number of times that input matching phrase must occur to constitute a match.

maxRepeat
Int32 Int32 Int32 Int32

phrase と一致する入力が、一致を構成するために発生できる最大回数。The maximum number of times that input matching phrase can occur to constitute a match.

次の例では、"phone"という単語が省略可能な"職場呼び出し James"や"で、携帯電話の呼び出し Anne"などの語句の音声認識文法を作成します。The following example creates a speech recognition grammar for phrases such as "Call James at work" and "Call Anne on her cell phone", where the word "phone" is optional. GrammarBuilder Choicesオブジェクトは、文法の構築に使用します。GrammarBuilder and Choices objects are used to construct the grammar. この例の使用を強調表示、Appendメソッド。The example highlights the use of the Append method.


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

注釈

minRepeat0 以上にする必要がありますの値以下maxRepeatします。The value of minRepeat must be greater than or equal to 0 and less than or equal to the value of maxRepeat.

こちらもご覧ください

Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32) Append(GrammarBuilder, Int32, Int32)

文法要素の現在のシーケンスに繰り返される文法要素を追加します。Appends a repeated grammar element to the current sequence of grammar elements.

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 GrammarBuilder GrammarBuilder GrammarBuilder

追加する繰り返される文法要素。The repeated grammar element to append.

minRepeat
Int32 Int32 Int32 Int32

builder によって定義される要素と一致する入力が、一致を構成するために発生する必要がある最小回数。The minimum number of times that input matching the element defined by builder must occur to constitute a match.

maxRepeat
Int32 Int32 Int32 Int32

builder によって定義される要素と一致する入力が、一致を構成するために発生できる最大回数。The maximum number of times that input matching the element defined by builder can occur to constitute a match.

次の例では、"phone"という単語が省略可能な"職場呼び出し James"や"で、携帯電話の呼び出し Anne"などの語句の音声認識文法を作成します。The following example creates a speech recognition grammar for phrases such as "Call James at work" and "Call Anne on her cell phone", where the word "phone" is optional. GrammarBuilder Choicesオブジェクトは、文法の構築に使用します。GrammarBuilder and Choices objects are used to construct the grammar. この例の使用を強調表示、Appendメソッド。The example highlights the use of the Append method.


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

注釈

minRepeat0 以上にする必要がありますの値以下maxRepeatします。The value of minRepeat must be greater than or equal to 0 and less than or equal to the value of maxRepeat.

重要

追加するとGrammarBuilderオブジェクトが含まれているSemanticResultValueまたはSemanticResultKeyインスタンスをGrammarBuilderオブジェクトの繰り返し可能性のある複数のセマンティック要素または同じキー名に重複するセマンティック要素を作成しないようにするかどうかを確認してください変更、ValueのプロパティをSemanticValueオブジェクト。When you append GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances to a GrammarBuilder object, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. 音声認識エンジンは、このような状況が発生した場合、例外をスローできます。The speech recognizer can throw an exception if it encounters these circumstances.

こちらもご覧ください

Append(String) Append(String) Append(String) Append(String)

文法要素の現在のシーケンスに語句を追加します。Appends a phrase to the current sequence of grammar elements.

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

パラメーター

phrase
String String String String

追加する言葉のシーケンス。The sequence of words to append.

注釈

phrase 要素の現在のシーケンスの末尾に追加されます。phrase is added to the end of the current sequence of elements.

こちらもご覧ください

Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode) Append(String, SubsetMatchingMode)

文法要素の現在のシーケンスに、語句のサブセットの要素を追加します。Appends an element for a subset of a phrase to the current sequence of grammar elements.

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 String String String

追加する言葉のシーケンス。The sequence of words to append.

subsetMatchingCriteria
SubsetMatchingMode SubsetMatchingMode SubsetMatchingMode SubsetMatchingMode

句を認識するために文法が使用する一致モード。The matching mode the grammar uses to recognize the phrase.

次の例は、それぞれの音声認識文法を作成SubsetMatchingMode値。The following example creates a speech recognition grammar for each SubsetMatchingMode value. 生成された文法などOrderedSubset、フレーズを認識"3 つ 4 つ 5"と"1 つ 3 つ 5"と文章校正Subsequenceというフレーズを認識"3 つ 4 つ 5 つ"、語句が、"1 つ次の 3 つ 5 つ"。For example, the generated grammar OrderedSubset recognizes the phrases, "three four five" and "one three five", and the grammar Subsequence recognizes the phrase "three four five", but not the phrase, "one three five".


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

注釈

サブセットの要素は、要素の現在のシーケンスの末尾に追加されます。The subset element is added to the end of the current sequence of elements. 文字列を使用して、音声認識文法のビルドの詳細については、次を参照してください。 GrammarBuilder 文法を作成するのを使用して文字列します。For more information about building a speech recognition grammar using strings, see Using Strings to Create a GrammarBuilder Grammar.

サブセットの一致のモードの使用に関する詳細については、次を参照してください。System.Speech.Recognition.SubsetMatchingModeします。For detailed information on the use of subset matching modes, see System.Speech.Recognition.SubsetMatchingMode.

こちらもご覧ください

Append(SemanticResultKey) Append(SemanticResultKey) Append(SemanticResultKey) Append(SemanticResultKey)

文法要素の現在のシーケンスにセマンティクス キーを追加します。Appends a semantic key to the current sequence of grammar elements.

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 SemanticResultKey SemanticResultKey SemanticResultKey

追加するセマンティクス キー。The semantic key to append.

次の例は、送信元と送信先の都市でフライトを選択するためのコンソール アプリケーションの一部です。The following example is part of a console application for choosing origin and destination cities for a flight. アプリケーション「たいシカゴにマイアミから飛行」など、語句が認識します。The application recognizes phrases such as "I want to fly from Miami to Chicago." ハンドラーは、SpeechRecognizedイベントを使用して、SemanticResultKeyで指定された空港コードを抽出する、SemanticResultValue送信元と送信先の都市。The handler for the SpeechRecognized event uses the SemanticResultKey to extract the airport code specified in the SemanticResultValue for the origin and destination cities.

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 要素の現在のシーケンスの末尾に追加されます。key is added to the end of the current sequence of elements.

重要

追加するとSemanticResultValueまたはSemanticResultKeyインスタンスをGrammarBuilderオブジェクト、または同じキー名が繰り返しを変更する複数のセマンティック要素に重複するセマンティック要素を作成しないようにすることを確認、ValueのプロパティをSemanticValueオブジェクト。When you append SemanticResultValue or SemanticResultKey instances to a GrammarBuilder object, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. 音声認識エンジンは、このような状況が発生した場合、例外をスローできます。The speech recognizer can throw an exception if it encounters these circumstances.

こちらもご覧ください

Append(SemanticResultValue) Append(SemanticResultValue) Append(SemanticResultValue) Append(SemanticResultValue)

文法要素の現在のシーケンスにセマンティクス値を追加します。Appends a semantic value to the current sequence of grammar elements.

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 SemanticResultValue SemanticResultValue SemanticResultValue

追加するセマンティクス値。The semantic value to append.

次の例は、送信元と送信先の都市でフライトを選択するためのコンソール アプリケーションの一部です。The following example is part of a console application for choosing origin and destination cities for a flight. アプリケーション「たいシカゴにマイアミから飛行」など、語句が認識します。The application recognizes phrases such as "I want to fly from Miami to Chicago." ハンドラーは、SpeechRecognizedイベントを使用して、SemanticResultKeyで指定された空港コードを抽出する、SemanticResultValue送信元と送信先の都市。The handler for the SpeechRecognized event uses the SemanticResultKey to extract the airport code specified in the SemanticResultValue for the origin and destination cities.


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 要素の現在のシーケンスの末尾に追加されます。value is added to the end of the current sequence of elements.

重要

追加するとSemanticResultValueまたはSemanticResultKeyインスタンスをGrammarBuilderオブジェクト、または同じキー名が繰り返しを変更する複数のセマンティック要素に重複するセマンティック要素を作成しないようにすることを確認、ValueのプロパティをSemanticValueオブジェクト。When you append SemanticResultValue or SemanticResultKey instances to a GrammarBuilder object, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. 音声認識エンジンは、このような状況が発生した場合、例外をスローできます。The speech recognizer can throw an exception if it encounters these circumstances.

こちらもご覧ください

Append(GrammarBuilder) Append(GrammarBuilder) Append(GrammarBuilder) Append(GrammarBuilder)

文法要素の現在のシーケンスに文法要素を追加します。Appends a grammar element to the current sequence of grammar elements.

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 GrammarBuilder GrammarBuilder GrammarBuilder

追加する文法要素。The grammar element to append.

次の例では、"phone"という単語が省略可能な"職場呼び出し James"や"で、携帯電話の呼び出し Anne"などの語句の音声認識文法を作成します。The following example creates a speech recognition grammar for phrases such as "Call James at work" and "Call Anne on her cell phone", where the word "phone" is optional. GrammarBuilder Choicesオブジェクトは、文法の構築に使用します。GrammarBuilder and Choices objects are used to construct the grammar. この例の使用を強調表示、Appendメソッド。The example highlights the use of the Append method.


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 文法要素の現在のシーケンスの末尾に追加されます。builder is added to the end of the current sequence of grammar elements.

注意

追加するとGrammarBuilderオブジェクトが含まれているSemanticResultValueまたはSemanticResultKeyインスタンスをGrammarBuilderオブジェクトの繰り返し可能性のある複数のセマンティック要素または同じキー名に重複するセマンティック要素を作成しないようにするかどうかを確認してください変更、ValueのプロパティをSemanticValueオブジェクト。When you append GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances to a GrammarBuilder object, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. 音声認識エンジンは、このような状況が発生した場合、例外をスローできます。The speech recognizer can throw an exception if it encounters these circumstances.

こちらもご覧ください

Append(Choices) Append(Choices) Append(Choices) Append(Choices)

文法要素の現在のシーケンスに代替のセットを追加します。Appends a set of alternatives to the current sequence of grammar elements.

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 Choices Choices Choices

追加する代替のセット。The set of alternatives to append.

次の例では、"phone"という単語が省略可能な"職場呼び出し James"や"で、携帯電話の呼び出し Anne"などの語句の音声認識文法を作成します。The following example creates a speech recognition grammar for phrases such as "Call James at work" and "Call Anne on her cell phone", where the word "phone" is optional. この例の使用を強調表示、Appendメソッド。The example highlights the use of the Append method.


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 要素の現在のシーケンスの末尾に追加されます。alternateChoices is added to the end of the current sequence of elements.

重要

追加するとChoicesオブジェクトが含まれているSemanticResultValueまたはSemanticResultKeyインスタンスをGrammarBuilderオブジェクトの繰り返し可能性のある複数のセマンティック要素または同じキー名に重複するセマンティック要素を作成しないようにするかどうかを確認してください変更、ValueのプロパティをSemanticValueオブジェクト。When you append Choices objects that contain SemanticResultValue or SemanticResultKey instances to a GrammarBuilder object, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. 音声認識エンジンは、このような状況が発生した場合、例外をスローできます。The speech recognizer can throw an exception if it encounters these circumstances.

適用対象