# Import audio in uLaw format?

How do I import a uLaw-format audio file into Mathematica? Here's an example:

For reference, here's the same file in wav format:

As I understand it, the uLaw format contains raw µ-law audio data. In this respect, it should be very similar (or identical) to AU, which Mathematica supports, except there is no header.

I have tried:

Import["hello-world.ulaw", "AU"]


but Mathematica returns:

Import::fmterr: Cannot import data as AU/SND format.


From the documentation, it looks like there is probably some combination of parameters and options that will work, but the Import/Export documentation doesn't go into much detail on how to actually use the various available options. (Or at least, not in a way that makes sense to me!)

-
You can import the data in the file with BinaryReadList["hello-world.uLaw"]. This gives a long list of values (between 2 and 255). Normally one would turn these into sound with SampledSoundList but it does not lead to an intelligible sound in this case, so the data must be encoded in some way. –  bill s Sep 11 '13 at 4:11

@SWB You can run sox from within Mathematica, and even read through a pipe. Import["!sox ...", "WAV"] will read whatever sox writes to stdout. This is going to give you a seamless and practical, but maybe not "beautiful" solution. If you need to see how Mma reads AU, your can do spelunking, starting with the SystemFiles/Formats folder, figure out how it works, and re-use the bits to read your files. I expect it to be doable with a few hours of work, but personally I don't think it's worth the effort when there's already a convenient solution. –  Szabolcs Sep 13 '13 at 4:24
@SWB To give some more guidance, start with importing some AU file to trigger loading all relevant functions. Then take a look ?SystemConvertAudioDump*. It looks like there are some useful pieces there (mentions of μlaw). These spelunking tools will come handy. –  Szabolcs Sep 13 '13 at 4:31
Thanks, @Szabolcs! It hadn't occurred to me to use sox as an importer for Mathematica, and I didn't know until now how to efficiently study Mathematica's internal implementation. After a few minutes with Spelunk, I've found that importing an AU file results in a call to SystemConvertAudioDumpImportAudioFile, which finally calls \$InstallationDirectory\SystemFiles\Converters\Binaries\Windows-x86-64\Audio.exe‌​ over a MathLink connection to perform the import. Therefore, it looks like the only solution will be to use an external helper like sox. –  SWB Sep 13 '13 at 15:20