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:

#!/bin/bash

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

MESSAGE=$1
NUMBER=$2

URLMESSAGE=$( echo $MESSAGE | sed 's/ /+/g' )
wget -q -U Mozilla -O /tmp/message.mp3 \
  "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=$URLMESSAGE"
sox /tmp/message.mp3 /tmp/message.wav
( sleep 45; echo q ) | $HOME/bin/pjsua --config-file $HOME/.pjsuarc \
  sip:$NUMBER@pbx.domain.com

And the config file:

--id sip:1234@pbx.domain.com 
--registrar sip:pbx.domain.com 
--username 1234 
--password password 
--realm asterisk 
--null-audio 
--auto-play 
--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