Recognition Mode: Automatic Example
The following example demonstrates Automatic recognition mode. Click the Start button and say any one of the cities listed. The recognition result status is listed in the first text box, named Reco Status. The actual results of the recognition display in the second text box, named Reco Text. The Semantic Markup Language (SML) recognition result displays in the large text box.
The following example uses the automatic mode, which is the default mode. Because automatic mode is used, there is no need to explicitly call the Stop method to end the recognition process. In automatic mode, the end of speech is detected and recognition is stopped as needed. If any errors are reported, the Reco Status textbox displays a value that indicates the type of error that occurred.
This example uses an inline grammar to define the city names however, an external XML grammar file could also have been specified.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<head>
<title>listen Test</title>
<object id="Speechtags" CLASSID="clsid:DCF68E5B-84A1-4047-98A4-0A72276D19CC" VIEWASTEXT></object>
</head>
<body>
<!-- declare the object on the page-->
<?import namespace="salt" implementation="#Speechtags" />
<salt:listen id="listen1" mode="automatic" babbletimeout="5000" endsilence="500" onreco="Handleonreco()"
onnoreco="Handleonnoreco()" onsilence="Handleonsilence()" onerror="Handleonerror()">
<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="BtnDe" value="Start" OnClick="Start()" id="Button"/>
<br><br>
This example uses an automatic mode listen.<br>
Click Start to begin; after speaking, the application will automatically stop.<br>
Valid city names for recognition: Seattle, Boston, Dallas, and Houston.
<br><br>
Recognition Status:
<input type="text" size="25" name="boxStatus" value="(recognition status goes here)" id="boxStatus"/>
<br><br>
Recognition Text:
<input type="text" size="25" name="boxReco" value="(recognition text goes here)" id="boxReco"/>
<br><br>
Semantic Markup Language (SML) Result:<br>
<TEXTAREA cols="60" rows="10" ID=txtComments>(Semantic Markup Language (SML) results are displayed here)
</TEXTAREA>
<script>
<!--
function Start() {
boxStatus.value = "";
boxReco.value = "";
txtComments.value = "";
listen1.Start();
}
function Handleonreco(){
boxStatus.value = listen1.status;
boxReco.value = event.srcElement.text;
txtComments.value = event.srcElement.recoresult.xml
}
function Handleonnoreco(){
boxStatus.value = "onnoreco fired " + listen1.status;
boxReco.value = ""
}
function Handleonsilence(){
boxStatus.value = "onsilence fired " + listen1.status;
boxReco.value = ""
}
function Handleonerror(){
boxStatus.value = "onerror fired " + listen1.status;
boxReco.value = "";
}
-->
</script>
</body>
</html>
See Also
listen Element | Recognition Mode: Single Example | Recognition Mode: Multiple Example