Grammar 생성자

정의

Grammar 클래스의 새 인스턴스를 초기화합니다.

오버로드

Grammar()

Grammar 클래스의 새 인스턴스를 초기화합니다.

Grammar(SrgsDocument, String, Uri, Object[])

Grammar의 인스턴스에서의 SrgsDocument 클래스의 새 인스턴스를 초기화하며, 상대 참조를 확인하기 위해 문법 및 기본 URI로의 진입점이 될 규칙의 이름을 지정합니다.

Grammar(Stream, String, Uri, Object[])

StreamGrammar 클래스의 새 인스턴스를 초기화하며 상대 참조를 확인하기 위해 루트 규칙 및 기본 URI를 지정합니다.

Grammar(SrgsDocument, String, Uri)

개체에서 SrgsDocument 클래스의 Grammar 새 인스턴스를 초기화하고, 루트 규칙을 지정하고, 상대 규칙 참조를 확인하기 위한 기본 URI(Uniform Resource Identifier)를 정의합니다.

Grammar(SrgsDocument, String, Object[])

Grammar의 인스턴스에서의 SrgsDocument 클래스의 새 인스턴스를 초기화하며, 문법으로의 진입점이 될 규칙의 이름을 지정합니다.

Grammar(Stream, String, Uri)

스트림에서의 Grammar 클래스의 새 인스턴스를 초기화하며, 루트 규칙을 지정하고, 상대 규칙 참조를 확인하기 위해 기본 URI(Uniform Resource Identifier)를 정의합니다.

Grammar(Stream, String, Object[])

Grammar에서 Stream 클래스의 새 인스턴스를 초기화하고 루트 규칙을 지정합니다.

Grammar(String, String, Object[])

문법 정의를 포함하는 파일에서의 Grammar 클래스의 새 인스턴스를 초기화하며, 문법으로의 진입점이 될 규칙의 이름을 지정합니다.

Grammar(SrgsDocument, String)

개체에서 클래스의 새 인스턴스를 Grammar SrgsDocument 초기화하고 루트 규칙을 지정합니다.

Grammar(Stream, String)

Grammar에서 Stream 클래스의 새 인스턴스를 초기화하고 루트 규칙을 지정합니다.

Grammar(String)

파일에서 Grammar 클래스의 새 인스턴스를 초기화합니다.

Grammar(SrgsDocument)

Grammar 개체를 사용하여 SrgsDocument 클래스의 새 인스턴스를 초기화합니다.

Grammar(String, String)

파일에서 Grammar 클래스의 새로운 인스턴스를 초기화하고 루트 규칙을 지정합니다.

Grammar(GrammarBuilder)

Grammar 개체에서 GrammarBuilder 클래스의 새 인스턴스를 초기화합니다.

Grammar(Stream)

Grammar에서 Stream 클래스의 새 인스턴스를 초기화합니다.

설명

생성자를 사용하여 Grammar 지원되는 형식의 문법에 대한 GrammarBuilder SrgsDocument 설명이 포함된 파일이나 파일 또는 Stream 개체에서 인스턴스를 만들 Grammar 수 있습니다. 지원되는 형식은 다음과 같습니다.

인수에 XML 형식 문법 파일을 허용하는 문법 생성자는 XML 문법을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 문법을 미리 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

음성 인식 문법은 루트 규칙을 정의할 수 있습니다. 루트 규칙으로 사용할 규칙을 지정하는 개체를 만들 Grammar 려면 매개 변수를 허용하는 ruleName 생성자를 사용합니다.

상대 규칙 참조를 Grammar 확인하기 위해 기본 URI를 지정하는 개체를 만들려면 매개 변수를 사용하는 baseUri 생성자를 사용합니다.

Grammar()

Grammar 클래스의 새 인스턴스를 초기화합니다.

protected:
 Grammar();
protected Grammar ();
Protected Sub New ()

적용 대상

Grammar(SrgsDocument, String, Uri, Object[])

Grammar의 인스턴스에서의 SrgsDocument 클래스의 새 인스턴스를 초기화하며, 상대 참조를 확인하기 위해 문법 및 기본 URI로의 진입점이 될 규칙의 이름을 지정합니다.

public:
 Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, Uri ^ baseUri, cli::array <System::Object ^> ^ parameters);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, Uri baseUri, object[] parameters);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * Uri * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, baseUri As Uri, parameters As Object())

매개 변수

srgsDocument
SrgsDocument

음성 인식 문법에 대한 제약 조건을 포함하는 SrgsDocument의 인스턴스

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

baseUri
Uri

문법 설명에서 관련 규칙 참조를 해결하기 위해 사용하는 기본 URI 또는 null입니다.

parameters
Object[]

생성되는 OnInit의 루트 규칙 또는 진입점에 대한 Grammar 속성에 지정된 초기화 처리기에 전달되는 매개 변수입니다. 이 매개 변수는 null일 수 있습니다.

예외

  • 매개 변수에 잘못된 값이 있는 경우

  • srgsDocument에서 지정한 SrgsDocumentruleName에서 지정한 규칙을 포함하지 않습니다.

  • 배열 매개 변수의 내용이 규칙의 초기화 처리기의 인수와 일치하지 않습니다.

  • 문법은 baseUri가 제공한 URI나 문법에 대한 기본 기준 Uri 규칙으로 확인할 수 없는 상대 규칙 참조를 포함합니다.

설명

초기화 처리기에 대한 매개 변수도 지정할 수 있습니다.

적용 대상

Grammar(Stream, String, Uri, Object[])

StreamGrammar 클래스의 새 인스턴스를 초기화하며 상대 참조를 확인하기 위해 루트 규칙 및 기본 URI를 지정합니다.

public:
 Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, Uri ^ baseUri, cli::array <System::Object ^> ^ parameters);
public Grammar (System.IO.Stream stream, string ruleName, Uri baseUri, object[] parameters);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * Uri * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, baseUri As Uri, parameters As Object())

매개 변수

stream
Stream

문법 사양을 포함하는 입력/출력 개체(파일, VisualStudio 리소스, DLL 포함)에 연결된 Stream입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

baseUri
Uri

문법 설명에서 관련 규칙 참조를 해결하기 위해 사용하는 기본 URI 또는 null입니다.

parameters
Object[]

생성되는 OnInit의 루트 규칙 또는 진입점에 대한 Grammar 속성에 지정된 초기화 처리기에 전달되는 매개 변수입니다. 이 매개 변수는 null일 수 있습니다.

예외

  • 매개 변수에 잘못된 값이 있는 경우

  • streamruleName에서 지정한 규칙을 포함하지 않는 문법에 연결됩니다.

  • 배열 매개 변수의 내용이 규칙의 초기화 처리기의 인수와 일치하지 않습니다.

문법에는 baseUri가 제공한 URI나 문법에 대한 기본 기준 Uri 규칙으로 확인할 수 없는 상대 규칙 참조가 포함됩니다.

설명

초기화 처리기에 대한 매개 변수도 지정할 수 있습니다.

적용 대상

Grammar(SrgsDocument, String, Uri)

개체에서 SrgsDocument 클래스의 Grammar 새 인스턴스를 초기화하고, 루트 규칙을 지정하고, 상대 규칙 참조를 확인하기 위한 기본 URI(Uniform Resource Identifier)를 정의합니다.

public:
 Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, Uri ^ baseUri);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, Uri baseUri);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * Uri -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, baseUri As Uri)

매개 변수

srgsDocument
SrgsDocument

음성 인식 문법에 대한 제약 조건입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자 또는 SrgsDocument의 기본 루트 규칙을 사용하는 null

baseUri
Uri

SrgsDocument에서 관련 규칙 참조를 해결하기 위해 사용하는 기본 URI 또는 null입니다.

예외

ruleName을 확인할 수 없거나 public이 아닙니다. 또는 ruleNamenull이고 srgsDocument에 루트 규칙이 포함되지 않습니다.

srgsDocument이(가) null인 경우

srgsDocument확인할 수 없는 규칙 참조를 포함합니다.

예제

다음 예제에서는 cities.xml 파일에 대한 상대 규칙 참조를 포함하는 음성 인식 문법 SrgsDocument 을 만들고 규칙 참조를 확인하는 데 사용할 URI를 지정합니다. cities.xml 파일의 내용은 C# 예제를 따르는 XML 예제에 나타납니다.

private static Grammar CreateSrgsDocumentGrammar3()  
{  
  // Create the SrgsDocument.  
  SrgsDocument document = new SrgsDocument();  

  // Create the Main rule and add it to the document.  
  SrgsRule mainRule = new SrgsRule("Main");  
  mainRule.Scope = SrgsRuleScope.Public;  

  SrgsItem item = new SrgsItem("Can I get a shuttle in");  

  // Create a relative URI for the cities rule.  
  Uri ruleUri = new Uri("cities.xml#Cities", UriKind.Relative);  

  item.Add(new SrgsRuleRef(ruleUri));  

  mainRule.Add(item);  
  document.Rules.Add(mainRule);  

  // Set the root rule.  
  document.Root = mainRule;  

  // Create the grammar.  
  Uri baseUri = new Uri(@"file://c:\temp\");  
  Grammar citiesGrammar = new Grammar(document, null, baseUri);  
  citiesGrammar.Name = "SrgsDocument Cities Grammar 3";  

  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 인수 SrgsDocument 가 필요한 초기화 처리기를 포함하지 않아야 합니다.

이 생성자는 유효성을 검사 baseUri하지 않습니다. 그러나 문법 설명에서 LoadGrammar 모든 규칙 참조를 SpeechRecognitionEngine 확인할 수 없는 경우 개체의 SpeechRecognizer 메서드는 예외를 throw합니다. 그렇지 않은 null경우 baseUri 메서드는 LoadGrammar URI를 사용하여 다른 방법으로 확인할 수 없는 규칙 참조를 확인합니다. 파일을 나타내는 경우 baseUri 메서드는 LoadGrammar 상대 규칙 참조를 확인하려고 할 때 지정된 파일과 파일의 디렉터리를 모두 사용합니다.

추가 정보

적용 대상

Grammar(SrgsDocument, String, Object[])

Grammar의 인스턴스에서의 SrgsDocument 클래스의 새 인스턴스를 초기화하며, 문법으로의 진입점이 될 규칙의 이름을 지정합니다.

public:
 Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String, parameters As Object())

매개 변수

srgsDocument
SrgsDocument

음성 인식 문법에 대한 제약 조건을 포함하는 SrgsDocument의 인스턴스

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

parameters
Object[]

생성되는 OnInit의 루트 규칙 또는 진입점에 대한 Grammar 속성에 지정된 초기화 처리기에 전달되는 매개 변수입니다. 이 매개 변수는 null일 수 있습니다.

예외

  • 매개 변수에 잘못된 값이 있는 경우

  • srgsDocument에서 지정한 SrgsDocumentruleName에서 지정한 규칙을 포함하지 않습니다.

  • 배열 매개 변수의 내용이 규칙의 초기화 처리기의 인수와 일치하지 않습니다.

설명

초기화 처리기에 대한 매개 변수도 지정할 수 있습니다.

적용 대상

Grammar(Stream, String, Uri)

스트림에서의 Grammar 클래스의 새 인스턴스를 초기화하며, 루트 규칙을 지정하고, 상대 규칙 참조를 확인하기 위해 기본 URI(Uniform Resource Identifier)를 정의합니다.

public:
 Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, Uri ^ baseUri);
public Grammar (System.IO.Stream stream, string ruleName, Uri baseUri);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * Uri -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, baseUri As Uri)

매개 변수

stream
Stream

지원되는 형식의 음성 인식을 문법을 설명하는 스트림

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

baseUri
Uri

문법 설명에서 관련 규칙 참조를 해결하기 위해 사용하는 기본 URI 또는 null입니다.

예외

ruleName을 확인할 수 없거나 public이 아닙니다. 또는 ruleNamenull이고 문법 설명에서 루트 규칙을 정의하지 않습니다.

stream이(가) null인 경우

스트림에 올바른 설명이 포함되어 있지 않거나 스트림이 확인할 수 없는 규칙 참조가 포함된 문법을 설명합니다.

예제

다음 예제에서는 파일 스트림에서 로컬 SRGS 파일(shuttle.xml)을 로드합니다. 파일에는 cities.xml 파일의 규칙에 대한 상대 규칙 참조가 포함되어 있으며 규칙 참조를 확인하는 데 사용할 기본 URI를 지정합니다. shuttle.xml 및 cities.xml 파일의 콘텐츠는 C# 예제를 따르는 XML 예제에 표시됩니다.

private static Grammar CreateGrammarFromStream3()  
{  
  FileInfo file = new FileInfo(@".\shuttle.xml");  
  Uri baseUri = new Uri(@"file://c:\temp\");  
  Grammar citiesGrammar = new Grammar(file.OpenRead(), null, baseUri);  
  citiesGrammar.Name = "Stream Cities Grammar 3";  
  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- shuttle.xml:   
    Defines an SRGS grammar for asking about a shuttle service. This grammar  
    references a Cities rule that is defined in the cities.xml grammar. -->  

  <rule id="Main">  
    <item>  
      Can I get a shuttle in  
      <ruleref uri="cities.xml#Cities"/>  
    </item>  
  </rule>  
</grammar>  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 설명은 인수가 필요한 초기화 처리기를 정의해서는 안 됩니다.

이 생성자는 다음 형식에서 인스턴스를 만들 Grammar 수 있습니다.

이 생성자는 XML 형식 문법 파일을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 사전에 문법을 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

이 생성자는 유효성을 검사 baseUri하지 않습니다. 그러나 문법 설명에서 LoadGrammar 모든 규칙 참조를 SpeechRecognitionEngine 확인할 수 없는 경우 개체의 SpeechRecognizer 메서드는 예외를 throw합니다. 그렇지 않은 null경우 baseUri 메서드는 LoadGrammar URI를 사용하여 다른 방법으로 확인할 수 없는 규칙 참조를 확인합니다. 파일을 LoadGrammar 나타내는 경우 baseUri 상대 규칙 참조를 확인하려고 할 때 지정된 파일과 파일의 디렉터리를 모두 사용합니다.

추가 정보

적용 대상

Grammar(Stream, String, Object[])

Grammar에서 Stream 클래스의 새 인스턴스를 초기화하고 루트 규칙을 지정합니다.

public:
 Grammar(System::IO::Stream ^ stream, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (System.IO.Stream stream, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : System.IO.Stream * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String, parameters As Object())

매개 변수

stream
Stream

문법 사양을 포함하는 입력/출력 개체(파일, VisualStudio 리소스, DLL 포함)에 연결된 Stream입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

parameters
Object[]

생성되는 OnInit의 루트 규칙 또는 진입점에 대한 Grammar 속성에 지정된 초기화 처리기에 전달되는 매개 변수입니다. 이 매개 변수는 null일 수 있습니다.

예외

stream 은 다음 문법으로 연결합니다:

  • ruleName에 지정된 규칙을 포함하지 않습니다.

  • parameters에서 정해진 것들과 다른 초기화 매개 변수를 요구합니다.

  • 문법에 대한 기본 기본 Uri 규칙으로 확인할 수 없는 상대 규칙 참조를 포함합니다.

설명

초기화 처리기에 대한 매개 변수도 지정할 수 있습니다.

적용 대상

Grammar(String, String, Object[])

문법 정의를 포함하는 파일에서의 Grammar 클래스의 새 인스턴스를 초기화하며, 문법으로의 진입점이 될 규칙의 이름을 지정합니다.

public:
 Grammar(System::String ^ path, System::String ^ ruleName, cli::array <System::Object ^> ^ parameters);
public Grammar (string path, string ruleName, object[] parameters);
new System.Speech.Recognition.Grammar : string * string * obj[] -> System.Speech.Recognition.Grammar
Public Sub New (path As String, ruleName As String, parameters As Object())

매개 변수

path
String

DLL을 포함한 문법 사양이 들어 있는 파일의 경로입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

parameters
Object[]

생성되는 OnInit의 루트 규칙 또는 진입점에 대한 Grammar 속성에 지정된 초기화 처리기에 전달되는 매개 변수입니다. 이 매개 변수는 null일 수 있습니다.

예외

  • 매개 변수에 잘못된 값이 있는 경우

  • path에서 지정된 파일에 유효한 문법이나 ruleName에 지정된 규칙이 없습니다.

  • 배열 매개 변수의 내용이 규칙의 초기화 처리기의 인수와 일치하지 않습니다.

  • 문법은 문법에 대한 기본 기준 Uri 규칙으로 확인할 수 없는 상대 규칙 참조를 포함합니다.

설명

초기화 처리기에 대한 매개 변수도 지정할 수 있습니다.

적용 대상

Grammar(SrgsDocument, String)

개체에서 클래스의 새 인스턴스를 Grammar SrgsDocument 초기화하고 루트 규칙을 지정합니다.

public:
 Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument, System::String ^ ruleName);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument, string ruleName);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument * string -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument, ruleName As String)

매개 변수

srgsDocument
SrgsDocument

음성 인식 문법에 대한 제약 조건입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자 또는 SrgsDocument의 기본 루트 규칙을 사용하는 null

예외

ruleName을 확인할 수 없거나 public이 아닙니다. 또는 ruleNamenull이고 srgsDocument에 루트 규칙이 포함되지 않습니다.

srgsDocument이(가) null인 경우

srgsDocument확인할 수 없는 규칙 참조를 포함합니다.

예제

다음 예제에서는 인스턴스에서 음성 인식 문법을 SrgsDocument 만들고 문법의 루트 규칙으로 사용할 규칙을 지정합니다. 이 예제에서는 인스턴스에서 개체를 Grammar SrgsDocument 생성하고 음성 인식 엔진에 로드합니다.

using System;  
using System.Speech.Recognition;  
using System.Speech.Recognition.SrgsGrammar;  

namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  

    // Initialize an in-process speech recognition engine.  
    {  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine())  
      {  

        // Create the SrgsDocument.  
        SrgsDocument document = new SrgsDocument();  

        // Create the Cities rule and add it to the document.  
        SrgsRule citiesRule = new SrgsRule("Cities");  
        citiesRule.Scope = SrgsRuleScope.Public;  

        SrgsOneOf cityChoice = new SrgsOneOf();  
        cityChoice.Add(new SrgsItem("Seattle"));  
        cityChoice.Add(new SrgsItem("Los Angeles"));  
        cityChoice.Add(new SrgsItem("New York"));  
        cityChoice.Add(new SrgsItem("Miami"));  

        citiesRule.Add(cityChoice);  
        document.Rules.Add(citiesRule);  

        // Create the Main rule and add it to the document.  
        SrgsRule mainRule = new SrgsRule("Main");  
        mainRule.Scope = SrgsRuleScope.Public;  

        mainRule.Add(new SrgsItem("I would like to fly from"));  
        mainRule.Add(new SrgsRuleRef(citiesRule));  
        mainRule.Add(new SrgsItem("to"));  
        mainRule.Add(new SrgsRuleRef(citiesRule));  

        document.Rules.Add(mainRule);  

        // Create the Grammar object and specify which rule to use as the root.  
        Grammar citiesGrammar = new Grammar(document,"Main");  

        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(citiesGrammar);  

        // Attach a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Set the input to the recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  

        // Start recognition.  
        recognizer.RecognizeAsync();  
        Console.WriteLine("Starting asynchronous recognition...");  

        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("  Speech recognized: " + e.Result.Text);  
    }  
  }  
}  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 인수 SrgsDocument 가 필요한 초기화 처리기를 포함해서는 안 됩니다.

a에서 개체를 Grammar SrgsDocument 만들고 상대 규칙 참조를 확인하는 데 사용할 기본 URI를 지정하려면 생성자를 사용합니다 Grammar .

추가 정보

적용 대상

Grammar(Stream, String)

Grammar에서 Stream 클래스의 새 인스턴스를 초기화하고 루트 규칙을 지정합니다.

public:
 Grammar(System::IO::Stream ^ stream, System::String ^ ruleName);
public Grammar (System.IO.Stream stream, string ruleName);
new System.Speech.Recognition.Grammar : System.IO.Stream * string -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream, ruleName As String)

매개 변수

stream
Stream

지원되는 형식의 음성 인식을 문법을 설명하는 스트림

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

예외

ruleName을 확인할 수 없거나 public이 아닙니다. 또는 ruleNamenull이고 문법 설명에서 루트 규칙을 정의하지 않습니다.

stream이(가) null인 경우

스트림에 올바른 설명이 포함되어 있지 않거나 스트림이 확인할 수 없는 규칙 참조가 포함된 문법을 설명합니다.

예제

다음 예제에서는 파일 스트림에서 로컬 SRGS 파일(cities.xml)을 로드하고 문법의 루트로 사용할 규칙을 지정합니다. cities.xml 파일의 내용은 C# 예제 다음에 나오는 XML 예제에 나타납니다.

// Load a cities grammar from an I/O stream, use a specific  
// rule as the root of the grammar, and return the new grammar.   
private static Grammar CreateGrammarFromStream2()  
{  
  FileInfo file = new FileInfo(@"c:\temp\cities.xml");  
  Grammar citiesGrammar = new Grammar(file.OpenRead(), "Main");  
  citiesGrammar.Name = "Stream Cities Grammar 2";  
  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 설명은 인수가 필요한 초기화 처리기를 정의해서는 안 됩니다.

이 생성자는 다음 형식에서 Grammar 인스턴스를 만들 수 있습니다.

이 생성자는 XML 형식 문법 파일을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 문법을 미리 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

스트림에서 만들고 Grammar 상대 규칙 참조를 확인하는 데 사용할 기본 URI를 지정하려면 생성자를 사용합니다 Grammar .

추가 정보

적용 대상

Grammar(String)

파일에서 Grammar 클래스의 새 인스턴스를 초기화합니다.

public:
 Grammar(System::String ^ path);
public Grammar (string path);
new System.Speech.Recognition.Grammar : string -> System.Speech.Recognition.Grammar
Public Sub New (path As String)

매개 변수

path
String

지원되는 형식으로 음성 인식 문법을 설명하는 파일의 경로입니다.

예외

path가 빈 문자열("")을 포함하거나, 또는 파일이 루트 규칙을 포함하지 않는 문법을 설명합니다.

path이(가) null인 경우

파일에 올바른 설명이 포함되어 있지 않거나, 확인할 수 없는 규칙 참조가 포함된 문법을 설명합니다.

예제

다음 예제에서는 로컬 SRGS 파일에서 음성 인식 문법을 로드하여 개체를 빌드합니다 Grammar . cities.xml 파일의 내용은 C# 예제 다음에 나오는 XML 예제에 나타납니다.

// Load a cities grammar from a local file and  
// return the new grammar.   
private static Grammar CreateGrammarFromFile()  
{  
  Grammar citiesGrammar = new Grammar(@"c:\temp\cities.xml");  
  citiesGrammar.Name = "SRGS File Cities Grammar";  
  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 설명은 인수가 필요한 초기화 처리기를 정의해서는 안 됩니다.

이 생성자는 다음 형식에서 Grammar 인스턴스를 만들 수 있습니다.

이 생성자는 XML 형식 문법 파일을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 문법을 미리 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

SRGS 문법은 루트 규칙을 정의할 수 있습니다. 문자열에서 개체를 Grammar 만들고 루트 규칙을 지정하려면 생성자를 사용합니다 Grammar .

상대 규칙 참조를 Grammar 확인하는 데 사용할 기본 URI를 지정하는 개체를 만들려면 파일 스트림에서 파일을 열고 생성자를 사용합니다 Grammar.Grammar .

추가 정보

적용 대상

Grammar(SrgsDocument)

Grammar 개체를 사용하여 SrgsDocument 클래스의 새 인스턴스를 초기화합니다.

public:
 Grammar(System::Speech::Recognition::SrgsGrammar::SrgsDocument ^ srgsDocument);
public Grammar (System.Speech.Recognition.SrgsGrammar.SrgsDocument srgsDocument);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.SrgsGrammar.SrgsDocument -> System.Speech.Recognition.Grammar
Public Sub New (srgsDocument As SrgsDocument)

매개 변수

srgsDocument
SrgsDocument

음성 인식 문법에 대한 제약 조건입니다.

예외

srgsDocument에 루트 규칙이 포함되지 않습니다.

srgsDocument이(가) null인 경우

srgsDocument확인할 수 없는 규칙 참조를 포함합니다.

예제

다음 예제에서는 인스턴스에서 음성 인식 문법을 SrgsDocument 만든 다음 개체를 Grammar 생성하는 데 사용됩니다.

private static Grammar CreateSrgsDocumentGrammar()  
{  
  // Create the SrgsDocument.  
  SrgsDocument document = new SrgsDocument();  

  // Create the Cities rule and add it to the document.  
  SrgsRule citiesRule = new SrgsRule("Cities");  

  SrgsOneOf cityChoice = new SrgsOneOf();  
  cityChoice.Add(new SrgsItem("Seattle"));  
  cityChoice.Add(new SrgsItem("Los Angeles"));  
  cityChoice.Add(new SrgsItem("New York"));  
  cityChoice.Add(new SrgsItem("Miami"));  

  citiesRule.Add(cityChoice);  
  document.Rules.Add(citiesRule);  

  // Create the Main rule and add it to the document.  
  SrgsRule mainRule = new SrgsRule("Main");  
  mainRule.Scope = SrgsRuleScope.Public;  

  SrgsItem item = new SrgsItem("I would like to fly from");  
  item.Add(new SrgsRuleRef(citiesRule));  
  item.Add(new SrgsText("to"));  
  item.Add(new SrgsRuleRef(citiesRule));  

  mainRule.Add(item);  
  document.Rules.Add(mainRule);  

  // Set the root rule.  
  document.Root = mainRule;  

  // Create the Grammar object.  
  Grammar citiesGrammar = new Grammar(document);  
  citiesGrammar.Name = "SrgsDocument Cities Grammar";  

  return citiesGrammar;  
}  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 인수 SrgsDocument 가 필요한 초기화 처리기를 포함해서는 안 됩니다.

A에는 SrgsDocument 루트 규칙이 있을 수 있습니다. 루트 규칙을 지정하는 개체를 만들 Grammar 려면 또는 Grammar 생성자를 사용합니다Grammar.

음성 인식을 Grammar SrgsDocument 만들고 상대 규칙 참조를 확인하는 데 사용할 기본 URI를 지정하려면 생성자를 사용합니다 Grammar .

추가 정보

적용 대상

Grammar(String, String)

파일에서 Grammar 클래스의 새로운 인스턴스를 초기화하고 루트 규칙을 지정합니다.

public:
 Grammar(System::String ^ path, System::String ^ ruleName);
public Grammar (string path, string ruleName);
new System.Speech.Recognition.Grammar : string * string -> System.Speech.Recognition.Grammar
Public Sub New (path As String, ruleName As String)

매개 변수

path
String

지원되는 형식으로 음성 인식 문법을 설명하는 파일의 경로입니다.

ruleName
String

음성 인식 문법의 진입점으로 사용하는 규칙의 식별자이거나, 문법 설명의 기본 루트 규칙을 사용하는 null입니다.

예외

ruleName이 확인할 수 없거나 public이 아닙니다. 또는 path가 빈 문자열("")이거나 ruleNamenull이고 문법 설명에서 루트 규칙을 정의하지 않습니다.

path이(가) null인 경우

파일에 올바른 설명이 포함되어 있지 않거나 확인할 수 없는 규칙 참조가 포함된 문법을 설명합니다.

예제

다음 예제에서는 파일에서 로컬 SRGS 파일(cities.xml)을 로드하고 문법의 루트로 사용할 규칙을 지정합니다. cities.xml 파일의 내용은 C# 예제를 따르는 XML 예제에 나타납니다.

// Load a cities grammar from a local file, use a specific  
// rule as the root of the grammar, and return the new grammar.  
private static Grammar CreateGrammarFromFile2()  
{  
  Grammar citiesGrammar = new Grammar(@"c:\temp\cities.xml", "Main");  
  citiesGrammar.Name = "SRGS File Cities Grammar 2";  
  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 설명은 인수가 필요한 초기화 처리기를 정의해서는 안 됩니다.

이 생성자는 다음 형식에서 인스턴스를 만들 Grammar 수 있습니다.

이 생성자는 XML 형식 문법 파일을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 사전에 문법을 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

상대 규칙 참조를 Grammar 확인하는 데 사용할 기본 URI를 지정하는 URI를 만들려면 파일에 대한 파일 스트림을 열고 생성자를 사용합니다 Grammar .

추가 정보

적용 대상

Grammar(GrammarBuilder)

Grammar 개체에서 GrammarBuilder 클래스의 새 인스턴스를 초기화합니다.

public:
 Grammar(System::Speech::Recognition::GrammarBuilder ^ builder);
public Grammar (System.Speech.Recognition.GrammarBuilder builder);
new System.Speech.Recognition.Grammar : System.Speech.Recognition.GrammarBuilder -> System.Speech.Recognition.Grammar
Public Sub New (builder As GrammarBuilder)

매개 변수

builder
GrammarBuilder

음성 인식 문법에 대한 제약 조건을 포함하는 GrammarBuilder의 인스턴스

예제

다음 예제에서는 음성 인식 문법을 사용 하 여 Choices 개체를 GrammarBuilder 만듭니다. Grammar 생성자는 개체에서 Grammar 개체를 GrammarBuilder 만듭니다.

// Create a grammar using a GrammarBuilder and return the new grammar.   
private static Grammar CreateGrammarBuilderGrammar()  
{  
  GrammarBuilder builder = new GrammarBuilder();  

  Choices cityChoice = new Choices (new string[]   
  {"Seattle", "New York", "Miami", "Los Angeles"});  

  builder.Append("I would like to fly from");  
  builder.Append(cityChoice);  
  builder.Append("to");  
  builder.Append(cityChoice);  

  Grammar citiesGrammar = new Grammar(builder);  
  citiesGrammar.Name = "GrammarBuilder Cities Grammar";  

  return citiesGrammar;  
}  

추가 정보

적용 대상

Grammar(Stream)

Grammar에서 Stream 클래스의 새 인스턴스를 초기화합니다.

public:
 Grammar(System::IO::Stream ^ stream);
public Grammar (System.IO.Stream stream);
new System.Speech.Recognition.Grammar : System.IO.Stream -> System.Speech.Recognition.Grammar
Public Sub New (stream As Stream)

매개 변수

stream
Stream

지원되는 형식의 음성 인식을 문법을 설명하는 스트림

예외

stream 은 루트 규칙을 포함하지 않는 문법을 설명합니다.

stream이(가) null인 경우

스트림에 문법에 대한 올바른 설명이 포함되어 있지 않거나 스트림이 확인할 수 없는 규칙 참조가 포함된 문법을 설명합니다.

예제

다음 예제에서는 파일 스트림을 사용하여 로컬 SRGS 파일(cities.xml)에서 음성 인식 문법을 만듭니다. C# 예제에 따라 cities.xml 파일의 내용이 나타납니다.

// Load a cities grammar from an I/O stream and    
// return the new grammar.   
private static Grammar CreateGrammarFromStream()  
{  
  string fileName = @"c:\temp\cities.xml";  
  Grammar citiesGrammar =  
    new Grammar(new FileStream(fileName, FileMode.Open));  
  citiesGrammar.Name = "Stream Cities Grammar";  
  return citiesGrammar;  
}  
<?xml version="1.0" encoding="UTF-8" ?>  
<grammar version="1.0" xml:lang="en-US"  
         xmlns="http://www.w3.org/2001/06/grammar"  
         tag-format="semantics/1.0" root="Main">  

  <!-- cities.xml:   
    Defines an SRGS grammar for requesting a flight. This grammar includes  
    a Cities rule that lists the cities that can be used for departures  
    and destinations. -->  

  <rule id="Main">  
    <item>  
      I would like to fly from <ruleref uri="#Cities"/>  
      to <ruleref uri="#Cities"/>  
    </item>  
  </rule>  

  <rule id="Cities" scope="public">  
    <one-of>  
      <item>Seattle</item>  
      <item>Los Angeles</item>  
      <item>New York</item>  
      <item>Miami</item>  
    </one-of>  
  </rule>  
</grammar>  

설명

이 생성자는 초기화 처리기에 매개 변수를 전달하지 않으며 설명은 인수가 필요한 초기화 처리기를 정의해서는 안 됩니다.

이 생성자는 다음 형식에서 Grammar 인스턴스를 만들 수 있습니다.

이 생성자는 XML 형식 문법 파일을 이진 형식으로 컴파일하여 음성 인식 엔진의 로드 및 사용을 최적화합니다. 메서드 중 하나를 Compile 사용하여 문법을 미리 컴파일하여 XML 형식 문법에서 개체를 생성하는 Grammar 데 필요한 시간을 줄일 수 있습니다.

SRGS 문법은 루트 규칙을 정의할 수 있습니다. 스트림에서 개체를 Grammar 만들고 루트 규칙을 지정하려면 해당 또는 Grammar 생성자를 사용합니다Grammar.

스트림에서 개체를 Grammar 만들고 상대 규칙 참조를 확인하는 데 사용할 기본 URI를 지정하려면 생성자를 사용합니다 Grammar .

추가 정보

적용 대상