Voicemail transcription is a great feature to have in any voice system. Voicemail transcription is the process of converting voicemail audio into text, so you can read what was said in the voicemail without having to actually listen to the vo
icemail message itself. This process can also work with recorded calls and other audio files. In this article, I’m going to show you how to configure Asterisk (More specifically,
Elastix) to transcribe voicemail messages and send them via email to the user.
Instructions
These instructions are based off directions originally posted by Nickolay V. Shmyrev
here but with many alterations.
Step 1
Install the dependancies needed to compile and install PocketSphinx:
CentOS/RHEL/Fedora
Ubuntu/Debian
Code:
sudo apt-get install libtool build-essentials
Step 2
Download the latest version of PocketSphinx and SpinxBase and extract it. You can find the latest version on their website:
http://cmusphinx.sourceforge.net/wiki/download
You can also download the packages using wget:
Code:
wget http://cmusphinx.svn.sourceforge.net/viewvc/cmusphinx/trunk/sphinxbase/?view=tar -O sphinxbase.tgz
wget http://cmusphinx.svn.sourceforge.net/viewvc/cmusphinx/trunk/pocketsphinx/?view=tar -O pocketsphinx.tgz
And extract:
Code:
tar xvfz sphinxbase.tgz
tar xvfz pocketsphinx.tgz
Step 3
You can then compile and install sphinxbase:
Code:
cd sphinxbase/
./autogen.sh
make
make install
Then compile and install pocketsphinx:
Code:
cd pocketsphinx/
./autogen.sh
make
make install
Step 4
Download an acoustic model that pocketsphinx will use to transcribe the voicemails.
Code:
wget http://downloads.sourceforge.net/project/cmusphinx/Acoustic%20and%20Language%20Models/US%20English%20Communicator%20Telephone%20Acoustic%20Model/communicator_4000_20080321.tar.gz
And extract and move the acoustic model somewhere we can use it later:
Code:
tar xvfz communicator*.tar.gz
mv Communicator_40.cd_cont_4000 /var/lib/asterisk/communicator/
Step 5
We’ll next need to create a script that will perform the transcription, and save the transcript as a text file so we can include the text in an email. You can view the script below, or download it
here:
Code:
nano /sbin/voicemail-transcribe.sh
Code:
#!/bin/sh
voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/
echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log
for audiofile in `ls $voicemaildir/*.wav`; do
transcriptfile=${audiofile/wav/transcript}
# For each message.wav we check if message.transcript
# exists
if [ ! -f $transcriptfile ]; then
# If not, we create it
/usr/local/bin/pocketsphinx_continuous -infile $audiofile \
-hmm /var/lib/asterisk/communicator \
-samprate 8000 2> /var/log/asterisk/voicemail-notify.log \
> $transcriptfile
# Now we can do whatever we want with the new transcription
echo `cat $transcriptfile | cut -d: -f2`
fi
done
Then, ensure that the script is executable:
Code:
chmod +x /sbin/voicemail-transcript.sh
Step 6
We can then modify the voicemail email template to include a section for the voicemail transcription. This in an important step because we’ll be using a secondary script that will insert the voicemail transcript into the email after the keywords “Voicemail Transcript”.
Add the following text to
/etc/asterisk/vm_email.inc at the end of the
“emailbody=” line. Note that this must be one continuous line.
Code:
\nExtension: ${VM_MAILBOX}\nVoicemail Transcription: \n\n
Step 7
We’ll then need to create a secondary script that will grab the email generated by Asterisk and modify it to include the voicemail transcription. You can view the script below or download it
here:
Code:
#!/bin/sh
cat > /tmp/voicemail.tmp
# Grab the extension of the voicemail
EXT=`cat /tmp/voicemail.tmp | grep Extension | awk {'print $2'}`
# Transcribe the voicemail for the given extension
/sbin/voicemail-transcribe.sh default $EXT > /tmp/transcribe.tmp
# Append the outgoing email with the voicemail transcription
cat /tmp/voicemail.tmp \
| sed "/Voicemail Transcription:/ r /tmp/transcribe.tmp" \
| /usr/sbin/sendmail -t
# Clean up temporary files
rm /tmp/voicemail.tmp
rm /tmp/transcribe.tmp
Then, ensure that the script is executable:
Code:
chmod +x /sbin/vm-modify.sh
Step 8
You’ll then need to modify the Asterisk voicemail configuration to use our script instead of the default sendmail agent:
Code:
nano /etc/asterisk/voicemail.conf
And add the mailcmd option to use our script:
Code:
[general]
…
mailcmd=/sbin/vm-modify.sh
And that’s it! Now whenever a user receives a voicemail, the message will be transcribed and sent in an email along with their voicemail message. You can also modify these scripts to perform other fancy tasks with your voicemail transcription!