Specifies a speech-recognition grammar.
Specifies a grammar to be used within some VoiceXML tag such as <field>, <form>, or <link>. When the speech-recognition engine detects a match with a grammar, it may cause a transition to another dialog (if the grammar is in a menu item or link) or assign a return value to assign to an input variable (if the grammar is in a form or input item).
The <grammar> element serves two primary purposes:
| | To define the grammar or point to a predefined grammar | ||||||||||||||||||||||||
The <grammar> element can either contain the entire grammar definition directly, point to an external grammar file in one of several formats, or point to a built-in grammar. If the grammar definition is inline and is in the XML format, then the <grammar> element allows extra attributes to support the grammar definition; these attributes are ignored for an inline grammar in any other format and they are ignored for all external grammars. | |||||||||||||||||||||||||
| | To specify aspects of how to use the grammar in the particular containing VoiceXML element. | ||||||||||||||||||||||||
For this purpose, the <grammar> element supports a set of attributes you can use with any application grammar. You can use these attributes for any grammar format and for both external and internal grammars. You cannot use these attributes for built-in grammars. |
| Attribute | Description | ||||||||||
src |
URI of the grammar specification, when it is contained in an external file. Optional (as an alternative to an inline grammar or If you specify this attribute, the element cannot have content. You specify a grammar with a URI of one of the following forms: An |
||||||||||
srcexpr |
JavaScript expression that evaluates to grammar file URI. Optional (as alternative to If you specify this attribute, the element cannot have content. You can specify either |
||||||||||
expr |
Extension. JavaScript expression that evaluates to grammar file URI. Optional (as alternative to Note: The If you specify this attribute, the element cannot have content. You can specify either |
||||||||||
mode |
New in VoiceXML 2.0. Whether the grammar is for speech or DTMF input. Optional (default is
Used to define a grammar in the XML grammar format. For an inline XML grammar, attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
root |
New in VoiceXML 2.0. Specifies the name of the root grammar rule. Required for an inline XML grammar; optional for an external XML grammar. Used to define a grammar in the XML grammar format. For an inline XML grammar, attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
tag-format |
New in VoiceXML 2.0. Indicates the content type of enclosed The only valid value is Used to define a grammar in the XML grammar format. For an inline XML grammar, attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
version |
New in VoiceXML 2.0. Version of the grammar format. Required for any XML grammar. The only allowed version is Used to define a grammar in the XML grammar format. For an inline XML grammar, attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
xml:base |
New in VoiceXML 2.0. Base URI. Optional. Used to define a grammar in the XML grammar format. For an inline XML grammar, attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
xml:lang |
New in VoiceXML 2.0. The language and optional country local identifier for the grammar. Optional (default is The accepted language identifiers are:
If an unsupported language is specified, an Used to define a grammar in the XML grammar format. For an inline XML grammar, the attribute occurs in the VoiceXML document. For an external XML grammar file, attribute occurs in the grammar file and is ignored if present in the VoiceXML document. For a grammar of any other format, this attribute is always ignored. |
||||||||||
xmlns |
New in VoiceXML 2.0. Indicates the grammar namespace. Required in an external XML grammar file. Must never occur in a VoiceXML document. |
||||||||||
xmlns:xsi |
New in VoiceXML 2.0. Indicates the location of the grammar schema. Optional in an external XML grammar file. Must never occur in a VoiceXML document. The only legal value is |
||||||||||
xmlns:schema |
New in VoiceXML 2.0. Indicates the location of the grammar schema. Optional in an external XML grammar file. Must never occur in a VoiceXML document. "http://www.w3.org/2001/06/grammar |
||||||||||
scope |
Sets the scope of the grammar. Note: A The scope of any other
Allowed on a |
||||||||||
type |
MIME type of the grammar. Optional. The currently supported types are: If you specify an unsupported type, an error is thrown. For external grammars, the default type is taken from the
For internal grammars, if the grammar definition specifies the grammar type (either directly with a declaration or indirectly by containing XML elements), the interpreter uses that type. If the grammar definition doesn't indicate the type, the interpreter uses the value of the Allowed on any |
||||||||||
universal |
Extension. Makes this grammar a "universal" grammar with the specified name so that it can be activated and deactivated using the Allowed on any |
||||||||||
fetchhint |
Specifies whether the interpreter can attempt to optimize dialog interpretation by prefetching the resource. See Prefetching Resources. Optional. Allowed only on a |
||||||||||
fetchtimeout |
Specifies the interval to wait for the resource to be returned before throwing a Allowed only on a |
||||||||||
maxage |
New in VoiceXML 2.0. Specifies the maximum acceptable age, in seconds, of the cached resource. See Maximum Age. Optional. Allowed only on a |
||||||||||
maxstale |
New in VoiceXML 2.0. Specifies the maximum acceptable time, in seconds, during which an expired cached resource can still be used. See Maximum Stale Time. Optional. Allowed only on a |
||||||||||
weight |
New in VoiceXML 2.0. Not implemented. The weight of the grammar. |
(VoiceXML 1.0 only) The following attributes can be used in applications in which the version attribute of the <vxml> tag is set to 1.0.
| Attribute | Description |
caching |
VoiceXML 1.0 only. Specifies the caching policy for the resource being fetched. See Caching. Optional. Used in place of the VoiceXML 2.0 attributes |
Multiple grammars may be active at the same time. When the speech-recognition engine detects a match from a higher level, control is passed to that grammar's parent element.
BeVocal VoiceXML supports the W3C specification, Speech Recognition Grammar Format, which defines an XML Grammar and an ABNF Grammar. The VoiceXML 2.0 specification defines the XML grammar as a must support, and the ABNF Grammar as a should support. It is expected that many VoiceXML developers will use ABNF because it is more readable and concise.
BeVocal VoiceXML additionally supports the Java JSGF format (used as examples in the VoiceXML 1.0 draft) and the Nuance GSL Grammar format.
See the following for details:
| | Examples has examples of every format. |
| | The Grammar Reference details syntax and usage of the various supported grammar formats. |
You may refer to a compiled GSL grammar using the src attribute of the <grammar> tag; for example:
<grammar src="compiled:/key"/>
However, if you want to combine a compiled grammar in a more complex way with another grammar, you can refer to a compiled grammar from within an ABNF grammar:
<grammar> <![CDATA[ #ABNF 1.0 en-US; root $script; $script = prescription $<compiled:/key>; ]]> </grammar>
Using the Grammar Compiler tool on the BeVocal Café, you can compile a grammar and receive an associated key. For information on compiling grammars, see Chapter 7, "Grammar Compiler" in Using the BeVocal Café Tools.
The VoiceXML 2.0 specification (Appendix P) includes a set of built-in grammars as a convenience to enable developers to get started writing more complex VoiceXML applications quickly. Some of the basic built-in grammars such as date and time are actually difficult to write and tune by hand, but are very useful in many applications. The basic built-in grammars are:
| Grammar Type | Description |
|
|
|
|
|
|
|
|
|
|
|
Recognizes a telephone number adhering to the North American Dialing Plan (with no extension). |
|
Note: All standard built-in grammars are supported in the Spanish language. Currently there are no extended built-in grammars for Spanish. Neither standard nor extended built-in grammars are currently supported in French Canadian. All extended built-in grammars are supported only in English. If you specify a language other than English and refer to an unsupported built-in grammar, a parse error error.unsupported.builtin is thrown.
In addition, BeVocal VoiceXML contains a set of extended built-in grammars, so VoiceXML developers can reference these quite complex grammars which have been tuned over the years by caller usage. The extended grammars are:
Note that built-in grammars can be used where other grammars are used, commonly either in fields or in forms.
A built-in grammar can be specified using the syntax:
<grammar src="builtin:grammar/type">
For example the phone type is specified using:
<grammar src="builtin:grammar/phone">
Most built-in grammars, such as phone, fill a single slot whose name is the same as the grammar name. For example, the date grammar fills a slot named date. However, some of the more complex grammars fill in multiple slots, for example airline fills in code and name.
Standard built-in dtmf-only grammars can be specified using the syntax:
<grammar src="builtin:dtmf/type">
Currently, the boolean, digits, number, and date built-in grammars are supported for dtmf-only. For other buil-tin grammars, such as phone, currency, and time, a warning is thrown that the dtmf-only version is not supported, and the regular grammar (voice and dtmf) is used. Other built-in grammars may be supported as dtmf-only in a future release.
Built-in Grammars--Fields and Forms
If the built-in grammar is used as a field grammar, the input variable is set to the slot value.
If the built-in grammar fills multiple slots:
For more details, see Chapter 1, "Using VoiceXML Grammars" in the Grammar Reference.
Built-in Grammars--Multiple Slots
The following table lists the slots for the extended built-in grammars which return multiple slots. In the case of using a built-in grammar in a <field> element, these are the properties of the field's item variable which are assigned the slot values.
| Field Type | Slots (or Properties) | ||||||||||||||||||||||||
airport |
|
||||||||||||||||||||||||
airline |
|
||||||||||||||||||||||||
datetime |
The following examples show utterances and the corresponding slots that are filled:
"four twenty-two p m on november thirtieth"
"in one hour and fifteen minutes"
|
||||||||||||||||||||||||
equity |
|
||||||||||||||||||||||||
stockindex |
|
||||||||||||||||||||||||
street |
|||||||||||||||||||||||||
streetaddress |
|
||||||||||||||||||||||||
citystate |
A property is accessed with an expression of the form:
fieldName.propertyName
For example the city property of a citystate field is accessed as follows:
<field name="mycity"> <grammar src="builtin:grammar/citystate"/> <filled> <prompt>The city is <value expr="mycity.city"/> </filled> </field>
Two standard built-in grammars, digits and boolean, can be parameterized. Specifically, you can set limits on the length of a digit string, and you can set DTMF key presses to mean yes or no. In addition, you must specify the city and state with the street and streetaddress built-in grammars; you can optionally specify the county to disambiguate a case in which the state contains two cities with the same name.
The following table shows the built-in grammars that can be parameterized and indicates which parameters are required.
You express parameter information using URI-style query syntax of the form:
builtin:grammar/typeName?parameter=value
For example, the grammar matches a sequence of exactly five digits:
<grammar src="builtin:grammar/digits?length=5">
You can specify more than one parameter, separated by semicolons. For example, the following grammar allows a user to press 7 for an affirmative answer and 9 for a negative answer:
<grammar src="builtin:grammar/boolean?y=7;n=9"/>
Note: The interpreter throws a error.badfetch event if it loads a VoiceXML file that contains a built-in grammar with an unrecognized parameter or with inconsistent parameters, such as:
<!-- ERROR: Inconsistent parameters for built-in grammar--> <grammar src="builtin:grammar/digits?minlength=5;maxlength=1">
Built-in Extended Grammars--Input
The following table shows example user inputs for each extended built-in grammar.
| Grammar Type | Example Inputs |
airport |
|
airline |
|
equity |
|
stockindex |
|
street |
|
streetaddress |
|
citystate |
Built-in Extended Grammars--Output.
In VoiceXML 2.0 the field's type attribute no longer defines an implicit <say-as> type to output the field's value. Instead it plays the value in normal TTS. You must now use the type attribute of <say-as> for a type-specific read-out of the value (in TTS).
The bevocal:mode attribute of <say-as> can be used to define recorded output for some types. See the <say-as> tag for details.
| Grammar Type | Say-As Type | Audio Output | String Result |
airport |
airport |
||
airline |
airline |
||
equity |
equity |
||
stockindex |
stockindex |
||
street |
street |
||
streetaddress |
address |
||
citystate |
citystate |
|
|||
|
| Parents | Children |
|
|
| | VoiceXML 2.0 Specification: <grammar> |
| | Grammar Reference |
| | <say-as> |
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar mode="dtmf" root="pin" version="1.0"> <rule id="digit"> <one-of> <item> 0 </item> <item> 1 </item> <item> 2 </item> <item> 3 </item> <item> 4 </item> <item> 5 </item> <item> 6 </item> <item> 7 </item> <item> 8 </item> <item> 9 </item> </one-of> </rule> <rule id="pin" scope="public"> <item repeat="4"><ruleref uri="#digit"/></item> </rule> </grammar> <filled> You entered <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar mode="voice" root="pin" version="1.0"> <rule id="digit"> <one-of> <item> 0 </item> <item> 1 </item> <item> 2 </item> <item> 3 </item> <item> 4 </item> <item> 5 </item> <item> 6 </item> <item> 7 </item> <item> 8 </item> <item> 9 </item> </one-of> </rule> <rule id="pin" scope="public"> <item repeat="4"><ruleref uri="#digit"/></item> </rule> </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar type="application/grammar"> <![CDATA[ #ABNF 1.0; mode dtmf; root $pin; $digit = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9); $pin = $digit<4> ; ]]> </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar type="application/grammar"> <![CDATA[ #ABNF 1.0; root $pin; $digit = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9); $pin = $digit<4> ; ]]> </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar type="application/x-nuance-gsl"> FourDigits (Digit Digit Digit Digit) Digit [dtmf-1 dtmf-2 dtmf-3 dtmf-4 dtmf-5 dtmf-6 dtmf-7 dtmf-8 dtmf-9 dtmf-0] </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar type="application/x-nuance-gsl"> FourDigits (Digit Digit Digit Digit) Digit [1 2 3 4 5 6 7 8 9 0] </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
<?xml version="1.0" ?> <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <field name="pin"> What is your pin? <grammar> <![CDATA[ #JSGF 1.0; grammar pin; <digit> = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9); public <pin> = <digit> <digit> <digit> <digit>; ]]> </grammar> <filled> You said <value expr="pin"/> </filled> </field> </form> </vxml>
| Café Home |
Developer Agreement |
Privacy Policy |
Site Map |
Terms & Conditions Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL |