listen Example
The following is an example of a listen element for a browser that supports scripting. This page has two elements: a Start Listening button and a text box for printing the status. Click Start Listening to begin the recognition process. Speak the name of one of the recognized cities for a successful recognition. The cities are Boston, Houston, New York, and Seattle.
In the case of a successful recognition, the status text box briefly displays a message in response to an onreco event. The Semantic Markup Language (SML) result from the recognition engine appears in the text box, confirming the recognized text. If an unsuccessful recognition occurred, a message is displayed in response to an onnoreco event.
The example uses an inline grammar rather than an external grammar file.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<head>
<object id="Speechtags" CLASSID="clsid:DCF68E5B-84A1-4047-98A4-0A72276D19CC" VIEWASTEXT></object>
</head>
<body>
<?import namespace="salt" implementation="#Speechtags" />
<salt:listen id="listen1" onreco="Handleonreco()" onnoreco="Handleonnoreco()">
<salt:grammar name="cities">
<grammar version="1.0" tag-format="semantics-ms/1.0" lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar" root="root">
<rule id="root">
<item repeat="0-1">from </item>
<ruleref uri="#cities" />
</rule>
<rule id="cities">
<one-of>
<item>Seattle</item>
<item>Boston</item>
<item>Houston</item>
<item>New York</item>
</one-of>
</rule>
</grammar>
</salt:grammar>
</salt:listen>
<input type="button" name="BtnListen" value="Start Listening" OnClick="StartListening()" id="Button2">
<br><br>
This is an example of an automatic mode listen.<br>
Click Start to begin; after speaking, the application will automatically stop.<br>
Valid city names for recognition are Seattle, Boston, Houston, and New York.
<br><br>
<input type="text" name="TxtStatus" size = "80" value="Listening for test" id="RecoTxt">
<script language="JScript">
<!--
function StartListening() {
RecoTxt.value = "Starting to listen...";
listen1.Start();
RecoTxt.value = "Listening...";
}
function Handleonreco() {
RecoTxt.value = "Received onreco.";
smlResult = event.srcElement.recoresult;
RecoTxt.value = smlResult.xml;
}
function Handleonnoreco() {
RecoTxt.value = "Received onnoreco";
}
-->
</script>
</body>
</html>