SemanticResultKey 생성자

정의

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

오버로드

Name Description
SemanticResultKey(String, GrammarBuilder[])

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

SemanticResultKey(String, String[])

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

설명

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

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

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

SemanticResultKey(String, GrammarBuilder[])

Source:
SemanticResultKey.cs
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 변수에서 SemanticValue 제공하는 인스턴스에 GrammarBuilder 의해 결정됩니다 builders .

개체에 GrammarBuilder 정의 인스턴스가 SemanticResultValue없으면 값 SemanticValue 은 다음과 같습니다 null.

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

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

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

적용 대상

SemanticResultKey(String, String[])

Source:
SemanticResultKey.cs
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

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

phrases
String[]

연결된 텍스트가 정의된 태그semanticResultKey로 액세스할 수 있는 SemanticValue 개체와 연결되는 하나 이상의 String 개체입니다.

예제

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

생성된 인식 엔진은 Grammar "빨강 녹색 파란색 0"이라는 구를 인식합니다. 인식에 의해 반환되는 RecognizedPhrase 의미 체계에는 "빨강 녹색 파란색"이 포함 SemanticValueValue 됩니다. "코드" 태그를 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 에 사용되는 키를 결정합니다.

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

적용 대상