Grammars
A grammar is describes the words and phrases that the recognizer will understand, and interprets when they are spoken. Grammars are invoked in a VoiceXML file, and loaded by the recognizer at runtime to convert spoken responses into information the voice application can use. Grammars can also import other grammars.
A typical voice application may invoke many grammars during the course of a conversation. You may require a different grammar each time your application prompts the caller for information, as well as a global grammar to interpret general commands that the caller may speak at any time.
Grammar development is a central part of voice application development, and involves many complex issues.
Sources
There are three basic sources for grammars:
- Inline grammars are very small grammars that are coded directly in a VoiceXML file, and interpreted by the Voice Browser service at runtime.
- Built-in grammars are included as part of the Voice Platform installation. They cover common words like numbers and dates, and can be used without further development.
The VoiceXML specification defines several built-in grammars that support different field types (boolean, date, digits, currency, number, phone, and time). Some Nuance language packs support additional built-in grammars. For example, the US English language supports a socialsecurity built-in grammar that interprets 9-digit US Social Security numbers, while the British English language supports a national_insurance grammar that recognizes UK citizens’ alphanumeric national insurance numbers.
- External grammars are contained in separate files, which are invoked as needed. An external grammar may be precompiled into a binary file for faster recognition, or written as a text document and compiled at runtime.
When an external grammar is written as a text file, it must be encoded as an XML document that adheres to version 1.0 of the W3C Speech Recognition Grammar Specification.
Note: Within the Voice Platform documentation set, we adopt the term “GrXML” as shorthand to refer to the XML format of the SRGS.
External and inline grammars must be coded by the grammar developer, while built-in grammars are provided as part of the Voice Platform installation.
Samples
The grammars for PizzaTalk are located in:
%Voice Platform_HOME%\appservice\applications\webapps\PizzaTalk\grammars\
The grammar files all end in a .grxml extension. The application VoiceXML files refer to these grammar files, and compile them at runtime.
Built-in grammar parameters
The Voice Platform implementations of built-in grammars allow you to specify certain parameters affecting their use in any given context. For example, when using the date grammar you can specify a range of dates that will be accepted.
See the Language Supplement from your language pack for full information on parameters that apply to each built-in grammar. The Voice Platform default installation includes the American English Language Supplement in:
%SWISRSDK%\documentation\languages
Where %SWISRSDK% is an environment variable whose value is the path to the directory where the Voice Platform recognizer was installed (by default, in Windows this directory is C:\Program Files\Nuance\Voice Platform\Recognizer\).
N-best processing
Normally the recognizer evaluates the possible interpretations, and only returns the top one. However, you can have the recognizer return two or more of the top-ranked interpretations, and choose between them in the application itself.
See Using n-best for a discussion of strategies for using this feature.
Natural language grammars
In addition to regular GrXML grammars, Voice Platform supports various methods for advanced natural language recognition. These methods let you create grammars that are able to interpret an exceptionally broad range of words and phrases, using statistical models derived from real data. However, natural language techniques require that you prepare training files from the existing data.
These training files are text files, but the format depends on the natural language method being used.