| VoiceXML 2.1 Development Guide | Home | Frameset Home |
|
<![CDATA[
[
(big old jet airliner) { <F_1 "Steve Miller"> }
(bingo jet said right on) { <F_1 "Bingo"> }
(jango fett left a light on) { <F_1 "Jango"> }
(big old bet on a rhino) { <F_1 "Rhino"> }
]
]]>
SONG [
(little deuce coop) { <F_1 "beach boys"> }
(little goose poop) { <F_1 "goose poop"> }
(little doo scoop) { <F_1 "doo scoop"> }
(little boot scoop) { <F_1 "boot scoop"> }
(little blue sloop) { <F_1 "blue sloop"> }
]
<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
<meta name="maintainer" content="yourEmail@here.com"/>
<property name="maxnbest" value="5"/>
<property name="com.nuance.rec.DoNBest" value="1" />
<var name="resultLen"/>
<var name="resultArray"/>
<var name="myArray"/>
<form id="F1">
<field name="F_1" slot="F_1">
<prompt bargein="true">
what the heck were the beach boys talking about in
that song? i bet you dont know either.
</prompt>
<grammar src="Lyrics.grammar#SONG"/>
<filled>
</filled>
</field>
<block name="B_1">
<script language="Javascript">
</script>
<field name="Bool_0" type="boolean">
<prompt>
</prompt>
<filled>
</filled>
</field>
</block>
</form>
</vxml>
<property> designating that we do want to enable Nbesting, and that the maximum amount of possible matches for our NBest list to cycle through is '5'. We have also declared a few empty variables for use later on -- these will hold the values for length of our array and the actual value of the array itself, respectively. We also put in a <block> to hold our post-processing script (it will delete unwanted utterances) and a boolean <field> grammar to prompt the user to confirm his utterance before moving on. Fear not, we will fill in all the blanks, and have a complete script before the sundown beach-blanket bingo party. <block>, remember? Let's skip right on down and see what this is all about:
<block name="B_1">
<script language="javascript">
<![CDATA[
function deleteElement(array, n) {
// DEFINE THE PARAMETERS OF OUR FUNCTION
var length = array.length;
// SET THE LENGTH OF THE ARRAY EQUAL
// TO A VARIABLE CALLED 'LENGTH'
if (n >= length || n<0)
// IF OUR COUNT IS GREATER OR EQUAL TO THE ARRAY
// LENGTH OR IF IT IS EQUAL TO ZERO, DO NOTHING
return;
for (var i=n; i<length-1; i++)
// LOOP FROM 'n' TO THE ARRAY LENGTH MINUS 1
// INCREMENTING THE VALUE OF 'n' EACH TIME
array[i] = array[i+1];
// THE VALUE OF THE ARRAY ELEMENT [i] BECOMES
// THE VALUE OF THE ELEMENT AHEAD OF IT
// EX. array[1] = array[2]
array.length--;
// WHEN THE LOOP IS DONE, SHORTEN THE ARRAY LENGTH
// WHICH REMOVES THE LAST ELEMENT AND SETS IT
// TO "undefined"
}
deleteElement(myArray, 0);
// FINALLY, CALL THE FUNCTION
]]>
</script>
</block>
<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
<meta name="maintainer" content="yourEmail@here.com"/>
<property name="maxnbest" value="5"/>
<property name="com.nuance.rec.DoNBest" value="1" />
<var name="resultLen"/>
<var name="resultArray"/>
<form id="F1">
<field name="F_1" slot="F_1">
<prompt bargein="true">
what the heck were the beach boys talking about in
that song? i bet you dont know either.
</prompt>
<grammar src="Lyrics.grammar#SONG" type="text/gsl"/>
<catch event="nomatch noinput">Sorry, I didn't get that.
<reprompt/>
</catch>
<filled>
<assign name="resultArray" expr="application.lastresult$"/>
<assign name="resultLen" expr="resultArray.length"/>
<goto nextitem="Bool_0"/>
</filled>
</field>
<block name="B_1">
<script language="Javascript">
<![CDATA[
function deleteElement(array, n) {
var length = array.length;
if (n >= length || n<0)
return;
for (var i=n; i<length-1; i++)
array[i] = array[i+1];
array.length--;
}
deleteElement(myArray, 0);
]]>
</script>
<field name="Bool_0" type="boolean">
<prompt>
</prompt>
<filled>
<if cond="(Bool_0 == false) && (resultArray.length == 1)">
<clear namelist ="Bool_0 F_1"/>
<prompt>
i am having trouble getting your response, mushmouth.
lets start over, shall we?
</prompt>
<goto next="#F1"/>
</if>
<if cond="Bool_0==true">
<prompt>
</prompt>
<else/>
<clear namelist="Bool_0"/>
<goto nextitem="B_1"/>
</if>
</filled>
</field>
</block>
</form>
<form id="F2">
<block>
<prompt>
</prompt>
<goto next="#F1"/>
</block>
</form>
</vxml>
<field> construct is meant to query the user and confirm the caller's original statement, correct? If our array length of possible matches is equal to one, and the caller replies with a negative answer, we are going to want to send the caller back to the beginning, as this will programmatically indicate that there were no other matches left.
<?xml version="1.0" encoding="UTF-8" ?>
<vxml version="2.1">
<meta name="maintainer" content="yourEmail@here.com"/>
<property name="maxnbest" value="5"/>
<property name="com.nuance.rec.DoNBest" value="1" />
<var name="resultLen"/>
<var name="resultArray"/>
<var name="myArray"/>
<form id="F1">
<field name="F_1" slot="F_1">
<prompt bargein="true">
what the heck were the beach boys talking about in
that song? i bet you dont know either.
</prompt>
<grammar src="Lyrics.grammar#SONG" type="text/gsl"/>
<catch event="nomatch noinput">Sorry, I didn't get that.
<reprompt/>
</catch>
<filled>
<assign name="resultArray" expr="application.lastresult$"/>
<assign name="resultLen" expr="resultArray.length"/>
<goto nextitem="Bool_0"/>
</filled>
</field>
<block name="B_1">
<script>
<![CDATA[
function deleteElement(array, n) {
var length = array.length;
if (n >= length || n<0)
return;
for (var i=n; i<length-1; i++)
array[i] = array[i+1];
array.length--;
}
deleteElement(resultArray, 0);
]]>
</script>
</block>
<field name="Bool_0" type="boolean">
<prompt>did you say <value expr="resultArray[0].utterance"/> ? </prompt>
<filled>
<if cond="(Bool_0 == false) && (resultArray.length == 1)">
<clear namelist ="Bool_0 F_1"/>
<prompt>
i am having trouble getting your response, mushmouth.
lets start over, shall we?
</prompt>
<goto next="#F1"/>
</if>
<if cond="Bool_0==true">
<prompt>
Excellent, Brian Wilson will be proud.
When he regains conciousness, that is.
</prompt>
<else/>
<clear namelist="Bool_0"/>
<goto nextitem="B_1"/>
</if>
</filled>
</field>
</form>
<form id="F2">
<block>
<prompt>
You are now free to turn your thoughts to less confusing
channels, such as attempting to discern the true gender
of janet reno.
</prompt>
<goto next="#F1"/>
</block>
</form>
</vxml>
| ANNOTATIONS: EXISTING POSTS |
bfoster63
|
|
| I get an "internal error" message when trying this code over the phone. | |
MattHenry
|
|
| Hi there,
Sorry about that. The problem lies with the fact that i didn't encode some operators within a conditional statement: <if cond="(Bool_0 == false) && (resultArray.length == 1)"> should be using the '&' operators instead. I'll see that this is corrected as soon as I can get to it; thanks for the heads-up. ~Matt |
|
henryanelson
|
|
| I simplified the java script.
<?xml version="1.0" encoding="UTF-8" ?> <vxml version="2.1"> <meta name="maintainer" content="YOUREMAILADDRESS@HERE.com"/> <property name="maxnbest" value="5"/> <property name="com.nuance.rec.DoNBest" value="1" /> <var name="resultLen"/> <var name="resultArray"/> <var name="currIndex"/> <form id="F1"> <field name="F_1" slot="F_1"> <prompt bargein="true"> what the heck were the beach boys talking about in that song? i bet you dont know either. </prompt> <property name="maxnbest" value="5"/> <grammar src="Lyrics.grammar#SONG" type="text/gsl"/> <catch event="nomatch noinput">Sorry, I didn't get that. <reprompt/> </catch> <filled> <assign name="resultArray" expr="application.lastresult$"/> <assign name="resultLen" expr="resultArray.length"/> <assign name="currIndex" expr="1"/> <goto nextitem="Bool_0"/> </filled> </field> <block name="B_1"> <script> <![CDATA[ currIndex++; ]]> </script> </block> <field name="Bool_0" type="boolean"> <prompt> did you say <value expr="resultArray[currIndex-1].utterance"/> ? </prompt> <filled> <if cond="(Bool_0 == false) && (currIndex >= resultArray.length)"> <clear namelist ="Bool_0 F_1"/> <prompt> i am having trouble getting your response, mushmouth. lets start over, shall we? </prompt> <goto next="#F1"/> </if> <if cond="Bool_0==true"> <prompt> Excellent, Brian Wilson will be proud. When he regains conciousness, that is. </prompt> <else/> <clear namelist="Bool_0"/> <goto nextitem="B_1"/> </if> </filled> </field> </form> <form id="F2"> <block> <prompt> You are now free to turn your thoughts to less confusing channels, such as attempting to discern the true gender of janet reno. </prompt> <goto next="#F1"/> </block> </form> </vxml> |
|
MattHenry
|
|
|
Hiya Henry, Thanks man, you saved me some work. I had been meaning to retool the clunky JS in that tutorial for quite awhile, and just never got around to it. When we retool the docs for the Prophecy platform, I'll be sure to include your Code Stylings into the next-gen tutorial. Cheers! ~Matthew Henry |
|
hertanto
|
|
| How do we get 'goose poop', 'doo scoop', 'boot scoop', 'blue sloop'?
I want to be able to say those in the end instead of just " You are now free to turn your thoughts to less confusing channels, such as attempting to discern the true gender of janet reno." |
|
voxeoJeffK
|
|
| Hi Hertanto,
I hope I'm understanding your question properly. Do you want to output the utterance that matched? For instance if the caller says 'blue sloop' and it is recognized within the active grammar then that is captured in the variable: application.lastresult$.utterance which is available to you for output. If I have misunderstood you please provide me with a few more details on what you are trying to accomplish, and I will do my best to help. Regards, Jeff Kustermann Voxeo Support |
| login |
|