Κοινή χρήση μέσω


Choices Constructors

Definition

Initializes a new instance of the Choices class.

Overloads

Choices()

Initializes a new instance of the Choices class that contains an empty set of alternatives.

Choices(GrammarBuilder[])

Initializes a new instance of the Choices class from an array containing one or more GrammarBuilder objects.

Choices(String[])

Initializes a new instance of the Choices class from an array containing one or more String objects.

Examples

The following example uses Choices objects to create two lists of alternatives.

The first Choices object is constructed from an array of String objects. The other Choices object is constructed from an array of GrammarBuilder objects which have been implicitly converted by a cast.

The example uses a GrammarBuilder object to assemble a phrase, using the Choices objects and two additional strings, that can be used to recognize speech input in the form of "Call [contactlList] on [phoneType] phone" , for example "Call Jane on cell phone".

public GrammarBuilder ChoicesConstructor2 ()  
{  
    GrammarBuilder gb = new GrammarBuilder ();  
    Choices phoneType = new Choices (new string[] {"cell", "home", "work"});  
    Choices contactList = new Choices (new GrammarBuilder[] {(GrammarBuilder) "Mark", (GrammarBuilder) "Jane", (GrammarBuilder) "Frank"});  
    gb.Append ("Call");  
    gb.Append (contactList);  
    gb.Append ("on");  
    gb.Append (phoneType);  
    gb.Append ("phone");  
    return gb;  
}  

Remarks

You can construct a Choices object using a parameterless constructor (which returns an empty object), from a group of String objects, or a from set of GrammarBuilder objects.

Because the GrammarBuilder object supports implicit conversion from SemanticResultValue and SemanticResultKey, a Choices can be constructed from an array of these objects using a cast.

Choices()

Source:
Choices.cs
Source:
Choices.cs
Source:
Choices.cs

Initializes a new instance of the Choices class that contains an empty set of alternatives.

public:
 Choices();
public Choices ();
Public Sub New ()

Examples

The following example uses Choices and GrammarBuilder objects to create a phrase that can be used to recognize speech input such as "Call Anne on her cell" and "Call James on his work phone". The example uses implicit casts from Choices and String to GrammarBuilder.

public Grammar CreatePhonePhrase()  
{  

  // Create alternatives for female names and add a phrase.  
  GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });  
  females.Append("on her");  

  // Create alternatives for male names and add a phrase.  
  GrammarBuilder males = new Choices(new string[] { "James", "Sam" });  
  males.Append("on his");  

  // Create a Choices object that contains an array of alternative  
  // GrammarBuilder objects.  
  Choices people = new Choices();  
  people.Add(new Choices(new GrammarBuilder[] {females, males}));  

  // Create a Choices object that contains a set of alternative phone types.  
  Choices phoneType = new Choices();  
  phoneType.Add(new string[] { "cell", "home", "work" });  

  // Construct the phrase.  
  GrammarBuilder gb = new GrammarBuilder();  
  gb.Append("call");  
  gb.Append(people);  
  gb.Append(phoneType);  
  gb.Append(new GrammarBuilder("phone"), 0, 1);  

  return new Grammar(gb);  
}  

Remarks

This constructor returns a valid, empty set of alternatives. You can add alternatives using any of the Add methods.

See also

Applies to

Choices(GrammarBuilder[])

Source:
Choices.cs
Source:
Choices.cs
Source:
Choices.cs

Initializes a new instance of the Choices class from an array containing one or more GrammarBuilder objects.

public:
 Choices(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);
public Choices (params System.Speech.Recognition.GrammarBuilder[] alternateChoices);
new System.Speech.Recognition.Choices : System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.Choices
Public Sub New (ParamArray alternateChoices As GrammarBuilder())

Parameters

alternateChoices
GrammarBuilder[]

An array containing the set of alternatives.

Examples

The following example uses Choices and GrammarBuilder objects to create a Grammar for phrases such as, "Call Anne on her cell" and "Call James on his work phone". The example uses implicit casts from Choices and String to GrammarBuilder.

public Grammar CreatePhonePhrase()  
{  

  // Create alternatives for female names and add a phrase.  
  GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });  
  females.Append("on her");  

  // Create alternatives for male names and add a phrase.  
  GrammarBuilder males = new Choices(new string[] { "James", "Sam" });  
  males.Append("on his");  

  // Create a Choices object that contains an array of alternative  
  // GrammarBuilder objects.  
  Choices people = new Choices();  
  people.Add(new Choices(new GrammarBuilder[] {females, males}));  

  // Create a Choices object that contains a set of alternative phone types.  
  Choices phoneType = new Choices();  
  phoneType.Add(new string[] { "cell", "home", "work" });  

  // Construct the phrase.  
  GrammarBuilder gb = new GrammarBuilder();  
  gb.Append("call");  
  gb.Append(people);  
  gb.Append(phoneType);  
  gb.Append(new GrammarBuilder("phone"), 0, 1);  

  return new Grammar(gb);  
}  

Remarks

Each GrammarBuilder in alternateChoices defines one alternative. If alternateChoices is an empty array, the constructor returns an empty set of alternatives. You can add alternatives using any of the Add methods.

The constructor throws an ArgumentNullException when alternateChoices is null or when any of the array elements are null.

Because the GrammarBuilder class provides support for implicit conversion of Choices, SemanticResultValue, and SemanticResultKey objects to GrammarBuilder instances, by properly using casts, this constructor can also be used to create a Choices object from a list of any combination of these objects.

See also

Applies to

Choices(String[])

Source:
Choices.cs
Source:
Choices.cs
Source:
Choices.cs

Initializes a new instance of the Choices class from an array containing one or more String objects.

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

Parameters

phrases
String[]

An array containing the set of alternatives.

Examples

The following example uses Choices and GrammarBuilder objects to create a Grammar for the phrases such as, "Call Anne on her cell" and "Call James on his work phone". The example uses implicit casts from Choices and String to GrammarBuilder.

public Grammar CreatePhonePhrase()  
{  

  // Create alternatives for female names and add a phrase.  
  GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });  
  females.Append("on her");  

  // Create alternatives for male names and add a phrase.  
  GrammarBuilder males = new Choices(new string[] { "James", "Sam" });  
  males.Append("on his");  

  // Create a Choices object that contains an array of alternative  
  // GrammarBuilder objects.  
  Choices people = new Choices();  
  people.Add(new Choices(new GrammarBuilder[] {females, males}));  

  // Create a Choices object that contains a set of alternative phone types.  
  Choices phoneType = new Choices();  
  phoneType.Add(new string[] { "cell", "home", "work" });  

  // Construct the phrase.  
  GrammarBuilder gb = new GrammarBuilder();  
  gb.Append("call");  
  gb.Append(people);  
  gb.Append(phoneType);  
  gb.Append(new GrammarBuilder("phone"), 0, 1);  

  return new Grammar(gb);  
}  

Remarks

Each String in phrases defines one alternative. The speech recognition engine can use any one of the items in the string array to match speech input. If phrases is an empty array, the constructor returns an empty set of alternatives. You can add alternatives using any of the Add methods.

The constructor throws an ArgumentNullException when phrases is null or any of the array elements are null. The constructor throws an ArgumentException if any element in the array is an empty string ("").

See also

Applies to