Activate Method

  Microsoft Speech Technologies Homepage

Activates a grammar element or one of its rules.

listen.Activate(grammarName, ruleName)

Remarks

The Activate method must be called before speech recognition begins. If the Activate method is called after speech recognition begins, it has no immediate effect. The Activate method takes effect on the next speech recognition request.

All top-level grammar rules for the current speech recognition context that have not been explicitly deactivated are considered activated. If a specified rule does not exist, the Activate method has no effect.

Parameters

  • grammarName
    Required. Name of the grammar element to be activated. If grammarName does not exist, an onerror event occurs and the status property value of the listen element is set to -6.
  • ruleName
    Optional. Name of the top-level rule to be activated. If the ruleName is not specified, all top-level rules in grammarName are activated.

Example

The following code demonstrates activating and deactivating rules of a grammar within a listen element.

<html xmlns:salt="http://www.saltforum.org/2002/SALT">
  <body onload="p1.start()">
    <prompt id="p1" oncomplete="StartReco()" bargeIn="false">
      What time would you like to travel today?
    </prompt>
    <listen id="r1" onreco="VerifyResult()" >
      <grammar name="g1" src="./time.grxml" />
      <grammar name="g2" src="./commands.grxml" />
      <grammar name="g3" src="./servicejump.grxml" />
      <grammar name="g4" src="./correctdate.grxml" />
    </listen>
    
    <script language="JScript">
    <!--
      function StartReco() {
      // Deactivate service jumps, and activate HELP global command only
        r1.Deactivate("g3");
        r1.Deactivate("g2");
        r1.Activate("g2", "help");
        r1.Start();
      }
    -->  
    </script>
  </body>
<html>

See Also

listen Element | Deactivate Method  | onerror Event | status Property