Weekly sharing
Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer.
Previously
Introduction
Last week was quite a fuzzy journey. Not much concrete output has been done. Although the progress is slow, I still would like to share how to record and play audio through Asterisk.
Recording through dialing 41XXXX
Let's create an endpoint of 1114 for our softphone.
- In pjsip.conf,
;================================ TRANSPORTS ==
; Our primary transport definition for UDP communication behind NAT.
[transport-udp-nat]
type = transport
protocol = udp
bind = 0.0.0.0
; NAT settings
;local_net = 10.0.0.0/8
;external_media_address = 203.0.113.1
;external_signaling_address = 203.0.113.1
;================================ CONFIG FOR SIP ITSP ==
[endpoint-useragent](!)
type=endpoint
context=recordAndPlayback
allow = !all,ulaw,alaw
direct_media=no
trust_id_outbound=yes
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
device_state_busy_at=1
dtmf_mode=rfc4733
[auth-userpass](!)
type = auth
auth_type = userpass
[aor-single-reg](!)
type = aor
max_contacts = 1
[1114](endpoint-useragent)
auth=1114
aors=1114
callerid = 1114 <1114>
[1114](auth-userpass)
password = 1114
username = 1114
What I want to do here is to dial a number, which starts with 41 and is followed by any 4 digits, to record my voice on the softphone. And then, I would like hear my voice again when I dial 42 + any 4 digits I've just dialed.
- So, in the extensions.conf
[recordAndPlayback]
exten = _41XXXX,1,Answer
same = n,Record(record/${EXTEN:2}.gsm) ; record your voice and save it in the name of XXXX, the any 4 digits you dialed and in .gsm format
same = n,Wait(1)
same = n,Hangup()
exten = _42XXXX,1,Answer
same = n,Wait(1)
same = n,Playback(record/${EXTEN:2}) ; play the audio file you recorded from /var/lib/asterisk/sounds/record
same = n,Wait(1)
same = n,Hangup()
After that, add the load = app_record.so
in your modules.conf
.
;Application
load = app_bridgewait.so
load = app_dial.so
load = app_playback.so
load = app_stack.so
load = app_verbose.so
load = app_voicemail.so
load = app_directory.so
load = app_confbridge.so
load = app_queue.so
load = app_record.so ; add this into your modules.conf, so that you do not need to load the module every time.
It's time to restart the asterisk to make things ready.
sudo service asterisk restart
Then remember to go to CLI to reload the dialplan and pjsip.
sudo asterisk -rvvvvv
dialplan reload
core reload
Open you softphone and do the following settings
The SIP server and Domain should be your Ubuntu's IP. You can check it by this command:
ip addr
If you have problem connecting your softphone to your Ubuntu, please check that you've done these firewall settings: https://www.voip-info.org/asterisk-firewall-rules/ .
Hearing your voice
So, if you followed the aforementioned steps, you should be able to record your voice by dialing, for example, 411234. Noted that when you finish your recording, press # to finish the call. Do Not End The Call Right Away, or it won't save the recording.
After recording your voice, it's time to appreciate the cuss words you've just sworn yourself. (Yeah, I know it !!!! We all do it to ourselves.)
When you dial 421234
, you should hear your recording straight away.
Conclusion
Usually, when we want someone to record an audio track, we won't just use the Record
dialplan application alone because they won't have an idea that they need to press #
to save the recording. Hence, it is better to record a track that guides them what to do after they record their voices. That's what we'll do next time. For the time being, stay healthy and stay tuned !!!
Top comments (0)