Speech Recognition Grammars: Specify What a Recognizer Should Hear
Learn how recognition grammars constrain spoken phrases, how SRGS formats work, and what to test.
Speech Recognition Grammars: Specify What a Recognizer Should Hear
A speech recognition grammar specifies the words and patterns a recognizer should listen for. W3C SRGS 1.0 represents grammars in XML or ABNF, two forms designed to map to the same accepted language and interpretation.
Use a grammar for bounded choices such as a confirmation. Put natural alternatives into one rule, then test each expected phrase, an unexpected phrase, and silence. A grammar does not set pronunciation lexicons or recognizer thresholds; platform support and result details must be checked with the recognizer.
<?xml version="1.0" encoding="UTF-8"?>
<grammar version="1.0" xml:lang="en-US" mode="voice" root="answer"
xmlns="http://www.w3.org/2001/06/grammar">
<rule id="answer" scope="public">
<one-of>
<item>Choose 1 or 2.</item>
<item>I did not hear you. Choose 1 or 2.</item>
</one-of>
</rule>
</grammar>References
[Speech Recognition Grammar Specification (SRGS) 1.0 — W3C Recommendation (2004)](https://www.w3.org/TR/speech-grammar/)
[VoiceXML 2.0 — W3C Recommendation (2004)](https://www.w3.org/TR/voicexml20/)