legacy:vxi_developer_guide:voicexml_references:elements:grammar

< grammar >

The < grammar > element specifies a grammar (word or phrase) for speech recognition. When the grammar is recognized, the application may perform an action (such as a transition to another field item), or assign values to a field item variable. Multiple values can also be assigned with mixed initiative forms.

NOTE:

Inline grammars that use the XML grammar format will be passed into the Speech Recognition Engine as an XML document. The interpreter first decodes the VoiceXML document and then re-encodes the inline grammar into an XML document to pass to the Engine.

<grammar>
xml:lang="language"
src="URI"
scope="dialog" | "document"
type="MIME_Type"
mode="dtmf" | "voice"
root="String"
version="version_number"
weight="positive floating_point"
fetchhint="prefetch" | "safe"
fetchtimeout="time_interval"
maxage="time_interval"
maxstale="time_interval">
inline grammar
</grammar>
xml:langThe xml:lang attribute is the language and locale identifier of the grammar. Please refer to the multi-language support tutorial for detailed information. This attribute is optional and defaults to en-US. The value choices are en-US, en-UK, fr-FR…
srcThe src attribute is the URI of the grammar specification. The URI can have one of the following formats:
* External grammar file – the URI of the grammar file.
* Built-in grammars – the builtin:grammar/type or builtin:dtmf/type, refer to <field> element for built-in types.
scopeThe scope attribute defines the scope of the grammar. This attribute can be defined only if this < grammar > element is the child of a < form > or < menu > element. This attribute is optional and defaults to dialog.
* dialog – the grammar is only active within the form.
* document – the grammar is active throughout the document. If this is an application root document and the grammar is active throughout the application.
typeThe type attribute defines the MIME type of grammar format.
The following types are supported:
* application/x-jsgf for internal speech recognition.
* text/x-grammar-choice for voice speech recognition.
* text/x-grammar-choice-dtmf for DTMF recognition.
* application/srgs+xml for SRGS/XML grammar format.
* application/lumenvox-abnf for Lumenvox/ABNF format.
* application/isolated for Verbio/Isolated grammar format.
* application/verbio-abnf for Verbio/ABNF grammar format.
modeThe mode attribute defines the mode of the grammar. This attribute is required.
* voice – the voice input. \\* dtmf – the DTMF input. This replaces the obsolete <dtmf> element in VoiceXML 1.0.
rootThe root attribute specifies the root rule of the grammar when this is an inline XML grammar. This attribute is optional and defaults to default rule.
versionThe version attribute defines the version of the grammar. This attribute is optional and defaults to 1.0.
weightThe weight attribute defines the weight of a grammar, which indicates the possible occurrence of the grammar which can potentially increase recognition accuracy. Grammar weights only affect grammar processing; they do not affect the processing of grammar results. Different speech recognition engines and VoiceXML platforms also treat weights differently. This attribute does not apply to DTMF grammars and implicit grammars (i.e. <grammar> elements as children of <option> or <choice> tags). The range of values depends on the speech recognition engine, but it is usually 0.0 to 1.0. This attribute is optional and defaults to 1.0.
fetchtimeoutThe fetchtimeout attribute is the time interval to wait for an grammar file to be fetched. This attribute is optional.
fetchhintThe fetchhint attribute defines when the grammar file should be retrieved. This attribute is optional.
* prefetch – the audio file may be downloaded when the page is loaded.
* safe – the audio file only loads when needed.
maxageThe maxage attribute indicates the maximum time in seconds that this document will use the grammar file before fetching another copy. This attribute is optional.
maxstaleThe maxstale attribute indicates the maximum time in seconds that this document will use a grammar file that exceeded the maxage time. This attribute is optional.
<choice>, <field>, <form>, <link>, <record>, <transfer>
None.
None.
None.
<?xml version="1.0"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
 <form id="translate">
  <field name="number">
   <prompt>
    Enter a number
   </prompt>
   <grammar type="text/x-grammar-choice-dtmf">
    1 {uno} |
    2 {dos} |
    3 {tres} |
    4 {cuatro} |
    5 {cinco}
   </grammar>
   <filled>
    <prompt>
     <value expr="lastresult$.utterance" />
     in Spanish is
     <value expr="number" />
    </prompt>
   </filled>
  </field>
 </form>
</vxml>
  • legacy/vxi_developer_guide/voicexml_references/elements/grammar.txt
  • Last modified: 2017/07/28 23:53
  • by javier