Asterisk itself can transcode many audio formats such as g722, alaw and ulaw to name a few. Over the years FreePBX itself has required a few binaries to deal with importing MP3s and generating some wav files. These two binaries are important today so make sure they are installed before reading the rest of this article:
- sox (general conversion utility)
- mpg123 (allows uploading of MP3 files)
However Asterisk itself is unable to convert many files into HTML5 compatible audio types even with the two programs above!
What is an "HTML5 compatible audio file"?
Before HTML5, there was no standard for playing audio files on a web page. Before HTML5, audio files could only be played with a plug-in (like quicktime). With HTML5 audio files are able to be played back natively in your browser!
Great! So generate the HTML5 files for me
Unfortunately every browser supports a formats of audio files. We can't just generate a wav file and expect all browsers to understand it.
Wikipedia has a list of the different formats supported by different browsers – see the table at https://en.wikipedia.org/wiki/HTML5_Audio.
Ok. So can you generate the different formats?
This is where the fun begins. Unfortunately due to licensing and legalities we are not able to distribute anything that makes MP3 or MP4 (M4A) files. However it's not illegal for you to compile the binaries for these programs yourself. After you've installed them FreePBX can transcode your audio files for you!
So what do I have to do?
There are different options for different types of files. After looking at the table above you need to decide what you want to support. After the libraries have been installed FreePBX will automatically detect them and use them to create files.
WAV files can be generated through either Asterisk itself or through SOX. In nearly all distributions you can download and install SOX through rpm repositories (yum install sox or apt-get install sox)
OGG/OGA files can be generated through SOX. You can download and install SOX through rpm repositories (yum install sox or apt-get install sox)
MP3 files are usually generated through a program called LAME. There are several install guides for LAME online. A good starting point would be: http://lame.sourceforge.net/
MP4/M4A files are usually generated through a program called FFMPEG. There are several install guides for FFMPEG online. A good starting point would be: https://www.ffmpeg.org/
ffmpeg is a beast and takes like 40 minutes to compile on my machine. A helpful addition to this article would be the most minimal build options that are needed for converting m4a to wav!
I'll work on that. I use ffmpeg heavily for other audio/video/subtitle tasks and I've gotten fairly good at complex, maximized, builds, so it should not be all that hard to to come up with minimal build requirements. Would also be great to create and srpm and binaries that could be hosted in a repo.
There is a static build available, and it's linked to from the official download page so it should be trustworthy. Probably not as fast as a natively compiled build, but much easier to install. Just download and extract it, copy the binaries into
/usr/local/binand you're set. https://www.johnvansickle.com/ffmpeg/