How to use AMD Answering Machine Detection on Asterisk

To Use AMD - Answering Machine Detection On Asterisk

Introduction

This application attempts to detect an answering machine, based on the timing patterns. This application is usually used by outbound calls originating from either call files or from the Asterisk Manager Interface. This application sets the AMDSTATUS variable is set to one of the following, to show what type of call was detected.

Steps:

Step 1 : Check the OS version by using the below command

root@linuxhelp1:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

Step 2: Check the status of the Asterisk by using the below command

root@linuxhelp1:~# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Thu 2023-07-27 07:25:18 IST; 1 week 5 days ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 71 (limit: 4537)
     Memory: 122.6M
        CPU: 13min 53.557s
     CGroup: /system.slice/asterisk.service
             └─1427 /usr/sbin/asterisk

Jul 27 07:25:18 linuxhelp1 systemd[1]: Starting LSB: Asterisk PBX...
Jul 27 07:25:18 linuxhelp1 asterisk[1404]:  * Starting Asterisk PBX: asterisk
Jul 27 07:25:18 linuxhelp1 asterisk[1404]:    ...done.
Jul 27 07:25:18 linuxhelp1 systemd[1]: Started LSB: Asterisk PBX.
Jul 27 07:25:25 linuxhelp1 asterisk[1427]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusc>
Jul 27 07:25:25 linuxhelp1 asterisk[1427]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusc>

Step – 3 : Move to the Asterisk Directory by using the below command

root@linuxhelp1:~# cd /etc/asterisk/

Step – 4 : Edit the extensions.conf file by using the below command

root@linuxhelp1:/etc/asterisk# vim extensions.conf
Add the following lines
[internal]
exten => 168,1,Answer()
exten => 168,n,AMD()
exten => 168,n,GotoIf("${AMDSTATUS}" = "HUMAN"]?allow:deny)
exten => 168,n(deny),WaitForSilence(2000)
exten => 168,n,Playback(asterisk-friend)
exten => 168,n,Hangup()
exten => 168,n(allow),NoOp(Call from the ${EXTEN} is Detected as a Human)
exten => 168,n,Dial(PJSIP/${EXTEN})
exten => 168,n,Playback(im-sorry)
exten => 168,n,Hangup()

Step – 5 : Go to the Asterisk CLI mode by using the below command

root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvv
Asterisk 20.3.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.3.1 currently running on linuxhelp1 (pid = 1427)

Step – 6 : Reload the dialplan by using the below command

linuxhelp1*CLI> dialplan reload
Dialplan reloaded.
    -- Including switch 'Lua/' in context 'default'
    -- Including switch 'Lua/' in context 'demo'
    -- Including switch 'Lua/' in context 'local'
    -- Including switch 'Lua/' in context 'public'
    -- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000404 sec
    -- Time to restore hints and swap in new dialplan: 0.000006 sec
    -- Time to delete the old dialplan: 0.000080 sec
    -- Total time merge_contexts_delete: 0.000490 sec
    -- pbx_config successfully loaded 27 contexts (enable debug for details).


Output of the AMD application on asterisk dialplan 
    -- Executing [168@internal:1] Answer("PJSIP/167-00000029", "") in new stack
       > 0x7f533c0d33f0 -- Strict RTP learning after remote address set to: 192.168.6.101:4008
    -- Executing [168@internal:2] AMD("PJSIP/167-00000029", "") in new stack
       > 0x7f533c0d33f0 -- Strict RTP learning after remote address set to: 192.168.6.101:4008
    -- AMD: PJSIP/167-00000029 167 (N/A) (Fmt: ulaw)
    -- AMD: initialSilence [2500] greeting [1500] afterGreetingSilence [800] totalAnalysisTime [10000] minimumWordLength [100] betweenWordsSilence [50] maximumNumberOfWords [2] silenceThreshold [256] maximumWordLength [5000]
    -- <PJSIP/167-00000029> Playing 'pls-wait-connect-call.ulaw' (language 'en')
       > 0x7f533c0d33f0 -- Strict RTP switching to RTP target address 192.168.6.101:4008 as source
    -- AMD: Channel [PJSIP/167-00000029]. Changed state to STATE_IN_SILENCE
    -- AMD: Channel [PJSIP/167-00000029]. Word detected. iWordsCount:1
    -- AMD: Channel [PJSIP/167-00000029]. Detected Talk, previous silence duration: 840
    -- AMD: Channel [PJSIP/167-00000029]. Detected Talk, previous silence duration: 40
    -- AMD: Channel [PJSIP/167-00000029]. Detected Talk, previous silence duration: 40
    -- AMD: Channel [PJSIP/167-00000029]. Changed state to STATE_IN_SILENCE
    -- AMD: Channel [PJSIP/167-00000029]. Detected Talk, previous silence duration: 60
    -- AMD: Channel [PJSIP/167-00000029]. Word detected. iWordsCount:2
    -- AMD: Channel [PJSIP/167-00000029]. Changed state to STATE_IN_SILENCE
    -- AMD: Channel [PJSIP/167-00000029]. Detected Talk, previous silence duration: 100
    -- AMD: Channel [PJSIP/167-00000029]. Word detected. iWordsCount:3
    -- AMD: Channel [PJSIP/167-00000029]. ANSWERING MACHINE: iWordsCount:3
    -- Executing [168@internal:3] GotoIf("PJSIP/167-00000029", ""MACHINE" = "HUMAN"]?allow:deny") in new stack
    -- Goto (internal,168,7)
    -- Executing [168@internal:7] NoOp("PJSIP/167-00000029", "Call from the 168 is Detected as a Human") in new stack
    -- Executing [168@internal:8] Dial("PJSIP/167-00000029", "PJSIP/168") in new stack
    -- Called PJSIP/168
    -- PJSIP/168-0000002a is ringing
  == Everyone is busy/congested at this time (1:1/0/0)
    -- Executing [168@internal:9] Playback("PJSIP/167-00000029", "im-sorry") in new stack
    -- <PJSIP/167-00000029> Playing 'im-sorry.ulaw' (language 'en')
       > 0x7f533c0d33f0 -- Strict RTP learning complete - Locking on source address 192.168.6.101:4008
    -- Executing [168@internal:10] Hangup("PJSIP/167-00000029", "") in new stack
  == Spawn extension (internal, 168, 10) exited non-zero on 'PJSIP/167-00000029'
linuxhelp1*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute clean-ups

Step – 7 : Path of the amd.conf file where we edit the amd configuration by using the below command

root@linuxhelp1:/etc/asterisk# vim amd.conf
;
; Answering Machine Detection Configuration
;

[general]
total_analysis_time = 10000     ; Maximum time allowed for the algorithm to decide
                                ; on whether the audio represents a HUMAN, or a MACHINE
silence_threshold = 256         ; If the average level of noise in a sample does not reach
                                ; this value, from a scale of 0 to 32767, then we will consider
                                ; it to be silence.
playback_file = pls-wait-connect-call           ; Audio file to play while AMD is running, so the caller
                                ; does not just hear silence. Note that specifying this here
                                ; will apply to ALL AMD runs, so you may wish to set it
                                ; in the dialplan as an argument to AMD() instead.
                                ; Default is no audio file (not to play anything).

; Greeting ;
initial_silence = 2500          ; Maximum silence duration before the greeting.
                                ; If exceeded, then the result is detection as a MACHINE.
after_greeting_silence = 800    ; Silence after detecting a greeting.
                                ; If exceeded, then the result is detection as a HUMAN
greeting = 1500                 ; Maximum length of a greeting. If exceeded, then the
                                ; result is detection as a MACHINE.

; Word detection ;
min_word_length = 100           ; Minimum duration of Voice to considered as a word
maximum_word_length = 5000      ; Maximum duration of a single Voice utterance allowed.
between_words_silence = 50      ; Minimum duration of silence after a word to consider
                                ; the audio what follows as a new word

maximum_number_of_words = 2     ; Maximum number of words in the greeting
                                ; If exceeded, then the result is detection as a MACHINE

Conclusion :

We have reached the end of this article. In this guide, we have walked you through the steps How to use AMD Answering Machine Detection on Asterisk. Your feedback is much welcome.

FAQ
Q
How to reload the dialplan ?
A
dialplan reload
Q
Where is the amd configuration file located?
A
/etc/asterisk/amd.conf
Q
How to use the AMD application on an Asterisk dialplan?
A
Syntax : exten => extension,priority,AMD()
Q
What are the different types of AMDSTATUS ?
A
MACHINE, HUMAN, NOTSURE, HANGUP
Q
What is the use of AMD?
A
Attempt to detect answering machines.