# Differences

This shows you the differences between two versions of the page.

 — developer_guide:voicexml_references:elements:grammar [2015/10/27 12:38] (current)borja created 2015/10/27 12:38 borja created 2015/10/27 12:38 borja created Line 1: Line 1: + ====== < grammar > ====== + ===== Description ===== + + 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. ​ + + ===== Syntax ===== + + <​code>​ + <​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 + ​ + ​ + + ===== Attributes ===== + + |xml:​lang|The 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...| + |src|The 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.| + |scope|The 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.| + |type|The 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.| + |mode|The 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.| + |root|The 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.| + |version|The version attribute defines the version of the grammar. ​ This attribute is optional and defaults to 1.0.| + |weight|The 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.| + |fetchtimeout|The fetchtimeout attribute is the time interval to wait for an grammar file to be fetched. This attribute is optional.| + |fetchhint|The 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.| + |maxage|The maxage attribute indicates the maximum time in seconds that this document will use the grammar file before fetching another copy. This attribute is optional.| + |maxstale|The 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.| + + ===== Parents ===== + + <​code>​ + <​choice>,​ <​field>,​ <​form>,​ <​link>,​ <​record>,​ <​transfer>​ + ​ + + ===== Children ===== + + <​code>​ + None. + ​ + + ===== Extensions ===== + + <​code>​ + None. + ​ + + ===== Limitations/​Restrictions ===== + + <​code>​ + None. + ​ + + ===== Example Code ===== + + <​code>​ + ​ + ​ + <​form id="​translate">​ + ​ + <​prompt>​ + Enter a number + ​ + <​grammar type="​text/​x-grammar-choice-dtmf">​ + 1 {uno} | + 2 {dos} | + 3 {tres} | + 4 {cuatro} | + 5 {cinco} + ​ + <​filled>​ + <​prompt>​ + <​value expr="​lastresult\$.utterance"​ /> + in Spanish is + <​value expr="​number"​ /> + ​ + ​ + ​ + ​ + ​ +