For several years, Electromagnetic Field has operated its own internal telephone system. Attendees can set up one or more extensions which can terminate on a copper telephone line, a DECT phone, a SIP endpoint or a GSM phone.
Two years ago, I set up BatFax on a Raspberry Pi. Call the number, it calls you back and sends you a fax with a fact about bats. This time around, I wanted to do something more whimsical and considerably less difficult.
My initial idea was to register extension 2820 (twit-twoo) which simply plays back an MP3 of an owl. Everyone got the joke apart from one person who shall remain nameless, and there were a couple of hundred calls during the event after I put up an advert on the on-site Infobeamer.

I have a varied tech history, and did a lot of VoIP and SIP work in the mid-2000s using Asterisk. Since somebody asked about automated phone lines on Discord, I decided the best way to explain how to do it is by example. It’ll also serve as a reminder for me in two years time when I inevitably forget.
Please bear in mind that this is a really quick write-up and doesn’t cover everything. I can’t teach you all about VoIP, security, Asterisk and SIP, but I’ve tried to make the configuration as clear as I can.
First, you need to install Asterisk. I’ll leave that up to you.
Next, you need to set up several configuration blocks in /etc/asterisk/pjsip.conf.
The first is the transport configuration. UDP is used for SIP rather than TCP because latency is more important than guaranteed delivery:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0Next up, we need some authentication credentials to register with the remote Asterisk server:
[emf2820]
type=auth
auth_type=userpass
username=2820
password=geeksinafieldWe need an Address of Record (AOR):
[emf2820]
type=aor
contact=sip:2820To differentiate incoming calls, we need to tell Asterisk how to identify an incoming call to 2820. We do this by matching the To header in the SIP message, and check if it contains sip:2820@sip.emf.camp.
[emf2820]
type=identify
endpoint=emf2820
match_header=To:/sip:2820@sip.emf.camp/Next, we need to configure an endpoint. This combines the transport, authentication, AOR and identification, and defines the context for which calls are made/received. I won’t go in to it too much, but for security we’re just using a single context named emf which has nothing else in it. No other endpoints, no outbound trunks, no inbound trunks. VoIP is quite easy to get wrong, and you don’t want somebody being able to dial in, then somehow dial out again at your expense!
[emf2820]
type=endpoint
transport=transport-udp
outbound_auth=emf2820
aors=emf2820
disallow=all
allow=all
identify_by=header
from_domain=sip:sip.emf.camp
context=emfFinally, Asterisk needs to register, so we set this up.
[emf2820]
type=registration
server_uri=sip:sip.emf.camp
outbound_auth=emf2820
client_uri=sip:2820@sip.emf.campTo make this live, run pjsip reload at the Asterisk console. pjsip list registrations will then, hopefully, show that the server has registered.
Finally, we need to configure extensions.conf to handle incoming calls. The following minimal configuration will answer calls coming in to context emf, wait for one second, then play a custom sound from /usr/local/share/asterisk/sounds:
[general]
static=yes
writeprotect=yes
clearglobalvars=no
[emf]
exten => s,1,Wait(1)
same => 2,Playback(custom/long-eared-owl)
same => 3,Wait(2)
same => 4,Hangup()Incoming calls may use a variety of codecs, so if you want to cater both for high quality audio connections and low-bandwidth u-law connections, you can use sox to convert files from MP3 to other formats. It’s quite simple – replace $FILE with the name of the MP3 containing owl sounds, and run these commands to generate the file formats:
/usr/bin/sox $FILE.mp3 -r 8000 -c 1 -t ul $FILE.ulaw vol 0.9
/usr/bin/sox $FILE.mp3 -r 8000 -c 1 -t al $FILE.alaw vol 0.9
/usr/bin/sox $FILE.mp3 -r 8000 -c 1 $FILE.gsm vol 0.9
/usr/bin/sox $FILE.mp3 -r 8000 -c 1 -b 16 $FILE.wav vol 0.9
/usr/bin/ffmpeg -loglevel quiet -i $FILE.mp3 -ar 16000 -ac 1 -acodec g722 $FILE.g722That’s really it. Reload the Asterisk configuration and have some fun!