This documentation is archived and is not being maintained.

GrammarBuilder.AppendWildcard Method

Appends recognition logic designed to match any input.

Namespace: System.Speech.Recognition
Assembly: System.Speech (in system.speech.dll)

public void AppendWildcard ()
public void AppendWildcard ()
public function AppendWildcard ()
Not applicable.

The logical appended to a GrammarBuilder by calling AppendWildcard will match any spoken word. It will not match background noise or silence.

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 the 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();
    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")) {

                                              "No Password Provided", false);
                } else {

                    RecognizedAudio pwdAudio = result.GetAudioForWordRange(result.Words[3],
                                                                result.Words[result.Words.Count - 1]);
                    MemoryStream pwdMemoryStream = new MemoryStream();
                    if (!IsValidPwd(pwdMemoryStream)) {
                        string badPwd = System.IO.Path.GetTempPath() + "BadPwd" + (new Random()).Next().ToString() + ".wav";
                        FileStream waveStream = new FileStream(badPwd, FileMode.Create);
                                                  "Invalid Password", false);

    grammar.Enabled = true;
    UpdateGrammarTree(_grammarTreeView, _recognizer);


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0