Browse
 
Tools
Rss Categories

Recognizer DEFINE-GRAMMAR

Reference Number: AA-01652 Views: 27978 0 Rating/ Voters

The DEFINE-GRAMMAR method, from the client to the server, provides one or more grammars and tells the server to define, download if needed, and compile the specified grammar(s).

If the recognizer resource belonging to the session is in the idle state and is able to successfully load and compile the grammar, the status will return a COMPLETE reply with Status-Code indicating success.

If the recognizer could not define the grammar for some reason, for example if the download failed or the grammar failed to compile, or the grammar was in an unsupported form, the MRCP response for the DEFINE-GRAMMAR method will contain a failure status code of 407, and a completion-cause header field describing the failure reason.


MRCPV1 DEFINE-GRAMMAR Example:

C->S:DEFINE-GRAMMAR 543258 MRCP/1.0
     Content-Type:application/grammar+xml
     Content-Id:helpgrammar@root-level.store
     Content-Length:104

     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xml:lang="en-US" version="1.0">

     <rule id="request">
         I need help
     </rule>

     </grammar>

S->C:MRCP/1.0 543258 200 COMPLETE
     Completion-Cause:000 success


MRCPV2 DEFINE-GRAMMAR Example:

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543258
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:application/srgs+xml
     Content-ID:<helpgrammar@root-level.store>
     Content-Length:...

     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xmlns="http://www.w3.org/2001/06/grammar"
              xml:lang="en-US" version="1.0">

           <rule id="request">
                 I need help
           </rule>

     </grammar>

S->C:MRCP/2.0 ... 543258 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success

 



There are a number of ways in which grammars can be specified or referenced when using MRCP, which are described in the MRCPv1 and MRCPv2 specification documents, however a brief overview of the methods supported by LumenVox are shown below.

Typically, the type of reference used when specifying a grammar is indicated in the Content-Type header of the DEFINE-GRAMMAR request.

Inline XML-Based Speech Recognition Grammar Specification (SRGS) Grammar:

When describing inline XML-Based SRGS (GrXML), the grammar text is embedded within the data of the request.

In MRCPv1, the Content-Type for inline GrXML is application/grammar+xml

C->S:DEFINE-GRAMMAR 543258 MRCP/1.0
     Content-Type:application/grammar+xml
     Content-Id:helpgrammar@root-level.store
     Content-Length:104

     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xml:lang="en-US" version="1.0">

     <rule id="request">
         I need help
     </rule>

     </grammar>

S->C:MRCP/1.0 543258 200 COMPLETE
     Completion-Cause:000 success


In MRCPv2, the Content-Type for this inline GrXML is application/srgs+xml

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543258
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:application/srgs+xml
     Content-ID:<helpgrammar@root-level.store>
     Content-Length:...

     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xmlns="http://www.w3.org/2001/06/grammar"
              xml:lang="en-US" version="1.0">

           <rule id="request">
                 I need help
           </rule>

     </grammar>

S->C:MRCP/2.0 ... 543258 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success



Inline ABNF-Based Speech Recognition Grammar Specification (SRGS) Grammar:

When describing inline ABNF style SRGS, the grammar text is embedded within the data of the request.

In MRCPv1, the Content-Type for inline ABNF is application/grammar

C->S:DEFINE-GRAMMAR 543259 MRCP/1.0
     Content-Type:application/grammar
     Content-Id:helpgrammar@root-level.store
     Content-Length:...

     #ABNF 1.0;

     //// the default grammar language is US English ////
     language en-US;
     ////////////////////////////////////////////////////
      
     $request =
              I need help
           ;

S->C:MRCP/1.0 543259 200 COMPLETE
     Completion-Cause:000 success


In MRCPv2, the Content-Type for inline ABNF is application/srgs

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543259
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:application/srgs
     Content-ID:<helpgrammar@root-level.store>
     Content-Length:...

     #ABNF 1.0;

     //// the default grammar language is US English ////
     language en-US;
     ////////////////////////////////////////////////////

     $request =
                 I need help
           ;

S->C:MRCP/2.0 ... 543259 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success


Fetching Grammars from URI Reference:

Grammar documents that are located on HTTP or file servers on the local or remote machines can use Content-Type of text/uri-list. This is the same for both MRCPv1 and MRCPv2

C->S:DEFINE-GRAMMAR 543260 MRCP/1.0
     Content-Type:text/uri-list
     Content-Id:helpgrammar@root-level.store
     Content-Length:...

     session:help@root-level.store
     http://www.lumenvox.com/Directory-Name-List.grxml
     http://www.lumenvox.com/Department-List.grxml
     http://www.lumenvox.com/TAC-Contact-List.grxml
     session:menu1@menu-level.store

S->C:MRCP/1.0 543260 200 COMPLETE
     Completion-Cause:000 success

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543260
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:text/uri-list
     Content-ID:<helpgrammar@root-level.store>
     Content-Length:...

     session:help@root-level.store
     http://www.lumenvox.com/Directory-Name-List.grxml
     http://www.lumenvox.com/Department-List.grxml
     http://www.lumenvox.com/TAC-Contact-List.grxml
     session:menu1@menu-level.store

S->C:MRCP/2.0 ... 543260 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success



Mixing inline URI References:

If there is a need to combine the use of both inline and URI references when specifying grammars, the Content-Type is mixed/multipart.Embedded within the multi-part content block for MRCPv1 there may be content for the text/uri-listapplication/grammar or application/grammar+xml.  Embedded within the multi-part content block for MRCPv2 there may be content for thetext/uri-listapplication/srgs or application/srgs+xml

C->S:DEFINE-GRAMMAR 543263 MRCP/1.0
     Content-Type:multipart/mixed; boundary="break"
     Content-Length:...

     --break
     Content-Type:text/uri-list
     Content-Length:...
     http://www.example.com/Directory-Name-List.grxml
     http://www.example.com/Department-List.grxml
     http://www.example.com/TAC-Contact-List.grxml
     
     --break
     Content-Type:application/grammar+xml
     Content-ID:<request1@form-level.store>
     Content-Length:...
     
     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xml:lang="en-US" version="1.0">

     <rule id="request">
         I need help
     </rule>

     </grammar>
     --break--

S->C:MRCP/1.0 543263 200 COMPLETE
     Completion-Cause:000 success

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543263
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:multipart/mixed; boundary="break"
     Content-Length:...

     --break
     Content-Type:text/uri-list
     Content-Length:...
     http://www.example.com/Directory-Name-List.grxml
     http://www.example.com/Department-List.grxml
     http://www.example.com/TAC-Contact-List.grxml
     
     --break
     Content-Type:application/srgs+xml
     Content-ID:<request1@form-level.store>
     Content-Length:...
     
     <?xml version="1.0"?>

     <!-- the default grammar language is US English -->
     <grammar xml:lang="en-US" version="1.0">

     <rule id="request">
         I need help
     </rule>

     </grammar>
     --break--

S->C:MRCP/2.0 ... 543263 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success



Reference List with Weights:

An additional option for specifying grammars is to use the text/grammar-ref-list Content-Type, which is similar to the text/uri-list Content-Type, but additionally allows weights to be specified for each referenced grammar element in the list. Although this media type is not explicitly supported by MRCPv1, the LumenVox implementation supports this type for both MRCPv1 and MRCPv2 protocols.

C->S:DEFINE-GRAMMAR 543264 MRCP/1.0
     Content-Type:text/grammar-ref-list
     Content-Id:helpgrammar@root-level.store
     Content-Length:...

     <http://example.com/grammars/field1.gram>
     <http://example.com/grammars/field2.gram>
;weight="0.85"
     <session:field3@form-level.store>;weight="0.9"
     <http://example.com/grammars/universals.gram>;weight="0.75"


S->C:MRCP/1.0 543264 200 COMPLETE
     Completion-Cause:000 success

C->S:MRCP/2.0 ... DEFINE-GRAMMAR 543264
     Channel-Identifier:32AECB23433801@speechrecog
     Content-Type:text/grammar-ref-list
     Content-ID:<helpgrammar@root-level.store>
     Content-Length:...

     <http://example.com/grammars/field1.gram>
     <http://example.com/grammars/field2.gram>;weight="0.85"
     <session:field3@form-level.store>;weight="0.9"
     <http://example.com/grammars/universals.gram>;weight="0.75"

S->C:MRCP/2.0 ... 543264 200 COMPLETE
     Channel-Identifier:32AECB23433801@speechrecog
     Completion-Cause:000 success