-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
StateChangedEventArgs.xml
181 lines (153 loc) · 9.17 KB
/
StateChangedEventArgs.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
<Type Name="StateChangedEventArgs" FullName="System.Speech.Recognition.StateChangedEventArgs">
<TypeSignature Language="C#" Value="public class StateChangedEventArgs : EventArgs" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit StateChangedEventArgs extends System.EventArgs" />
<TypeSignature Language="DocId" Value="T:System.Speech.Recognition.StateChangedEventArgs" />
<TypeSignature Language="VB.NET" Value="Public Class StateChangedEventArgs
Inherits EventArgs" />
<TypeSignature Language="F#" Value="type StateChangedEventArgs = class
 inherit EventArgs" />
<TypeSignature Language="C++ CLI" Value="public ref class StateChangedEventArgs : EventArgs" />
<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.EventArgs</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Returns data from the <see cref="E:System.Speech.Recognition.SpeechRecognizer.StateChanged" /> event.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Speech.Recognition.SpeechRecognizer.StateChanged> event is raised by the <xref:System.Speech.Recognition.SpeechRecognizer> class. <xref:System.Speech.Recognition.StateChangedEventArgs> derives from <xref:System.EventArgs> and is passed to handlers for <xref:System.Speech.Recognition.SpeechRecognizer.StateChanged> events.
<xref:System.Speech.Recognition.SpeechRecognizer.State%2A> is a read-only property. A shared speech recognizer's state cannot be changed programmatically. Users can change a shared speech recognizer's state using the Speech Recognition user interface (UI) or through the **Speech Recognition** member of the Windows **Control Panel**.
Both the **On** and **Sleep** settings in the Speech Recognition UI correspond to the `Listening` state. The **Off** setting in the Speech Recognition UI corresponds to <xref:System.Speech.Recognition.RecognizerState.Stopped>.
## Examples
The following example creates a shared speech recognizer, and then creates two types of grammars for recognizing specific words and for accepting free dictation. The example asynchronously loads all the created grammars to the recognizer. A handler for the <xref:System.Speech.Recognition.SpeechRecognizer.StateChanged> event uses the <xref:System.Speech.Recognition.SpeechRecognizer.EmulateRecognizeAsync%2A> method to put Windows Recognition in "listening" mode.
```
using System;
using System.Speech.Recognition;
namespace SampleRecognition
{
class Program
{
private static SpeechRecognizer recognizer;
public static void Main(string[] args)
{
// Initialize a shared speech recognition engine.
recognizer = new SpeechRecognizer();
// 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);
// Add a handler for the StateChanged event.
recognizer.StateChanged += new EventHandler<StateChangedEventArgs>(recognizer_StateChanged);
// Create "yesno" grammar.
Choices yesChoices = new Choices(new string[] { "yes", "yup", "yah}" });
SemanticResultValue yesValue =
new SemanticResultValue(yesChoices, (bool)true);
Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });
SemanticResultValue noValue = new SemanticResultValue(noChoices, (bool)false);
SemanticResultKey yesNoKey =
new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));
Grammar yesnoGrammar = new Grammar(yesNoKey);
yesnoGrammar.Name = "yesNo";
// Create "done" grammar.
Grammar doneGrammar =
new Grammar(new Choices(new string[] { "done", "exit", "quit", "stop" }));
doneGrammar.Name = "Done";
// Create dictation grammar.
Grammar dictation = new DictationGrammar();
dictation.Name = "Dictation";
// Load grammars to the recognizer.
recognizer.LoadGrammarAsync(yesnoGrammar);
recognizer.LoadGrammarAsync(doneGrammar);
recognizer.LoadGrammarAsync(dictation);
// Keep the console window open.
Console.ReadLine();
}
// Put the shared speech recognizer into "listening" mode.
static void recognizer_StateChanged(object sender, StateChangedEventArgs e)
{
if (e.RecognizerState != RecognizerState.Stopped)
{
recognizer.EmulateRecognizeAsync("Start listening");
}
}
// Write the grammar name and the text of the recognized phrase to the console.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Grammar({0}): {1}", e.Result.Grammar.Name, e.Result.Text);
// Add event handler code here.
}
// Handle the LoadGrammarCompleted event.
static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
{
string grammarName = e.Grammar.Name;
bool grammarLoaded = e.Grammar.Loaded;
if (e.Error != null)
{
Console.WriteLine("LoadGrammar for {0} failed with a {1}.",
grammarName, e.Error.GetType().Name);
}
// Add exception handling code here.
Console.WriteLine("Grammar {0} {1} loaded.",
grammarName, (grammarLoaded) ? "is" : "is not");
}
}
}
```
]]></format>
</remarks>
<altmember cref="E:System.Speech.Recognition.SpeechRecognizer.StateChanged" />
<altmember cref="T:System.Speech.Recognition.RecognizerState" />
</Docs>
<Members>
<Member MemberName="RecognizerState">
<MemberSignature Language="C#" Value="public System.Speech.Recognition.RecognizerState RecognizerState { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Speech.Recognition.RecognizerState RecognizerState" />
<MemberSignature Language="DocId" Value="P:System.Speech.Recognition.StateChangedEventArgs.RecognizerState" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property RecognizerState As RecognizerState" />
<MemberSignature Language="F#" Value="member this.RecognizerState : System.Speech.Recognition.RecognizerState" Usage="System.Speech.Recognition.StateChangedEventArgs.RecognizerState" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Speech::Recognition::RecognizerState RecognizerState { System::Speech::Recognition::RecognizerState get(); };" />
<MemberType>Property</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>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Speech.Recognition.RecognizerState</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the current state of the shared speech recognition engine in Windows.</summary>
<value>A <see cref="T:System.Speech.Recognition.RecognizerState" /> instance that indicates whether the state of a shared speech recognition engine is <see langword="Listening" /> or <see langword="Stopped" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Examples
The following example updates a display based on the state information provided by a <xref:System.Speech.Recognition.RecognizerState> instance that is obtained from the <xref:System.Speech.Recognition.StateChangedEventArgs.RecognizerState%2A> property of a <xref:System.Speech.Recognition.StateChangedEventArgs> instance passed to a handler for a <xref:System.Speech.Recognition.SpeechRecognizer.StateChanged> event.
```
// Make sure that _recognizer and recognition start buttons are disabled if state is stopped.
// Re-enable the start button to allow manual re-enable if the speech recognizer is listening.
_recognizer.StateChanged +=
delegate(object sender, StateChangedEventArgs eventArgs)
{
_recognizerStateLabel.Text = "Speech Recognizer State: " + eventArgs.RecognizerState.ToString();
};
```
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>