Share via


Create the Detection Grammar

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The essential component of an application that can distinguish a human answering a call and a machine answering a call is the DetectAnsweringMachineActivity class. This activity uses an algorithm that makes a decision based on the length of the response (humans tend to have shorter responses and answering machines tend to have longer responses) and the response itself. For more information about the algorithm, see Detect Answering Machines. When the called number response time is longer than that of a typical human, but shorter than that of a typical answering machine, DetectAnsweringMachineActivity attempts to match the response from the called number to a phrase in a developer-supplied detection grammar.

The grammar in the following code sample contains two blocks of phrases. The first block consists of phrases uttered by people and the second block consists of phrases recorded from a number of answering machines. If the response from a called number matches any of the phrases in the first block, the grammar rule returns a Rule Variable property named DetectedEntity whose semantic value is LIVE_PERSON_RESPONSE. Similarly, if the response from a called number matches any of the phrases in the second block, the grammar rule returns the DetectedEntity Rule Variable property with a semantic value of ANSWERING_MACHINE_RESPONSE.

Important

Any detection grammar must return a Rule Variable property named DetectedEntity that must be set to a semantic value of either LIVE_PERSON_RESPONSE or ANSWERING_MACHINE_RESPONSE. LIVE_PERSON_RESPONSE corresponds to a match with a phrase assumed to be spoken by a human; ANSWERING_MACHINE_RESPONSE corresponds to a match with a phrase assumed to come from an answering machine.

The following grammar should be considered a starting point. Undoubtedly, you will find human and answering machine responses that are not included in this grammar. You can improve detection accuracy by including any such responses.

<?xml version="1.0"?>
<!--  Responses.grxml -->
<grammar xml:lang="en-US" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics-ms/1.0">
<rule id="Rule1" scope="public">
  <one-of>
    <item>
      <one-of>
        <item>Hello</item>
        <item>
           <item>This is</item>
           <ruleref special="GARBAGE"/>
           <item>speaking</item>
        </item>
        <item>Speaking</item>
        <item>Okay</item>
        <item>May I help you</item>
        <item>Who is it</item>
        <item>Hello may I ask who is calling</item>
        <item>Hey what's up man</item>
        <item>May I help you</item>
        <item>Good morning</item>
        <item>Good afternoon</item>
        <item>Good evening</item>
      </one-of>
      <tag>$.DetectedEntity = "LIVE_PERSON_RESPONSE"</tag>
    </item>
    <item>
      <one-of>
        <item>We are sorry we can't come to the phone</item>
        <item>
           <item>You have reached the home of</item>
           <ruleref special="GARBAGE"/>
        </item>
        <item>Please leave your name and phone number</item>
        <item>
           <item>Hi this is</item>
           <ruleref special="GARBAGE"/>
        </item>
        <item>We'll get back to you as soon as possible</item>
        <item>Thank you for calling</item>
        <item>
           <item>Please leave a voice message for</item>
           <ruleref special="GARBAGE"/>
        </item>
        <item>When you are finished recording hang up or press pound for more options</item>
        <item>After the tone please record your message</item>
        <item>Please leave your name and number and a brief message after the beep</item>
        <item>Leave your name and number</item>
        <item>I'll get back to you when I can</item>
        <item>We'll get back to you</item>
        <item>
           <item>Hi you have reached</item>
           <ruleref special="GARBAGE"/>
           <item>I'm not here right now but if you leave a message I'll get back to you right away</item>
        </item>
        <item>I'll get back to you</item>
        <item>I'm not here right now</item>
        <item>
           <item>You have reached the voice mail box of</item>
           <ruleref special="GARBAGE"/>
        </item>
        <item>We're not here right now</item>
        <item>Please leave a message</item>
        <item>Hello we're not at home right now</item>
        <item>Hello I'm not at home right now</item>
      </one-of>
      <tag>$.DetectedEntity = "ANSWERING_MACHINE_RESPONSE"</tag>
    </item>
  </one-of>
</rule>
</grammar>

Next Step

Create the Detection Application