Since the VoiceXML Forum Community Bulletin Board is increasingly besieged by spammers, going forward Iâ€™m going to cross post responses I submit there on this site so that interested parties (assuming there are any ;-)) can read them.
This response relates to the use of semantic interpretation in VoiceXML applications, something I have written on before. I hope readers find the exchange below helpful.
Is there a way to map a response to a certain value? For instance, if the user says â€œyes,â€ â€œsure,â€ or â€œyeahâ€ I’d like to put 1 in the database? If the user says â€œno,â€ â€œnope,â€ or â€œnahâ€ I’d put 0.
There are a couple of option open to you if all you are using is a simple yes/no grammar.
<var name="convert" expr="0"/>
<field name="F_1" type="boolean">
<prompt>Do you think VoiceXML rocks?</prompt>
<!-- If the user says yes, then the expression in the "cond" attribute will evaluate to true -->
<assign name="convert" expr="1"/>
<!-- If the preceding if statement did not execute, then expression in the cond attribute evaluated to false. User said no, so we keep our original value of 0 -->
<submit next="mypage.jsp" namelist="convert"/>
Option 2 = you can use the <tag> element with a custom yes/no grammar to return a 1 or a 0. (Check your platform vendor’s documentation on this element, as there is some variation.)
<!-- In your VoiceXML document, reference the yes/no grammar -->
<!-- Contents of yesno.grxml file -->
< ?xml version = "1.0"?>
<grammar xml:lang="en-US" version="1.0" root="R_1" type="application/srgs+xml" xmlns="http://www.w3.org/2001/06/grammar">
<item>yes <tag>F_1=1;</tag> </item>
<item>yeah <tag>F_1=1;</tag> </item>
<item>hells yeah <tag>F_1=1;</tag> </item>
<item>yur damn skippy <tag>F_1=1;</tag> </item>
<item>no <tag>F_1=0;</tag> </item>
<item>nope <tag>F_1=0;</tag> </item>
<item>no way <tag>F_1=0';</tag> </item>
<item>hells no <tag>F_1=0;</tag> </item>
This has the effect of filling the field named “F_1” with the value specified in the <tag> when one of the grammar items is recognized. A few good links to get you started follow: