Fun With Command-Line SIP

I always wanted to have the ability to have a program call my cell and give me an automated voice message, especially if something really goes awry in my infrastructure. Getting called and having to pick up the phone is way better than getting a page or text message, especially when you are sleeping.

The pjsip SIP library comes with a CLI tool pjsua that you can use to place calls. Using Google Translate and sox to convert MP3 to WAV, I constructed the following:


if [ "$#" -ne "2" ]; then
  echo "usage: basename $0 'text message' phone_number"
  exit 1


URLMESSAGE=$( echo $MESSAGE | sed 's/ /+/g' )
wget -q -U Mozilla -O /tmp/message.mp3 \
sox /tmp/message.mp3 /tmp/message.wav
( sleep 45; echo q ) | $HOME/bin/pjsua --config-file $HOME/.pjsuarc \

And the config file:

--username 1234 
--password password 
--realm asterisk 
--play-file /tmp/message.wav

If you want to send longer messages, you can’t use Google API since the message cannot exceed 100 characters. Use Festival instead:

echo $MESSAGE | text2wave -o /tmp/message.wav

Have fun! With such power comes great responsibility!

Dialogue & Discussion