GrammarBuilder.AppendWildcard 메서드

정의

입력과 일치하는 인식 문법 요소를 문법 요소의 현재 시퀀스에 추가합니다.

public:
 void AppendWildcard();
public void AppendWildcard ();
member this.AppendWildcard : unit -> unit
Public Sub AppendWildcard ()

예제

다음 예제에서는 와일드 카드로 암호 입력을 허용 하는 문법에 대해서를 만듭니다. 이 예제에서는 연결을 Grammar.SpeechRecognized 암호 입력의 유효성을 검사 하는 문법에 대 한 이벤트 처리기입니다.

private Grammar CreatePasswordGrammar()
{
  GrammarBuilder wildcardBuilder = new GrammarBuilder();
  wildcardBuilder.AppendWildcard();
  SemanticResultKey passwordKey =
    new SemanticResultKey("Password", wildcardBuilder);

  GrammarBuilder passwordBuilder =
    new GrammarBuilder("My Password is");
  passwordBuilder.Append(passwordKey);

  Grammar passwordGrammar = new Grammar(passwordBuilder);
  passwordGrammar.Name = "Password input";

  passwordGrammar.SpeechRecognized +=
    new EventHandler<SpeechRecognizedEventArgs>(
      PasswordInputHandler);

  return passwordGrammar;
}

// Handle the SpeechRecognized event for the password grammar.
private void PasswordInputHandler(object sender, SpeechRecognizedEventArgs e)
{
  if (e.Result == null) return;

  RecognitionResult result = e.Result;
  SemanticValue semantics = e.Result.Semantics;

  if (semantics.ContainsKey("Password"))
  {
    RecognizedAudio passwordAudio =
      result.GetAudioForWordRange(
        result.Words[3], result.Words[result.Words.Count - 1]);

    if (IsValidPassword(passwordAudio))
    {
      Console.WriteLine("Password accepted.");

      // Add code to handle a valid password here.
    }
    else
    {
      Console.WriteLine("Invalid password.");

      // Add code to handle an invalid password here.
    }
  }
}

// Validate the password input.
private bool IsValidPassword(RecognizedAudio passwordAudio)
{
  Console.WriteLine("Validating password.");

  // Add password validation code here.

  return false;
}

설명

와일드 카드 요소의 요소의 현재 시퀀스의 끝에 추가 됩니다.

와일드 카드 요소의 음성된 단어를 찾습니다. 배경 소음과 또는 대기에는 일치 하지 않습니다.

적용 대상

추가 정보