DEV Community

Ekim
Ekim

Posted on • Updated on

Record and Hear your voice through Asterisk

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

Asterisk basic set up

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
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

It's time to restart the asterisk to make things ready.

sudo service asterisk restart
Enter fullscreen mode Exit fullscreen mode

Then remember to go to CLI to reload the dialplan and pjsip.

sudo asterisk -rvvvvv
Enter fullscreen mode Exit fullscreen mode
dialplan reload
core reload
Enter fullscreen mode Exit fullscreen mode

Open you softphone and do the following settings

microsip-set-up

  • 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.

microsip-set-up

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.

microsip-set-up

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 !!!

Discussion (0)