Share via


Recognition Mode: Multiple Example

  Microsoft Speech Technologies Homepage

The following code demonstrates multiple mode. After starting a recognition, the recognizer remains active until a time-out occurs or it is explicitly stopped. Click and release the Start button. Say the name of one or more of the sample cities listed. The first text box displays that action that is currently occurring. The recognition result status is listed in the second text box, labeled Recognition Status. The results of the recognition display in the third text box, labeled Recognition Text. The Semantic Markup Language (SML) recognition result displays in the large text box. When an unsuccessful recognition occurs, either because the word is not in the grammar, or that the quality of the recognition was too low, the Recognition Status text box displays an appropriate message along with a status value.

To stop the recognizer, click Stop. Alternatively, do not say anything for the interval specified by the babbletimeout attribute.

The sample also uses an external XML grammar to define the city names. Alternatively, an inline grammar file could have been specified.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
  <head>
    <object id="Speechtags" CLASSID="clsid:DCF68E5B-84A1-4047-98A4-0A72276D19CC" VIEWASTEXT></object>
  </head>
    
  <body>
    <?import namespace="salt" implementation="#Speechtags" />
    <salt:listen id="listen1" mode="multiple" reject=".65" babbletimeout="5000" 
    onreco="Handleonreco()" onnoreco="Handleonnoreco()">
      <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="cities">
          <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="BtnListen" value="Start Listening" OnClick="StartListening()" id="StartListen"/>
     <input type="button" name="BtnStop" value="Stop" OnClick="StopListening()" id="StopListen"/>
    
     <br><br>
       This is an example of an multiple mode listen.<br>
       Click Start to begin; after speaking the name of one of the valid cities, click Stop to stop listening or wait 
       until the timeout occurs.<br>
       Valid city names for recognition are Seattle, Boston, Houston, and New York.<br><br>

    Speech Action:<br>      
    <input type="text" name="Action" size = "80" value="Listening for test" id="Action"/><br><br>
      
    Recognition Status:<br> 
    <input type="text" size="80" name="RecoStatus" value="(recognition status goes here)" id="RecoStatus"/>
    
    <br><br>
    Recognition Text:<br> 
    <input type="text" size="80" name="RecoText" value="(recognition text goes here)" id="RecoText"/>
        
    <br><br>
    Semantic Markup Language (SML) Result:<br>
    <TEXTAREA cols="80" rows="10" ID=TextComments>(Semantic Markup Language (SML) results are displayed here)
    </TEXTAREA><br><br>

    
    <script language="JScript">
    <!-- 
      var recoFlag = 0;
      function StartListening() {
        Action.value  = "Starting to listen...";
        recoFlag = 0;
        RecoStatus.value = "";
        RecoText.value="";
        TextComments.value="";
        listen1.Start();
        Action.value  = "Listening...";
      }
      
      function StopListening() {
        Action.value = "Stopped listening";
        listen1.Stop();
      }
      
      function Handleonreco() {
        Action.value = "Received onreco.";
        recoFlag = 1;
        smlResult = event.srcElement.recoresult;
        RecoStatus.value = listen1.status;        
        RecoText.value = smlResult.text;
        TextComments.value= smlResult.xml
      }
      
      function Handleonnoreco() {
          Action.value = "Received onnoreco";
          RecoStatus.value = listen1.status;
          TextComments.value = "";          
          if (recoFlag == 1) {
            RecoText.value = "No further speech was recognized.";
          }
          else 
            RecoText.value = "No speech was recognized.";
      }
    -->
    </script>
  </body>

See Also

listen Element | Recognition Mode: Automatic Example | Recognition Mode: Single Example