-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Choices.xml
589 lines (483 loc) · 29.7 KB
/
Choices.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
<Type Name="Choices" FullName="System.Speech.Recognition.Choices">
<TypeSignature Language="C#" Value="public class Choices" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit Choices extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Speech.Recognition.Choices" />
<TypeSignature Language="VB.NET" Value="Public Class Choices" />
<TypeSignature Language="F#" Value="type Choices = class" />
<TypeSignature Language="C++ CLI" Value="public ref class Choices" />
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Diagnostics.DebuggerDisplay("{_oneOf.DebugSummary}")]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.DebuggerDisplay("{_oneOf.DebugSummary}")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Represents a set of alternatives in the constraints of a speech recognition grammar.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A <xref:System.Speech.Recognition.Choices> object represents a component of a phrase that can have one of several values. Use this class when creating a speech recognition grammar from a <xref:System.Speech.Recognition.GrammarBuilder> object.
For example, a <xref:System.Speech.Recognition.Choices> object could represent the component *colorChoice* in the phrase, "Change the color to *colorChoice*", where acceptable values for *colorChoice* are "red", or "green", or "blue".
> [!NOTE]
> To use a <xref:System.Speech.Recognition.Choices> object as an optional component in a phrase, create the <xref:System.Speech.Recognition.Choices> object and add it to a <xref:System.Speech.Recognition.GrammarBuilder.%23ctor%28System.Speech.Recognition.GrammarBuilder%2CSystem.Int32%2CSystem.Int32%29?displayProperty=nameWithType> object with `minRepeat` and `maxRepeat` set to 0 and 1, respectively. Phrases containing optional components can be recognized whether or not the optional component is spoken.
The <xref:System.Speech.Recognition.Choices> class serves the same function as the `one-of` XML element defined by the [Speech Recognition Grammar Specification (SRGS) Version 1.0](https://www.w3.org/TR/speech-grammar/) and is similar to the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> class in the <xref:System.Speech.Recognition.SrgsGrammar> namespace.
For more information about defining a speech recognition grammar, see [Speech Recognition](https://learn.microsoft.com/previous-versions/office/developer/speech-technologies/hh361633(v=office.14)).
## Examples
The following example creates a speech recognition grammar for the phrase, "Set background to *colorChoice*", where *colorChoice* can be one of the defined colors. The <xref:System.Speech.Recognition.GrammarBuilder> is used to define the constraints for the grammar.
```csharp
private Grammar CreateColorGrammar()
{
// Create a Choices object that contains a set of alternative colors.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
colorChoice.Add(new string[] {"cyan", "yellow", "magenta"});
// Construct the phrase.
GrammarBuilder builder = new GrammarBuilder("Set background to");
builder.Append(colorChoice);
// Create a grammar for the phrase.
Grammar colorGrammar = new Grammar(builder);
colorGrammar.Name = "SetBackground";
return colorGrammar;
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
<related type="ExternalDocumentation" href="https://go.microsoft.com/fwlink/?LinkId=15143">Speech Recognition Grammar Specification (SRGS)</related>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.Choices" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can construct a <xref:System.Speech.Recognition.Choices> object using a parameterless constructor (which returns an empty object), from a group of <xref:System.String> objects, or a from set of <xref:System.Speech.Recognition.GrammarBuilder> objects.
Because the <xref:System.Speech.Recognition.GrammarBuilder> object supports implicit conversion from <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey>, a <xref:System.Speech.Recognition.Choices> can be constructed from an array of these objects using a cast.
## Examples
The following example uses <xref:System.Speech.Recognition.Choices> objects to create two lists of alternatives.
The first <xref:System.Speech.Recognition.Choices> object is constructed from an array of <xref:System.String> objects. The other <xref:System.Speech.Recognition.Choices> object is constructed from an array of <xref:System.Speech.Recognition.GrammarBuilder> objects which have been implicitly converted by a cast.
The example uses a <xref:System.Speech.Recognition.GrammarBuilder> object to assemble a phrase, using the <xref:System.Speech.Recognition.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".
```csharp
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;
}
```
]]></format>
</remarks>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Choices ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 Choices();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.Choices" /> class that contains an empty set of alternatives.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This constructor returns a valid, empty set of alternatives. You can add alternatives using any of the <xref:System.Speech.Recognition.Choices.Add%2A> methods.
## Examples
The following example uses <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.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 <xref:System.Speech.Recognition.Choices> and <xref:System.String> to <xref:System.Speech.Recognition.GrammarBuilder>.
```csharp
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);
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Choices (params System.Speech.Recognition.GrammarBuilder[] alternateChoices);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(class System.Speech.Recognition.GrammarBuilder[] alternateChoices) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.#ctor(System.Speech.Recognition.GrammarBuilder[])" />
<MemberSignature Language="VB.NET" Value="Public Sub New (ParamArray alternateChoices As GrammarBuilder())" />
<MemberSignature Language="F#" Value="new System.Speech.Recognition.Choices : System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.Choices" Usage="new System.Speech.Recognition.Choices alternateChoices" />
<MemberSignature Language="C++ CLI" Value="public:
 Choices(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="alternateChoices" Type="System.Speech.Recognition.GrammarBuilder[]">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ParamArray]</AttributeName>
<AttributeName Language="F#">[<System.ParamArray>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="alternateChoices">An array containing the set of alternatives.</param>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.Choices" /> class from an array containing one or more <see cref="T:System.Speech.Recognition.GrammarBuilder" /> objects.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Each <xref:System.Speech.Recognition.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 <xref:System.Speech.Recognition.Choices.Add%2A> methods.
The constructor throws an <xref:System.ArgumentNullException> when `alternateChoices` is `null` or when any of the array elements are `null`.
Because the <xref:System.Speech.Recognition.GrammarBuilder> class provides support for implicit conversion of <xref:System.Speech.Recognition.Choices>, <xref:System.Speech.Recognition.SemanticResultValue>, and <xref:System.Speech.Recognition.SemanticResultKey> objects to <xref:System.Speech.Recognition.GrammarBuilder> instances, by properly using casts, this constructor can also be used to create a <xref:System.Speech.Recognition.Choices> object from a list of any combination of these objects.
## Examples
The following example uses `Choices` and <xref:System.Speech.Recognition.GrammarBuilder> objects to create a <xref:System.Speech.Recognition.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 <xref:System.String> to <xref:System.Speech.Recognition.GrammarBuilder>.
```csharp
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);
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Choices (params string[] phrases);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string[] phrases) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.#ctor(System.String[])" />
<MemberSignature Language="VB.NET" Value="Public Sub New (ParamArray phrases As String())" />
<MemberSignature Language="F#" Value="new System.Speech.Recognition.Choices : string[] -> System.Speech.Recognition.Choices" Usage="new System.Speech.Recognition.Choices phrases" />
<MemberSignature Language="C++ CLI" Value="public:
 Choices(... cli::array <System::String ^> ^ phrases);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="phrases" Type="System.String[]">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ParamArray]</AttributeName>
<AttributeName Language="F#">[<System.ParamArray>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="phrases">An array containing the set of alternatives.</param>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.Choices" /> class from an array containing one or more <see cref="T:System.String" /> objects.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Each <xref:System.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 <xref:System.Speech.Recognition.Choices.Add%2A> methods.
The constructor throws an <xref:System.ArgumentNullException> when `phrases` is `null` or any of the array elements are `null`. The constructor throws an <xref:System.ArgumentException> if any element in the array is an empty string ("").
## Examples
The following example uses <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.GrammarBuilder> objects to create a <xref:System.Speech.Recognition.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 <xref:System.String> to <xref:System.Speech.Recognition.GrammarBuilder>.
```csharp
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);
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
</Docs>
</Member>
<MemberGroup MemberName="Add">
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Adds items to the set of alternatives.</summary>
</Docs>
</MemberGroup>
<Member MemberName="Add">
<MemberSignature Language="C#" Value="public void Add (params System.Speech.Recognition.GrammarBuilder[] alternateChoices);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Add(class System.Speech.Recognition.GrammarBuilder[] alternateChoices) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.Add(System.Speech.Recognition.GrammarBuilder[])" />
<MemberSignature Language="VB.NET" Value="Public Sub Add (ParamArray alternateChoices As GrammarBuilder())" />
<MemberSignature Language="F#" Value="member this.Add : System.Speech.Recognition.GrammarBuilder[] -> unit" Usage="choices.Add alternateChoices" />
<MemberSignature Language="C++ CLI" Value="public:
 void Add(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="alternateChoices" Type="System.Speech.Recognition.GrammarBuilder[]">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ParamArray]</AttributeName>
<AttributeName Language="F#">[<System.ParamArray>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="alternateChoices">The <see cref="T:System.Speech.Recognition.GrammarBuilder" /> objects to add to this <see cref="T:System.Speech.Recognition.Choices" /> object.</param>
<summary>Adds an array containing one or more <see cref="T:System.Speech.Recognition.GrammarBuilder" /> objects to the set of alternatives.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Because of support for implicit conversion from <xref:System.Speech.Recognition.Choices>, <xref:System.Speech.Recognition.SemanticResultKey>, and <xref:System.Speech.Recognition.SemanticResultValue> objects to <xref:System.Speech.Recognition.GrammarBuilder>, these three classes may be added to a <xref:System.Speech.Recognition.Choices> instance as well.
If `alternateChoices` is an empty array, this method does not update the set of alternatives.
Applications can use both <xref:System.Speech.Recognition.Choices.Add%28System.String%5B%5D%29> and <xref:System.Speech.Recognition.Choices.Add%28System.Speech.Recognition.GrammarBuilder%5B%5D%29> to add alternatives to a <xref:System.Speech.Recognition.Choices> object.
This method throws an <xref:System.ArgumentNullException> when `alternateChoices` is `null` or any of the array elements are `null`.
## Examples
The following example creates a speech recognition grammar for phrases such as "Call Anne on her cell" and "Call James on his work phone". The example uses both overloads of the <xref:System.Speech.Recognition.Choices.Add%2A> method to build the grammar.
```csharp
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);
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
<altmember cref="T:System.Speech.Recognition.Grammar" />
</Docs>
</Member>
<Member MemberName="Add">
<MemberSignature Language="C#" Value="public void Add (params string[] phrases);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void Add(string[] phrases) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.Add(System.String[])" />
<MemberSignature Language="VB.NET" Value="Public Sub Add (ParamArray phrases As String())" />
<MemberSignature Language="F#" Value="member this.Add : string[] -> unit" Usage="choices.Add phrases" />
<MemberSignature Language="C++ CLI" Value="public:
 void Add(... cli::array <System::String ^> ^ phrases);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="phrases" Type="System.String[]">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.ParamArray]</AttributeName>
<AttributeName Language="F#">[<System.ParamArray>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="phrases">The strings to add to this <see cref="T:System.Speech.Recognition.Choices" /> object.</param>
<summary>Adds an array containing one or more <see cref="T:System.String" /> objects to the set of alternatives.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Applications can use both <xref:System.Speech.Recognition.Choices.Add%28System.String%5B%5D%29> and <xref:System.Speech.Recognition.Choices.Add%28System.Speech.Recognition.GrammarBuilder%5B%5D%29> to add alternatives to a <xref:System.Speech.Recognition.Choices> object.
If `phrases` is an empty array, this method does not update the set of alternates.
This method throws an <xref:System.ArgumentNullException> when `phrases` is `null` or any of the array elements are `null`. This method throws an <xref:System.ArgumentException> if any element in the array is the empty string ("").
## Examples
The following example creates a speech recognition grammar for phrases similar to "Call Anne on her cell" and "Call James on his work phone". The example uses both overloads of the <xref:System.Speech.Recognition.Choices.Add%2A> method to build the grammar.
```csharp
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);
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
</Docs>
</Member>
<Member MemberName="ToGrammarBuilder">
<MemberSignature Language="C#" Value="public System.Speech.Recognition.GrammarBuilder ToGrammarBuilder ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Speech.Recognition.GrammarBuilder ToGrammarBuilder() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.Choices.ToGrammarBuilder" />
<MemberSignature Language="VB.NET" Value="Public Function ToGrammarBuilder () As GrammarBuilder" />
<MemberSignature Language="F#" Value="member this.ToGrammarBuilder : unit -> System.Speech.Recognition.GrammarBuilder" Usage="choices.ToGrammarBuilder " />
<MemberSignature Language="C++ CLI" Value="public:
 System::Speech::Recognition::GrammarBuilder ^ ToGrammarBuilder();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Speech.Recognition.GrammarBuilder</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a <see cref="T:System.Speech.Recognition.GrammarBuilder" /> object from this <see cref="T:System.Speech.Recognition.Choices" /> object.</summary>
<returns>A <see cref="T:System.Speech.Recognition.GrammarBuilder" /> that matches this <see cref="T:System.Speech.Recognition.Choices" /> object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Speech.Recognition.GrammarBuilder> returned by this method is equivalent to one returned by either of the following.
- Calling the <xref:System.Speech.Recognition.GrammarBuilder.%23ctor%2A> constructor with this object as the parameter.
- Using the implicit or explicit cast of this object to a <xref:System.Speech.Recognition.GrammarBuilder>.
## Examples
The following example creates a speech recognition grammar for changing the background color.
```csharp
private Grammar CreateColorChoice()
{
// Create a Choices object that contains a set of alternative colors.
Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(new Choices(new string[] {"Set", "Change"}));
gb.Append("background to");
gb.Append(colorChoice.ToGrammarBuilder());
Grammar grammar = new Grammar(gb);
grammar.Name = "modify background color";
return grammar;
}
```
]]></format>
</remarks>
<altmember cref="T:System.Speech.Recognition.Grammar" />
<altmember cref="T:System.Speech.Recognition.GrammarBuilder" />
</Docs>
</Member>
</Members>
</Type>