Custom Language files for Asterisk on Ubuntu


There are a number of steps needed to get custom language files working in a nice fashion for asterisk on ubuntu.

For this example I’m going to replace the standard digits of 0 to 10 with files that I’ve had recorded.

Create files in the correct format:

Starting with files in the format: 0.wav, 1.wav …. 10.wav which are 44.1kHz 16 bit PCM mono wav files.

We can convert them to alaw, ulaw and gsm formats which reduces asterisk transcoding with the following script: (requires sox to be installed)


#!/bin/sh
#
# Script to batch convert wav files to gsm,alaw and ulaw formats
# to help reduce overhead for asterisk server
# Run it in a directory of wav files.

for a in *.wav; do
echo “Processing $a”;
baseName=`echo $a|sed -e s/.wav//`;

#Convert to 8bit wav first at 8000Hz – this can take a while
sox “$a” -r 8000 -c1 “$baseName_temp.wav” resample -ql;

echo “…additional formats”;
#Convert to gsm
sox “$baseName_temp.wav” “$baseName.gsm”;

#convert to alaw – note using .alaw extension as asterisk likes that
sox “$baseName_temp.wav” -t al “$baseName.alaw”;
#convert to ulaw – note using .ulaw extension as asterisk likes that
sox “$baseName_temp.wav” -t ul “$baseName.ulaw”;

#clean up the .wav files
rm “$baseName_temp.wav”
done

Move the files to the correct place on the server:

I’m going to use the name ‘learnosity’ for the language as these are the files that we’ve recorded. So we need to create the following directory on the asterisk machine:


/usr/share/asterisk/sounds/digits/learnosity

If you wanted to do more audio files, you can create learnosity directories for the other audio files.

Once this is done, copy the alaw, ulaw and gsm files in but leave the original wav files out.

Tell asterisk to use these files:

The easiest way to use these language files is to set the channel language for the sections you want to use it:

Here’s an example from extensions.conf:


exten => 4,1,Answer()
exten => 4,n,SayDigits(123456789)
exten => 4,n,Set(CHANNEL(language)=learnosity)
exten => 4,n,SayDigits(123456789)
exten => 4,n,Hangup()

If you dial extension 4 you get the digits 1 to 9 in the default language and if you’ve done everything correctly you will get your newly recorded digits the second time.

Cheers,
Mark


This post was posted in , , by on