The following is a selection of sample code from the
SALT 1.0 specification.
- Click to talk
- Prompt playback across pages
- Simple mixed initiative dialog
- Audio recording
This simple example shows how, in a multimodal application, GUI events can be wired to SALT commands such as beginning a recognition turn. In this example, pressing the button named buttonCityListen starts the listen named listenCity, which holds a grammar of city names, and a bind command to transfer the value into the input control named txtBoxCity.
<!-- HTML -->
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<form id="travelForm">
<input name="txtBoxCity" type="text" />
<input name="buttonCityListen" type="button" onClick="listenCity.Start();" />
</form>
<!-- SALT -->
<salt:listen id="listenCity">
<salt:grammar name="g_city" src="./city.grxml" />
<salt:bind targetelement="txtBoxCity" value="//city[1]" />
</salt:listen>
</html>
This example shows how the PromptQueue is used to ensure seamless prompt playback across page transitions in an HTML profile:
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<body>
<form id="form1" action="nextpage.html">
<input type="button" onclick="transition();" value="next page" />
</form>
<salt:prompt id="transitionPrompt">
Let's go to the next page!
</salt:prompt>
<script>
function transition() {
transitionPrompt.Queue();
PromptQueue.Start();
form1.submit();
}
</script>
</body>
</html>
A simple system-initiative dialog might be authored in the following way, for example, where the RunAsk() function activates prompts and recognitions until the values of the input fields are filled:
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<body onload="RunAsk()">
<form id="travelForm">
<input name="txtBoxOriginCity" type="text" />
<input name="txtBoxDestCity" type="text" />
</form>
<!-- Speech Application Language Tags -->
<salt:prompt id="askOriginCity"> Where would you like to leave from? </salt:prompt>
<salt:prompt id="askDestCity"> Where would you like to go to? </salt:prompt>
<salt:listen id="recoOriginCity" onreco="procOriginCity()">
<salt:grammar src="city.xml" />
</salt:listen>
<salt:listen id="recoDestCity" onreco="procDestCity()">
<salt:grammar src="city.xml" />
</salt:listen>
<!—- scripted dialog flow -->
<script>
function RunAsk() {
if (travelForm.txtBoxOriginCity.value=="") {
askOriginCity.Start();
recoOriginCity.Start();
} else if (travelForm.txtBoxDestCity.value=="") {
askDestCity.Start();
recoDestCity.Start();
}
}
function procOriginCity() {
travelForm.txtBoxOriginCity.value = recoOriginCity.text;
RunAsk();
}
function procDestCity() {
travelForm.txtBoxDestCity.value = recoDestCity.text;
travelForm.submit();
}
</script>
</body>
</html>
The following example demonstrates recording audio for a voice mail system.
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<!-- on page load, run script -->
<body xmlns:salt="http://www.saltforum.org/2002/SALT" onload="RunAsk()">
<form id="f1" action="http://www.example.com/savewaveform.aspx" method="get">
<input name="vmail" type="hidden" />
</form>
<!-- Prompts -->
<salt:prompt id="p_record" oncomplete="l_recordvm.Start()">
Please speak after the tone. You may press any key to end your recording.
</salt:prompt>
<salt:prompt id="p_save">
Do you want to save this voicemail?
</salt:prompt>
<!-- listens -->
<!-- Recording session - max 60 seconds recording -->
<salt:listen id="l_recordvm" initialtimeout="3000"
endsilence="1500" babbletimeout="60000"
onreco="saveAudio()" onnoreco="saveAudio()" onsilence="RunAsk()" >
<salt:record />
</salt:listen>
<!-- listen for capturing whether user wants to save voice mail -->
<salt:listen id="l_save" onreco="processSave()">
<salt:grammar src="./yesno.grxml" />
</salt:listen>
<salt:dtmf id="d_stop_rec" onreco="saveAudio()">
<grammar src="alldigits.grxml" />
</salt:dtmf>
<!-- HTML script controlling dialog flow -->
<script>
function RunAsk() {
if (voicemail.value=="") {
p_record.Start();
}
}
// Ask user if they are satisfied with their recording
function saveAudio () {
p_save.Start();
l_save.Start();
}
// If user is satisfied post file name back to web server
// otherwise start again
function processSave () {
smlResult = event.srcElement.recoresult;
origNode = smlResult.selectSingleNode("//answer/text()");
if (origNode.value == "Yes") {
vmail.value = l_recordvm.recordlocation;
f1.submit();
} else {
RunAsk();
}
}
</script>
</body>
</html>
|