onsilence Event
Occurs when no speech is detected by the recognition platform before the time period specified by the initialtimeout attribute has expired.
HTML | <listen onsilence="onSilenceHandler()"> |
Scripting | listen.onsilence = onSilenceHandler; |
Named Script | <SCRIPT FOR = listen EVENT = onsilence> |
Remarks
For recognition in the automatic recognition mode, the onsilence event cancels the recognition process. In addition, the onsilence event does not support event-bubbling or event propagation.
Although the event handler does not receive properties directly, it can query the listen element for status and results information. Status information is contained in the status property while the text property and the recoresult property contain results information.
Example
The following code demonstrates the use of the onsilence event. This code displays a page containing a single button named "Start a single recognition" and two text boxes. Click the button to start the recognition. Speak a number from one to five, inclusive. A successful recognition displays the number spoken in one text box and confirmation of the recognition event in the other. If only silence is detected, status code -11 is displayed in the status textbox. Errors are not handled.
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<head>
<title>My Test Page</title>
<object id="Speechtags" CLASSID="clsid:DCF68E5B-84A1-4047-98A4-0A72276D19CC" VIEWASTEXT></object>
</head>
<body>
<!--Importing the namespace from the implementation -->
<?import namespace="salt" implementation="#Speechtags" />
<!--SALT speech recognition object -->
<salt:listen id="TestReco" onreco="Handleonreco()" onnoreco="Handleonnoreco()"
onspeechdetected="Handleonspeechdetected()" onsilence="Handleonsilence()">
<salt:grammar name="numbers">
<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="#numbers" />
</rule>
<rule id="numbers">
<one-of>
<item>one</item>
<item>two</item>
<item>three</item>
<item>four</item>
<item>five</item>
</one-of>
</rule>
</grammar>
</salt:grammar>
</salt:listen>
<form>
<input type="button" value="Start a single recognition" name="StartRecognitionButton"
onClick="StartRecognition()">
</form>
Say a number from one through five, inclusive.
<form id="StatusForm">
Status: <input size="55" name="StatusTextbox">
</form>
<form id="ResultForm">
Result: <input size="55" name="ResultTextbox">
</form>
<script id="script1" language="jscript">
<!--
function StartRecognition() {
try {
StatusForm.StatusTextbox.value = "Listening...";
ResultForm.ResultTextbox.value = "";
TestReco.Start();
} catch(e) {
alert("Recognition error");
}
}
function Handleonreco() {
try {
StatusForm.StatusTextbox.value = "Received recognition result";
ResultForm.ResultTextbox.value = event.srcElement.text;
} catch(e) {
alert("Recognition error");
}
}
function Handleonnoreco() {
var Status;
try {
Status = event.srcElement.status;
StatusForm.StatusTextbox.value = "No recognition, status: " + Status;
} catch(e) {
alert("No recognition");
}
}
function Handleonspeechdetected() {
var Status;
try {
Status = event.srcElement.status;
StatusForm.StatusTextbox.value = "Speech detected";
} catch(e) {
alert("No recognition");
}
}
function Handleonsilence() {
var Status;
try {
Status = event.srcElement.status;
StatusForm.StatusTextbox.value = "Silence detected, status: " + Status;
} catch(e) {
alert("No recognition");
}
}
-->
</script>
</body>
</html>
See Also
initialtimeout Attribute | listen Element | onnoreco Event Property | onreco Event | recoresult Property | status Property | text Property