Partilhar via


Start Method

  Microsoft Speech Technologies Homepage

Starts the recognition process.

listen.Start();

Remarks

The Start method uses as active grammars all the top-level rules for the recognition context that have not been explicitly deactivated. The Start method initiates one of the following four recognition events:

Event Reason for Occurrence
onreco Occurs when speech is recognized.
onnoreco Occurs when speech is not recognized.
onsilence Occurs when only silence is detected after a period of time established using the initialtimeout attribute.
onspeechdetected Occurs when speech is detected.
onerror Occurs when any error occurs. The status property provides a status code that indicates the cause of the error.

A call to the Start method is ignored if the same listen element is already started and in the active state. A Start call to another listen element raises an error and sets the status value to -9.

Example

The following code demonstrates the use of the Start method.

<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

listen Element |  onerror Event | onnoreco Event | onreco Event | onsilence Event