Beep Detector

Beep Detection allows you to detect beeps from answering machines. You can use the beep detector for more accurate call progress, or to make sure that the entirety of your message gets played back to your users.

Traditional Call Progress detection is limited, because it relies on the first couple of seconds of audio to determine if what picked up the phone was a human or an answering machine. The Beep Detector analyzes much longer amounts of audio listening for a beep. If a beep is “heard” you can be certain that it was a machine. Alternatively, you can be relatively certain that if no beep was detected that it was a human that answered the call. In our testing, we found that the Beep Detector was 98.5% accurate in detecting beeps. By comparison, the most finely tuned Call Progress engines reach only about 90% accuracy.

The Problem with Traditional Call Progress

Often, people will pick up the car while driving, and the system will hear the background noise and think that it was a machine that picked up. Or perhaps, someone will pick up the phone and say “Thank you for calling Inventive Labs, this is Matt, how may I help you?” — and because the introduction is so long, the call progress engine will determine that it was a machine that picked up the phone.

Also , it’s often difficult to determine when it’s appropriate to begin playing the message to a machine. Often, you will run into situations where the first half of the message is cut off, because of differences between Voice Mail systems. Our Beep Detector resolves this by allowing you to restart your message as soon as you hear a beep — effectively allowing you to get the entirety of your message on a voicemail system on a consistent basis.

How and Why Beep Detection Works

Once you start the Beep Detector in Voice Elements, it will analyze all of the audio listening for anything that might be considered a beep. When a beep is detected Voice Elements will return a Termination Code of Beep back to the client application, and you can then determine how to handle the situation.

What this means is that when you make calls you can begin playing a message as though a human picked up the phone, then once you hear a beep you can begin playing the machine message. This means that people that pick up the phone will always hear the message that is meant for them, and machines, will always hear the entirety of the message that was meant for them.

Using the Beep Detector

Below is some sample code that shows how to use the Beep Detector:

    public class BeepDetector
    {
        public ChannelResource ChannelResource
        {
            get;
            set;
        }
 
        public VoiceResource VoiceResource
        {
            get;
            set;
        }
 
        public TelephonyServer TelephonyServer
        {
            get;
            set;
        }
 
        public Log Log
        {
            get;
            set;
        }
 
        public string DeviceName
        {
            get;
            set;
        }
 
        public string PhoneNumber
        {
            get;
            set;
        }
 
        public BeepDetector(TelephonyServer telephonyServer, Log log)
        {
            TelephonyServer = telephonyServer;
            Log = log;
        }
 
        public bool IsBeepDetected
        {
            get;
            set;
        }
 
        public void RunScript()
        {
            try
            {
                TerminationCode tc = TerminationCode.Normal;
                try
                {
                    ChannelResource = TelephonyServer.GetChannel();
                    VoiceResource = ChannelResource.VoiceResource;
                    DeviceName = ChannelResource.DeviceName;
                }
                catch (Exception ex)
                {
                    Log.WriteException(ex, "Could not get a channel resource!");
                    return;
                }
 
                // We will set the CallProgress mode to WaitForConnect
                // This means that we will return as soon as we get a connect message back from the carrier
                ChannelResource.CallProgress = CallProgress.WaitForConnect;
 
                // Place the call
                DialResult dr = ChannelResource.Dial(PhoneNumber);
                Log.WriteWithId(DeviceName, "Returned from Dial: {0}", dr);
 
                // Now we begin our Beep Detector. Once started, it's possible for us to receive Termination Codes of Beep
                VoiceResource.BeepDetectionStart();
 
                // Now we play a message to a human
                tc = VoiceResource.PlayTTS("Hello Human! Please press any digit if you would like to speak to a live operator");
 
                // Check to see if we detected a beep
                if (tc == TerminationCode.Beep)
                {
                    IsBeepDetected = true;
                    // Stop the Beep Detector. Make sure you do so before doing your next play!
                    VoiceResource.BeepDetectionStop(); 
                    VoiceResource.PlayTTS("Hello Machine! This is a message meant for you");
 
                    // Return from this message -- we don't need to get digits if we know that it's a machine.
                    return;
                }
 
                // The beep detector also works when detecting digits
                tc = VoiceResource.GetDigits(1, 15, "@");
 
                Log.WriteWithId(DeviceName, "TerminationCode was: {0}", tc);
 
                if (tc == TerminationCode.Beep)
                {
                    IsBeepDetected = true;
                    // Stop the Beep Detector. Make sure you do so before doing your next play!
                    VoiceResource.BeepDetectionStop(); 
                    VoiceResource.PlayTTS("Hello Machine! This is a message meant for you");
 
                }
                else if (tc == TerminationCode.MaximumDTMF || tc == TerminationCode.Digit)
                {
                    // The person entered a digit...Transfer to an operator
                }
                else
                {
                    // The person did not enter a digit.
                }
            }
            catch (HangupException hex)
            {
                Log.WriteWithId(DeviceName, "Caller Hungup!");
            }
            catch (Exception ex)
            {
                Log.WriteException(ex, "Unexpected exception: {0}", DeviceName);
            }
            finally
            {
                if (!IsBeepDetected)
                {
                    // Make sure you always stop the Beep Detector
                    VoiceResource.BeepDetectionStop();
                }
                try
                {
                    ChannelResource.Disconnect();
                }
                catch { }
 
                try
                {
                    ChannelResource.Dispose();
                }
                catch { }
            }
        }
    }

Key Notes

The Beep Detector must be active for a termination code of Beep to be met. This means that you must always call BeepDetectionStart, before you do anything where you may want to detect a beep.

Make sure that that you always Stop the beep detector before doing a subsequent play. Otherwise, the next play will end immediately with a return code of beep. This allows you your code to fall through multiple plays (i.e. you play message 1, 2, and 3 in quick succession).

Using the Beep Detector with Short Messages

One potential issue with the beep detector is that if you play short messages, you may never hear a beep. To remedy this situation, we recommend the following:

1) Determine how long you should typically wait (between 30 and 45 seconds is typically long enough). Perhaps, you should make this a configuration setting.

2) Get the time when your call first connects.
3) Get the time when your message is finished playing.
4) If it’s been more time than you defined in item 1, then determine how many more seconds you need to wait by subtracting the duration of the call from the desired wait time for the beep.
5) Wait for digits:

VoiceResource.GetDigits(1, secondsToWait, "");

As long as the beep detector is still on, the GetDigits will return with a return code of BeepDetected.

Using the method above, you would ensure that you wait the necessary time for the message to return.

Next Steps

As you can see, it’s a straightforward process to take advantage of the Beep Detector in existing code. Implementing the Beep Detector is a powerful way to improve the accuracy of your call results. If you have any questions about using the Beep Detector, reel free to e-mail support@inventivelabs.com.