|
Author
|
Topic: Memory Game/JS Array Help
|
Paul Stamatiou
Junior Member
Member # 3383
|
posted February 14, 2006 07:39 PM
I am trying to make a memory game for one of my courses using VoiceXML. Basically the user will be read three numbers and have to repeat them back and if correct, the next round there will be four numbers and so on.
My problem is getting VoiceXML to identify the numbers the user said and comparing them to an array with the correct sequence of numbers. It doesn't have to use an array, that's just what I started out with. Any help would be greatly appreciated. Below is most of the code I have
code:
<var name="roundone" expr="new Array('one', 'seven', 'three')"/> <block> <audio src="http://cafe.bevocal.com/libraries/audio/female1/en_us/number/1.wav"/> <audio src="http://cafe.bevocal.com/libraries/audio/female1/en_us/number/7.wav"/> <audio src="http://cafe.bevocal.com/libraries/audio/female1/en_us/number/3.wav"/> </block>
<field name="round1" type="number"> <prompt> Please repeat the number sequence. </prompt> <grammar type="application/x-nuance-gsl"> [one seven three] </grammar>
<filled> <if cond="round1==roundone[0]+roundone[1]+roundone[2]"> <prompt> Awesome. You may proceed to the next round. </prompt> </if> <if cond="round1!==roundone[0]+roundone[1]+roundone[2]"> <prompt> Sorry, you lose. Clear your mind and try again. </prompt> </if><clear namelist="round1"/> </filled>
Thanks, Paul
Posts: 1 | Registered: Feb 2006
| IP: Logged
|
|
mheadd
Member
Member # 3181
Member Rated:
|
posted February 15, 2006 02:28 PM
I think using a JavaScript array makes sense. Here are some suggestions:
The field should use a builtin grammar � you currently have the field "type" attribute set to numbers. I would use the "digits" builtin type � this will allow you to recognize any numeric input from 0-9.
You don't need the second grammar for the field -- there is a property that dictates the amount of silence after spoken input that the interpreter waits to finalize input. This property � completetimeout � has a default setting that is usually around 3 to 5 seconds depending on the platform. You probably don�t need to change this. So, when a user is prompted at your field, they can say any number of digits (depending on where they are in the game) and then stop � the platform will wait for the number of seconds specified by the completetimeout property and then finalize the input.
To check the input, you should compare the value of the field to the numbers you have in your array. You do this (as you have in your example) by using an <if><else/> statement within the <filled> element.
If you want to get the values in your array as one string of numbers, you can use the join method of the JavaScript Array object:
code:
var numGame = new Array(); numGame[0] = 2; numGame[1] = 3; numGame[2] = 4; // assigns "234" to theAnswer var theAnswer = numGame.join(""); ...
<filled> <if cond="round1==theAnswer"> <prompt>Awesome. You may proceed to the next round.</prompt> <else/> <prompt> Sorry, you lose. Clear your mind and try again. .</prompt> </if> </filled>
Also, you can add elements to your array (as the player progresses through the game) using the push method of the JavaScript Array object:
code:
Round2 = numGame.push(�6�);
There is a very good JavaScript reference here.
Hope this helps.
-------------------- Mark VoiceinGov.org http://www.voiceingov.org
Posts: 55 | Registered: Jun 2005
| IP: Logged
|
|
|