Partilhar via


onspeechdetected Event

  Microsoft Speech Technologies Homepage

Occurs when the recognition engine detects speech.

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

Remarks

The Speech Platform determines the actual time the onspeechdetected event is initiated. The time can be configured on certain platforms using the param element. This event may occur anywhere between simple energy detection (early) or complete phrase or semantic value recognition (late).

The onspeechdetected event also initiates an onbargein event if a prompt is used in playback. Whenever an onspeechdetected event is raised, it also disables the initial time-out of any DTMF recognition that has started. This handler can be used in multimodal scenarios. For example, it can be used to generate a graphical indication that recognition is occurring. It can also be used in voice-only scenarios to enable fine control over other processes occurring during recognition.

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.

The onspeechdetected event does not support event-bubbling or propagation.

Example

The following code demonstrates the use of the onspeechdetected 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. The button can be clicked and released or held down continuously. Speak a number from one to three, inclusive. A successful recognition displays the number spoken in one text box and confirmation of the recognition event in the other. 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

listen Element |  onbargein Event | recoresult Property | status Property | text Property