Convert audio files to ulaw or sln for use with a VoIP PBX (Updates for 2018)

August 13, 2018
Converting high quality audio files to ulaw is easy, but making them sound good takes some effort. Keep reading for the technique we use, updated for 2018. Allison on Twitter writes:

Anyone have a simple tutorial on how to convert sound files to Linux Sox for a highly non-technical voice Goddess?

— Allison Smith (@voicegal) August 13, 2018
This sounds like a great time to revisit this article and rerun tests with the latest versions of our audio tools. In our opinion, the results of the following sounded best when played via Asterisk to a G.711-capable phone, and it was a very close second place when played to a G.722-capable phone. This is what we plan to use going forward.
sox input.wav --rate 8000 --channels 1 --type raw output.sln lowpass 3400 highpass 300
Without the lowpass and highpass, we thought the audio sounded slightly better to a G.722 phone, but not as good to a G.711 phone. However, the difference was subtle enough that we recommend you do your own testing with your own audio files, in case your opinion is different from ours.
sox input.wav --rate 8000 --channels 1 --type raw output.sln
NOTE: Depending on the type of CPU in your Asterisk server, if you hear a high-pitched screech instead of your audio file, you may need to use the --endian big switch like this:
sox input.wav --rate 8000 --channels 1 --type raw --endian big output.sln lowpass 3400 highpass 300
ulaw did not produce results that sounded as good as sln.
sox input.wav --rate 8000 --channels 1 --type ul output.ulaw lowpass 3400 highpass 300
In our tests with ulaw, ffmpeg and sox produced identical results.
ffmpeg -i input.wav -af "highpass=f=300, lowpass=f=3400" -ar 8000 -ac 1 -ab 64k -f mulaw output.ulaw
Adam W
July 18, 2011
Life. Saver. :-)
April 10, 2012
Couldn't help to stop by to say thanks. I had some gsm files that I wanted to convert to ulaw, and the second line worked for me.