Mod avmd

From FreeSWITCH Wiki
Jump to: navigation, search


Superseded by




AVMD stands for "Advanced Voice Mail Detection" and mod_avmd is designed to detect the beep sound at the end of voicemail or answering machine greetings. This is useful in cases where you wish to leave a recorded message on the recipient's message system but don't want to have the pregnant pause that is common when using wait_for_silence.

mod_avmd (AVMD) is the second generation Voice Mail Detection, and has a number of enhancements that make it much better at determining a beep. It is intended to replace mod_vmd. It works very similar to mod_vmd with a few exceptions.

  • VMD will listen for and send an event each time it thinks there is a beep. Therefore VMD may send many events while listening to a call.
    • AVMD only sends one event, and then quits. However AVMD is much better at determining correct beep sounds, which means it gives back fewer false positives and more true positives than VMD.
  • VDM events included frequency and duration details for the beep.
    • AVMD does not. [Eric said this about not including frequency and duration in the events, “It saves resources (cpu & memory) and we didn’t need the values.”]


AVMD (and VMD) are both very CPU intensive. You need to be aware of this fact when using it. It will drastically reduce your call capacity if you do not manage it correctly. On the other hand it is a very useful tool, and if managed properly will be a great aid for calls needing to do Voice Mail Detection.

  • Eric states, "You can expect about ~50 simultaneous instances on an Intel i7 920 CPU."


For best results in getting accurate detection as well a saving system resources (CPU & memory), you should do the following:

  • Wait until AFTER the call has been answered before starting AVMD. In many cases you may find it best to wait a few seconds after the call is answered before starting AVMD.
    • Starting AVMD before the call is answered will often result in false beeps and wastes CPU resources.
  • Once you have received the AVMD event, you should explicitly stop AVMD, even though it will not return another event.

From mod_event_socket

To start the mod:

api avmd <uuid> start

To stop the mod:

api avmd <uuid> stop

To get mod_avmd events:

event plain CUSTOM avmd::beep

A useful way to start avmd a few seconds after answer. Once you get an answer event, issue this command

api sched_api +3 none avmd <uuid> start

Example Event

Event-Subclass: avmd%3A%3Abeep
Event-Name: CUSTOM
Core-UUID: 3395d705-6571-414d-a38c-fad8b0bdd3e9
FreeSWITCH-Hostname: tpa-es-cos-232
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2010-07-02%2009%3A58%3A01
Event-Date-GMT: Fri,%2002%20Jul%202010%2013%3A58%3A01%20GMT
Event-Date-Timestamp: 1278079081446061
Event-Calling-File: mod_avmd.c
Event-Calling-Function: avmd_process
Event-Calling-Line-Number: 548
Beep-Status: stop
Unique-ID: d6ff2323-d57e-4e7d-b75b-7724d81bb5d9
call-command: avmd

Lua Example

This is an example of a callback in Lua:

local human_detected = false;
local voicemail_detected = false;

function onInput(session, type, obj)
    if type == "dtmf" and obj['digit'] == '1' and human_detected == false then
        human_detected = true;
        return "break";

    if type == "event" and voicemail_detected == false then
        voicemail_detected = true;
        return "break";


Javascript Example

This is an example of a callback in Javascript:

function onInput(s, type, obj, arg)
		if(type == "dtmf")
			console_log("info", "DTMF digit: "" ["+obj.digit+"] len ["+obj.duration+"]\n");
		else if(type == "event" && session.getVariable("avmd_detect") == "TRUE")
			console_log("info", "Voicemail Detected\n");
		console_log("err", e + "\n");
	return true;

session.execute("avmd", "start");
	session.streamFile(argv[0], onInput);

From Dialplan

Note: all it does is set chan variable ${avmd_detect} to "TRUE" and nothing else, so don't rely on this for acting quickly if a beep is detected.

  <!-- mod_avmd test extension (new mod)-->
  <extension name="avmdtest">
    <condition field="destination_number" expression="^(\d{10})$">
      <action application="answer"/>
      <action application="info"/>
      <action application="avmd"/> <!-- Starts detection on the call. -->
      <action application="sleep" data="25000"/>
      <action application="info"/> <!-- Look for chan var "avmd_detect" here -->
      <action application="avmd" data="stop"/> <!-- Stops detection on the call. -->
      <action application="hangup"/>


To compile it simply add this to 'modules.conf':


And do not forget to rebuild and install:

sudo make sure
sudo make install

To have FreeSWITCH load it on startup simply add this to '/usr/local/freeswitch/conf/autoload_configs/modules.conf.xml':

<load module="mod_avmd"/>


No voicemail detection can claim to be 100% accurate. The industry standard is 80% detection. This module if used properly should exceed the standard by a very wide margin.