How to get DTMF input with Background Audio on Asterisk
To Get DTMF Input With Background Audio On Asterisk
Introduction
Dual-tone multi-frequency (DTMF) is the sounds or tones generated by a telephone when the numbers are pressed. These tones are transmitted with the voice channel that is used to control automated equipment and signal user intent, such as the number they wish to dial. Each key has two tones at specific frequencies.
Procedure
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 2 days ago
Docs: man:systemd-sysv-generator(8)
Process: 1404 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
Tasks: 72 (limit: 4537)
Memory: 136.6M
CPU: 6min 793ms
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>
lines 1-17/17 (END)
Step 3: Move to the Asterisk directory by using the below command
root@linuxhelp1:~# cd /etc/asterisk/
Step 4: Edit the extensions.conf file to modify the dialplan by using the below command
root@linuxhelp1:/etc/asterisk# vim extensions.conf
add the following line
exten => _XXX,1,playback(hello)
exten => _XXX,n, playback(zombies)
exten => _XXX,n,WaitExten()
exten => 1,1,NoOp(you entered extension 1)
exten => 2,1,NoOp(you entered extension 2)
exten => i,1,Playback(invalid)
Step 5: Login to the Asterisk CLI mode by using the below command
root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvvvvvvvvvv
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 'public'
-- Including switch 'Lua/' in context 'default'
-- Including switch 'Lua/' in context 'demo'
-- Including switch 'Lua/' in context 'local'
-- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
-- Time to scan old dialplan and merge leftovers back into the new: 0.000878 sec
-- Time to restore hints and swap in new dialplan: 0.000005 sec
-- Time to delete the old dialplan: 0.000181 sec
-- Total time merge_contexts_delete: 0.001064 sec
-- pbx_config successfully loaded 27 contexts (enable debug for details).
Output of the DTMF get input in asterisk dialplan context by using playback application.
-- Added contact 'sip:167@192.168.6.101:61935;transport=TCP;ob' to AOR '167' with expiration of 300 seconds
== Endpoint 167 is now Reachable
-- Contact 167/sip:167@192.168.6.101:61935;transport=TCP;ob is now Reachable. RTT: 2.455 msec
-- Executing [167@internal:1] Playback("PJSIP/167-00000018", "hello") in new stack
> 0x7f5354010510 -- Strict RTP learning after remote address set to: 192.168.6.101:4000
-- <PJSIP/167-00000018> Playing 'hello.ulaw' (language 'en')
> 0x7f5354010510 -- Strict RTP switching to RTP target address 192.168.6.101:4000 as source
-- Executing [167@internal:2] Playback("PJSIP/167-00000018", "zombies") in new stack
-- <PJSIP/167-00000018> Playing 'zombies.ulaw' (language 'en')
> 0x7f5354010510 -- Strict RTP learning complete - Locking on source address 192.168.6.101:4000
-- Executing [167@internal:3] WaitExten("PJSIP/167-00000018", "") in new stack
-- Executing [2@internal:1] NoOp("PJSIP/167-00000018", "you entered extension 2") in new stack
-- Executing [168@internal:1] Playback("PJSIP/167-00000019", "hello") in new stack
> 0x7f535400fcf0 -- Strict RTP learning after remote address set to: 192.168.6.101:4002
-- <PJSIP/167-00000019> Playing 'hello.ulaw' (language 'en')
> 0x7f535400fcf0 -- Strict RTP switching to RTP target address 192.168.6.101:4002 as source
-- Executing [168@internal:2] Playback("PJSIP/167-00000019", "zombies") in new stack
-- <PJSIP/167-00000019> Playing 'zombies.ulaw' (language 'en')
> 0x7f535400fcf0 -- Strict RTP learning complete - Locking on source address 192.168.6.101:4002
-- Executing [168@internal:3] WaitExten("PJSIP/167-00000019", "") in new stack
-- Invalid extension '8' in context 'internal' on PJSIP/167-00000019
-- Executing [i@internal:1] Playback("PJSIP/167-00000019", "invalid") in new stack
-- <PJSIP/167-00000019> Playing 'invalid.ulaw' (language 'en')
-- Auto fallthrough, channel 'PJSIP/167-00000019' status is 'UNKNOWN'
linuxhelp1*CLI>
Step 7: Edit the extensions.conf file to use Background application by using the below command
root@linuxhelp1:/etc/asterisk# vim extensions.conf
Add the following lines
exten => _XXX,1,playback(hello)
exten => _XXX,n,Background(zombies)
exten => _XXX,n,WaitExten()
exten => 1,1,NoOp(you entered extension 1)
exten => 2,1,NoOp(you entered extension 2)
exten => i,1,Playback(invalid)
Step 8 : Again login to the Asterisk CLI mode by using the below command
root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvvvvvvvvvv
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 9: Reload the dialplan by using the below command
linuxhelp1*CLI> dialplan reload
Dialplan reloaded.
-- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
-- Including switch 'Lua/' in context 'local'
-- Including switch 'Lua/' in context 'demo'
-- Including switch 'Lua/' in context 'default'
-- Including switch 'Lua/' in context 'public'
-- Time to scan old dialplan and merge leftovers back into the new: 0.000480 sec
-- Time to restore hints and swap in new dialplan: 0.000005 sec
-- Time to delete the old dialplan: 0.000066 sec
-- Total time merge_contexts_delete: 0.000551 sec
-- pbx_config successfully loaded 27 contexts (enable debug for details).
Output of the DTMF get input in asterisk dialplan context by using background application
-- Executing [168@internal:1] Playback("PJSIP/167-0000001a", "hello") in new stack
> 0x7f535400fcf0 -- Strict RTP learning after remote address set to: 192.168.6.101:4004
-- <PJSIP/167-0000001a> Playing 'hello.ulaw' (language 'en')
> 0x7f535400fcf0 -- Strict RTP switching to RTP target address 192.168.6.101:4004 as source
-- Executing [168@internal:2] BackGround("PJSIP/167-0000001a", "zombies") in new stack
-- <PJSIP/167-0000001a> Playing 'zombies.ulaw' (language 'en')
> 0x7f535400fcf0 -- Strict RTP learning complete - Locking on source address 192.168.6.101:4004
-- Executing [2@internal:1] NoOp("PJSIP/167-0000001a", "you entered extension 2") in new stack
-- Auto fallthrough, channel 'PJSIP/167-0000001a' status is 'UNKNOWN'
linuxhelp1*CLI>
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps how to get DTMF input on Asterisk Dialplan Context. Your feedback is much welcome.
Comments ( 0 )
No comments available