Skip to main content

mod_avmd — Answering Machine and Beep Detection

mod_avmd (Advanced Voicemail Detection) attaches a media bug to a call leg and analyzes the audio stream in real time to detect single-frequency beep tones in the 440–2000 Hz range. Detection uses a modified DESA-2 algorithm with configurable amplitude and frequency estimators running across multiple parallel detector threads. When a beep is confirmed, the module fires an avmd::beep event and sets channel variables that downstream dialplan actions or scripts can test.

Operators reach for this module when building progressive-dialer or click-to-call flows that need to skip over voicemail greetings and respond as soon as the recording beep sounds — for example, to play a pre-recorded message or disconnect before leaving an unwanted recording.

Loading the Module

The module name is mod_avmd. It is not included in the vanilla modules.conf.xml load list and must be added manually:

<load module="mod_avmd"/>

No special build flag is required; the module compiles as part of the standard FreeSWITCH build when the applications group is enabled.

Configuration: avmd.conf.xml

mod_avmd reads autoload_configs/avmd.conf.xml at load time and re-reads it whenever a reloadxml event fires or the avmd reload API command is issued. All parameters live in a single <settings> block. Per-session values can be overridden at the dialplan level (see Dialplan Applications).

Parameter Reference

ParameterPurposeAccepted ValuesDefault
debugLog intermediate DESA-2 computation values0 / 10
report_statusLog detection status, session start/stop diagnostics, and config dumps0 / 11
fast_mathUse a memory-mapped arc cosine lookup table for faster computation (non-Windows only)0 / 10
require_continuous_streakRequire a consecutive run of SMA frequency samples (no reset) before declaring a beep0 / 11
sample_n_continuous_streakNumber of consecutive frequency SMA samples requiredinteger 0–655353
sample_n_to_skipSamples to skip at the start of each frame and after a reset, to discard inaccurate early estimatesinteger 0–655350
require_continuous_streak_ampSame as require_continuous_streak but for the amplitude estimator0 / 11
sample_n_continuous_streak_ampNumber of consecutive amplitude SMA samples requiredinteger 0–655353
simplified_estimationApproximate sin(x) with x in the range [0, π/2] for faster frequency estimation0 / 11
inbound_channelEnable detection on inbound call legs (write stream)0 / 10
outbound_channelEnable detection on outbound call legs (read stream)0 / 11
detection_modeCriteria used to declare a beep: 0 = amplitude only, 1 = frequency only, 2 = both0, 1, 22
detectors_nNumber of parallel detector threads per sessioninteger 0–25536
detectors_lagged_nNumber of additional lagged detector threads per sessioninteger 0–2551

Configuration Example

<configuration name="avmd.conf" description="AVMD config">
<settings>
<param name="debug" value="0"/>
<param name="report_status" value="1"/>
<param name="fast_math" value="0"/>
<param name="require_continuous_streak" value="1"/>
<param name="sample_n_continuous_streak" value="3"/>
<param name="sample_n_to_skip" value="0"/>
<param name="require_continuous_streak_amp" value="1"/>
<param name="sample_n_continuous_streak_amp" value="3"/>
<param name="simplified_estimation" value="1"/>
<param name="inbound_channel" value="0"/>
<param name="outbound_channel" value="1"/>
<param name="detection_mode" value="2"/>
<param name="detectors_n" value="36"/>
<param name="detectors_lagged_n" value="1"/>
</settings>
</configuration>

Dialplan Applications

ApplicationPurposeArguments
avmd_startAttach a media bug and start beep detection on the current sessionOptional comma-separated key=value pairs overriding any global config setting
avmd_stopRemove the media bug and stop detection, firing an avmd::stop eventNone
avmdDeprecated combined start/stop interface (do not use in new dialplans)stop to stop; no argument to start

avmd_start

Starts detection on the current session. With no arguments the global configuration values are used. Any subset of configuration parameters can be passed as comma-separated key=value pairs to override the global setting for this session only.

<!-- Start detection on an inbound leg, using frequency+amplitude mode -->
<action application="avmd_start" data="inbound_channel=1,outbound_channel=0,detection_mode=2"/>
<!-- Start with global defaults (outbound leg, detection_mode=2) -->
<action application="avmd_start"/>

avmd_stop

Stops detection and fires an avmd::stop event containing the final beep status and total running time.

<action application="avmd_stop"/>

Typical dialplan pattern

<extension name="detect_beep">
<condition field="destination_number" expression="^5551234$">
<action application="avmd_start" data="outbound_channel=1,detection_mode=2"/>
<action application="bridge" data="sofia/gateway/mycarrier/15551234"/>
<action application="avmd_stop"/>
</condition>
</extension>

API Commands

The avmd API command is available from fs_cli or ESL. Its full syntax is:

avmd <uuid> < start | stop >
avmd set < inbound | outbound | default >
avmd load < inbound | outbound >
avmd reload
avmd show
CommandPurposeSyntax
avmd <uuid> startStart detection on an existing session by UUIDavmd <uuid> start
avmd <uuid> stopStop detection on a sessionavmd <uuid> stop
avmd set inboundSet global direction to inbound=1, outbound=0 (in memory only)avmd set inbound
avmd set outboundSet global direction to inbound=0, outbound=1 (in memory only)avmd set outbound
avmd set defaultReset all global settings to factory defaults (in memory only)avmd set default
avmd load inboundReload XML config then set direction to inboundavmd load inbound
avmd load outboundReload XML config then set direction to outboundavmd load outbound
avmd reloadReload XML configuration from diskavmd reload
avmd showDisplay current global settings and active session countavmd show

fs_cli examples

avmd 3e7a2707-cd5a-4b5e-8c7f-1234abcd start
avmd 3e7a2707-cd5a-4b5e-8c7f-1234abcd stop
avmd reload
avmd show

Channel Variables

VariableSet / ReadPurpose
avmd_detectSetSet to TRUE when a beep is detected
avmd_total_timeSetDetection elapsed time in milliseconds from detection start to detection stop
execute_on_avmd_beepReadDialplan action string executed by the module via switch_channel_execute_on immediately on beep detection

Events

mod_avmd registers and fires three custom event subclasses under SWITCH_EVENT_CUSTOM:

Event SubclassFired WhenExtra Headers
avmd::startWhen avmd_start (or avmd <uuid> start) successfully attaches the media bugUnique-ID, Start-time
avmd::beepWhen a beep is detected on the audio streamUnique-ID, Beep-Status (DETECTED), Frequency, Frequency-variance, Amplitude, Amplitude-variance, Detection-time, Detector-resolution, Detector-offset, Detector-index
avmd::stopWhen avmd_stop (or avmd <uuid> stop) removes the media bugUnique-ID, Beep-Status (DETECTED or NOTDETECTED), Total-time

Both the originating session queue and the global event bus receive each event.

Source: src/mod/applications/mod_avmd, conf/vanilla/autoload_configs/avmd.conf.xml