Cancel Method
Stops the recognition process without returning a result.
listen.Cancel();
Remarks
The Cancel method also deactivates the grammar and releases the speech recognizer. It does not return any recognition results available up to the cancellation point. As a result of discarding the recognition results, events such as onreco and onnoreco do not occur. In contrast, the Stop method returns any available recognition results and initiates events notifying the application of the status of the recognition process.
The browser disregards recognition results for canceled recognition. If the speech recognizer has not been started, the call to the Cancel method has no effect.
Example
The following code demonstrates the use of the Cancel method.
<!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="StartListen">
<input type="button" name="BtnCancel" value="Cancel" OnClick="CancelListen()" id="CancelListen"
<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 CancelListen() {
RecoTxt.value = "Canceled listen";
listen1.Cancel();
}
function Handleonreco() {
RecoTxt.value = "Received onreco.";
smlResult = event.srcElement.recoresult;
RecoTxt.value = smlResult.xml;
}
function Handleonnoreco() {
RecoTxt.value = "Received onnoreco";
}
-->
</script>
</body>
</html>
See Also
listen Element | grammar Element | onnoreco Event | onreco Event | Stop Method