Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!)

share|improve this question
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
up vote 1 down vote accepted

For the quickest, simplest solution I would convert the μlaw file to wav using an external tool, then import the result into Mathematica.

Here's an article I found about how to do this. sox is available for all three common platforms.

share|improve this answer
I am familiar with sox, but I'm looking for a way to import uLaw into Mathematica directly, without first needing to convert to a different format. It looks like Mathematica has all of the necessary pieces built in (in particular, support for µ-law compression). Surely there is a way to get it to parse this format. – SWB Sep 13 '13 at 4:10
@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 ?System`Convert`AudioDump`*. 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 System`Convert`AudioDump`ImportAudioFile, 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.