dcsimg
December 2, 2016
Hot Topics:

VoiceXML 2.0 Grammars, Part I

  • October 7, 2002
  • By Jonathan Eisenzopf
  • Send Email »
  • More Articles »

Grammar Headers

ABNF and XML grammar files must contain specific header information; otherwise, the VoiceXML interpreter will fail to recognize the grammar properly. The elements of a grammar file are:

  • grammar declaration
  • language/locale
  • mode
  • root grammar
ABNF
# ABNF 1.0 ISO-8859-1;
language en;
mode voice;
root $topRule;
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" 
  xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en" mode="voice" root="topRule">
...

Grammar declaration

The grammar declaration specifies the grammar version and optionally, the character encoding scheme that should be used. The grammar version should always be set to 1.0. The character encoding specifies the character symbols that will be used for the grammar. For example, ISO-8859-1 is usually the character encoding used for English. Asian languages including Japanese and Chinese (Big5 or Mandarine) would use a different encoding scheme. In ABNF grammars, this is the first line. In XML, the encoding scheme is defined by the encoding attribute of the XML declaration (the first line of any XML file). 

ABNF
# ABNF 1.0 ISO-8859-1;
language en;
mode voice;
root $topRule;
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" 
  xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en" mode="voice" root="topRule">
...

The grammar version in an XML grammar is defined by the version attribute of the <grammar> element.

Language

Unless the grammar is a DTMF grammar, a language must be specified in the grammar header. For ABNF grammars, the language parameter defines the language (in this example, US English):

ABNF
# ABNF 1.0 ISO-8859-1;
language en;
mode voice;
root $topRule;
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" 
  xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en" mode="voice" root="topRule">
...

The language in an XML grammar is specified by the xml:lang attribute of the <grammar> element.

Mode

Grammars can be scoped for speech input (voice) or touch-tone input (dtmf) based on the value of the mode parameter. The default mode is voice. If the grammar is scoped dtmf, then speech input will not be recognized. VoiceXML 2.0 grammars do not allow mixed mode grammars. That means that a voice scoped grammar cannot include a dtmf scoped grammar or vice versa. In cases where we may want an application to accept both voice and DTMF input, two separate grammars can be defined within a given VoiceXML scope so long as they aren't combined into a single grammar in any way.

ABNF
# ABNF 1.0 ISO-8859-1;
language en;
mode voice;
root $topRule;
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" 
  xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en" mode="dtmf" root="topRule">
...

Root grammar 

When grammars contain many sub-grammar rules in a single file, it's important to identify the root grammar, or main the grammar that will be executed when a VoiceXML dialog calls the grammar file. 

ABNF
# ABNF 1.0 ISO-8859-1;
language en;
mode voice;
root $topRule;
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar version="1.0" 
  xmlns="http://www.w3.org/2001/06/grammar"
  xml:lang="en" mode="voice" root="topRule">
...

Filename Extensions

The filename extension for ABNF grammars is .gram and .grxml for XML grammars. This is the recommended (but not required) filename extension format for grammar files.

About Jonathan Eisenzopf

Jonathan is a member of The Ferrum Group, LLC which specializes in Voice Web consulting and training. Feel free to send an email to eisen@ferrumgroup.com regarding questions or comments about this or any article.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel