Choices Constructor (String[])
Constructs a new instance of Choices from one or more System.String instances.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Parameters
- phrases
One or more phrases containing in valid instances of System.String used to construct a new Choices object.
Remarks
The Choices created with this constructor defines a choice between one or more different System.String objects or phrases, such as a list of names, options, or colors.
Example
In this example a Grammar object is created which supports two commands to change colors "Set background to [color]" and "Change background to [color]".
Two Choices objects are created -- one (bothChoice)
is constructed from two GrammarBuilder objects containing an introductory phrase for a command ("Set background to" and "Change background to"), the other (colorChoice
) constructed from an array of color names System.String objects.
These two Choices object are then added together (making use of implicit conversion support for the Choices object under the GrammarBuilder class).
The construction of a Choices object from a list of System.String parameters is highlighted.
private Grammar CreateSimpleColorGrammar1(params int[] info) {
GrammarBuilder builder1 = "Set background to";
GrammarBuilder builder2 = "Change background to";
Choices bothChoice = new Choices(builder1, builder2);
System.Collections.ArrayList colorNameList = new System.Collections.ArrayList();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) {
// Associate the string name of the color with each item.
colorNameList.Add(colorName);
}
string[] colors = (string[])colorNameList.ToArray(typeof(string));
Choices colorChoice = new Choices(colors);
GrammarBuilder bothBuilders = GrammarBuilder.Add(bothChoice,(GrammarBuilder)colorChoice);
Grammar grammar = new Grammar(bothBuilders);
grammar.Name = "Set/Change Background to";
return grammar;
}
Platforms
Development Platforms
Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition
Target Platforms
See Also
Reference
Choices Class
Choices Members
Microsoft.Speech.Recognition Namespace
GrammarBuilder
Grammar
SemanticResultValue
SemanticResultKey