Condividi tramite


onerror Event

  Microsoft Speech Technologies Homepage

Occurs when the speech recognition platform is unable to process a recognition or recording request and specifies a function to handle the error.

HTML <listen onerror="errorHandler()">
Scripting listen.onerror = errorHandler;
Named Script <SCRIPT FOR = listen EVENT = onerror>

Remarks

Error handling for recognition or recording occurs once the Start method begins. The specific error being returned is determined using the status property. When an onerror event occurs, recognition or recording is automatically stopped.

Although the event handler does not receive properties directly, the handler can query the event object for error codes.

The following is a list of the error codes returned when a fatal error occurs during recognition or recording:

Scenario Value Description
Possible error codes while recognizing  -1 A generic Speech Platform error has occurred.
 -2 No Speech Platform has been found (for distributed architectures).
 -3 An inappropriate property/attribute setting that causes a problem with the recognition request.
 -4 Failed to find a resource—in the case of recognition, this is a grammar resource.
 -5 Failed to load or compile a grammar resource.
 -6 Failed to activate or deactivate rules or grammars.
 -7 The time period specified by the maxtimeout attribute elapsed before recognition was completed.
 -8 There are no active grammars when recognition begins.
 -9 Recognition was attempted while another recognition was in progress.
Possible error codes while recording -20 Failed to record on the local platform.
-21 Unsupported CODEC. (If neither format nor CODEC are unsupported, only one of the values needs to be set.)
-22 Unsupported format
-23 Error occurred during streaming to a remote server.
-24 An invalid property/attribute setting that caused a problem with the recording request.
-30 Recording was attempted after a disconnect (telephony profiles).

Example

The following code demonstrates the use of the onerror event. The example is similar to the onreco event sample. However, this example replaces the inline grammar with a reference to a non-existent grammar file, in this case named "numbers.grxml." The sample produces an error at the first statement. The error is -8 because the grammar file is not found, there are no active rules.

<html xmlns:salt="http://www.saltforum.org/2002/SALT">
  <head>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
    <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()" onerror="HandleError()">
      <grammar src="./numbers.grxml">
    </salt:listen>

    <form>
      <input type="button" value="Start a single recognition" name="StartRecognitionButton"
      onClick="StartRecognition()">
    </form>

    The sample attempts to open a non-existent grammar file, thus forcing an error.

    <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 HandleError() {
        var Status;
        try {
          Status = event.srcElement.status;
          StatusForm.StatusTextbox.value = "Error detected, status: " + Status;
        } catch(e) {
          alert("No recognition");
        }
      }
    -->
    </script>
  </body>
</html>

See Also

listen Element |  record Element