GrammarBuilder.AppendWildcard Method
Appends a recognition grammar element that matches any input.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Public Sub AppendWildcard
public void AppendWildcard ()
public:
void AppendWildcard ()
public void AppendWildcard ()
public function AppendWildcard ()
Remarks
The grammar element appended to a GrammarBuilder by calling AppendWildcard will match any spoken word. It will not match background noise or silence.
Example
The example below defines a Grammar and an Grammar.SpeechRecognized event handler designed to process password input of the form "My password is [wildcard]".
The example is implemented by creating two GrammarBuilder instances: one (pwdBuilder
) constructed with the "My password"; the other (wildcardBuilder
) uses the default GrammarBuilder constructor, has a wild card appended to it, and has a semantic key applied to it. The two GrammarBuilder instances are then added together.
private void pwdGrammar() {
GrammarBuilder pwdBuilder = new GrammarBuilder("My Password is");
GrammarBuilder wildcardBuilder = new GrammarBuilder();
wildcardBuilder.AppendWildcard();
SemanticResultKey pwd = new SemanticResultKey("Password", wildcardBuilder);
pwdBuilder += pwd;
Grammar grammar = new Grammar(pwdBuilder);
grammar.Name = "Password input";
grammar.SpeechRecognized +=
delegate(object sender, SpeechRecognizedEventArgs eventArgs) {
SemanticValue semantics = eventArgs.Result.Semantics;
RecognitionResult result = eventArgs.Result;
if (!semantics.ContainsKey("Password")) {
SpeechUI.SendTextFeedback(eventArgs.Result,
"No Password Provided", false);
} else {
RecognizedAudio pwdAudio = result.GetAudioForWordRange(result.Words[3],
result.Words[result.Words.Count - 1]);
MemoryStream pwdMemoryStream = new MemoryStream();
pwdAudio.WriteToAudioStream(pwdMemoryStream);
if (!IsValidPwd(pwdMemoryStream)) {
string badPwd = System.IO.Path.GetTempPath() + "BadPwd" + (new Random()).Next().ToString() + ".wav";
FileStream waveStream = new FileStream(badPwd, FileMode.Create);
pwdAudio.WriteToWaveStream(waveStream);
waveStream.Flush();
waveStream.Close();
SpeechUI.SendTextFeedback(eventArgs.Result,
"Invalid Password", false);
}
}
};
grammar.Enabled = true;
_recognizer.LoadGrammar(grammar);
UpdateGrammarTree(_grammarTreeView, _recognizer);
}
Thread Safety
All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.
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
GrammarBuilder Class
GrammarBuilder Members
Microsoft.Speech.Recognition Namespace