SemanticResultKey 생성자

정의

SemanticResultKey의 인스턴스를 생성하고 키를 문법 구성 요소에 연결합니다.

오버로드

SemanticResultKey(String, GrammarBuilder[])

음성 인식 문법을 만드는 데 사용하는 하나 이상의 GrammarBuilder 개체에 의미 키를 할당합니다.

SemanticResultKey(String, String[])

음성 인식 문법을 만드는 데 사용하는 하나 이상의 String 인스턴스에 의미 키를 할당합니다.

설명

텍스트 태그(의미 체계 키) 및 음성 인식 문법에 추가할 문법 구성 요소 집합을 지정하기 위한 SemanticResultKey 생성자입니다.

문법 구성 요소는 개체의 배열 또는 인스턴스의 GrammarBuilderString 배열로 지정할 수 있습니다.

문법 구성 요소가 인식에 사용되는 경우 의 생성자에 SemanticResultKey 제공된 텍스트 태그를 의미 체계 키로 사용하여 반환 SemanticValue 된 에 액세스할 수 있습니다. instance 속성 SemanticValueValue 정의SemanticResultKey에 사용되는 문법 구성 요소에 의해 결정됩니다.

SemanticResultKey(String, GrammarBuilder[])

Source:
SemanticResultKey.cs
Source:
SemanticResultKey.cs
Source:
SemanticResultKey.cs

음성 인식 문법을 만드는 데 사용하는 하나 이상의 GrammarBuilder 개체에 의미 키를 할당합니다.

public:
 SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ builders);
public SemanticResultKey (string semanticResultKey, params System.Speech.Recognition.GrammarBuilder[] builders);
new System.Speech.Recognition.SemanticResultKey : string * System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray builders As GrammarBuilder())

매개 변수

semanticResultKey
String

builders 인수로 지정된 SemanticValue 개체와 연결된 GrammarBuilder 인스턴스에 액세스할 때 의미 키로 사용할 태그입니다.

builders
GrammarBuilder[]

semanticResultKey에 정의된 태그를 사용하여 액세스할 수 있는 SemanticValue 개체와 연결된 문법 구성 요소의 배열입니다.

예제

다음 예제에서는 "내 암호는 ..."형식의 암호 입력을 인식하는 을 만듭니다 Grammar . 여기서 실제 입력은 와일드카드와 일치합니다.

와일드카드는 키 값이 "Password"인 에 SpeechRecognizer 의해 태그가 지정됩니다. SpeechRecognized 처리기는 이 태그의 존재를 확인하고, 암호의 오디오 입력을 가져오고, 암호를 확인합니다.

private void pwdGrammar()
{
  GrammarBuilder pwdBuilder = new GrammarBuilder("My Password is");
  GrammarBuilder wildcardBuilder = new GrammarBuilder();
  wildcardBuilder.AppendWildcard();
  SemanticResultKey wildcardKey= new SemanticResultKey("Password", wildcardBuilder);
  pwdBuilder+=wildcardKey;
  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);

}

설명

암시적 변환으로 인해 인수는 builders , , SemanticResultKeyChoicesString 개체도 지원합니다SemanticResultValue. 암시적 변환에 대한 자세한 내용은 를 참조하세요 Implicit.

인식 작업을 GrammarBuilder 수행할 때 인수에 제공된 개체는 builders 순차적으로 처리됩니다. 예를 들어 다음 SemanticResultValue 을 사용하여 를 생성하는 Grammar경우 인식 엔진에 대한 입력에는 인식할 "빠른 갈색 여우"라는 단어가 순서대로 포함되어야 합니다.

SemanticResultKey stringTest=new SemanticResultKey(
    "stringTest", new GrammarBuilder[] {
    new GrammarBuilder("the"),
    new GrammarBuilder("quick"),
    new GrammarBuilder("brown"),
    new GrammarBuilder("fox")});

인수에는 semanticResultKey 반환될 수 있는 에 액세스 SemanticValue 하는 데 사용되는 태그가 포함되어 있습니다.

의 는 Value 매개 변수에서 GrammarBuilder 제공하는 인스턴스에 의해 결정됩니다builders.SemanticValue

개체에 GrammarBuilder 의 정의 인스턴스가 SemanticResultValue없는 경우 의 SemanticValue 값은 입니다 null.

매개 변수에 제공된 개체가 GrammarBuilder 인식 논리에 builders 사용되는 태그가 지정되지 않은(개체와 SemanticResultKey 연결되지 않음) SemanticResultValue instance 제공하는 경우 해당 instance SemanticResultValue 생성되는 의 SemanticValue 속성을 정의 Value 합니다.

매개 변수로 지정된 builders 개체에 태그 SemanticResultValue 가 지정되지 않은 instance GrammarBuilder 하나만 있어야 합니다. 태그 SemanticResultValue 가 지정되지 않은 여러 인스턴스가 와 SemanticResultKey연결된 경우 각각은 인식 결과에서 생성된 의 SemanticValue 값을 설정하려고 시도합니다. 이는 허용되지 않으며 인식기는 이러한 instance 사용하여 만든 을 Grammar 사용하려고 할 때 예외를 SemanticResultKey 생성합니다.

매개 변수에 지정된 개체에 GrammarBuilder 포함되고 이미 다른 SemanticResultKey 인스턴스와 연결된 의 SemanticResultValue 인스턴스는 현재 SemanticResultKey instance 영향을 주지 builders 않습니다.

적용 대상

SemanticResultKey(String, String[])

Source:
SemanticResultKey.cs
Source:
SemanticResultKey.cs
Source:
SemanticResultKey.cs

음성 인식 문법을 만드는 데 사용하는 하나 이상의 String 인스턴스에 의미 키를 할당합니다.

public:
 SemanticResultKey(System::String ^ semanticResultKey, ... cli::array <System::String ^> ^ phrases);
public SemanticResultKey (string semanticResultKey, params string[] phrases);
new System.Speech.Recognition.SemanticResultKey : string * string[] -> System.Speech.Recognition.SemanticResultKey
Public Sub New (semanticResultKey As String, ParamArray phrases As String())

매개 변수

semanticResultKey
String

phrases 인수로 지정된 String 개체와 연결된 SemanticValue 인스턴스에 액세스하는 데 사용할 태그입니다.

phrases
String[]

결부된 텍스트가 semanticResultKey에서 정의된 태그에 액세스 가능한 String 개체와 연결된, 하나 이상의 SemanticValue 개체

예제

다음 예제에서는 개체의 배열 StringGrammarBuilder 의해 정의 되는 를 사용 SemanticResultKey하는 개체에서 를 만듭니다Grammar.

만든 를 Grammar 사용하는 인식 엔진은 "빨강 녹색 파란색 0"이라는 구를 인식합니다. 인식에서 반환된 RecognizedPhrase 의 의미 체계에는 "빨간색 녹색 파란색"이 있는 가 Value 포함 SemanticValue 됩니다. "코드" 태그를 사용하여 에 액세스할 SemanticValue 수 있습니다.

SemanticResultValue("zero", 5) 추가된 GrammarBuilder으로 인해 의 루트 SemanticValue 개체 RecognizedPhrase 값은 5입니다.

private void keyTest()
{
  // Say "color red green blue zero"
  GrammarBuilder gb = new GrammarBuilder("color") +
                        new SemanticResultKey("code",
                          (new string[] {"red", "green", "blue"})) +
                        new SemanticResultValue("zero", 5);
  Grammar g = new Grammar(gb);
  g.Name = "keyTest";
  _recognizer.LoadGrammar(g);
}

설명

인식 작업을 String 수행할 때 매개 변수에 phrases 사용되는 개체는 순차적으로 처리됩니다. 예를 들어 다음 SemanticResultValue 을 사용하여 를 생성하는 Grammar경우 인식 엔진에 대한 입력에는 인식할 "빠른 갈색 여우"라는 단어가 순서대로 포함되어야 합니다.

SemanticResultKey stringTest=new SemanticResultKey("stringTest",
                                new string[] {
                                               "the",
                                               "quick",
                                               "brown",
                                               "fox"});

인수는 semanticResultKey 반환될 수 있는 에 액세스 SemanticValue 하는 데 사용되는 키를 결정합니다.

문자열 Value 개체 배열이 있는 의미 체계 키를 포함하는 개체를 사용하여 GrammarBuilder 를 생성하는 Grammar 경우 인식 작업에서 생성된 의 SemanticValue 는 인식에 사용되는 문자열입니다. 앞의 예제에서 이것은 "빠른 갈색 여우"임을 Value 의미합니다.

적용 대상