Quick convert raw g711 uLaw audio to a .au file

I had reason to playback some raw g.711 audio data. I made the following script to convert the data to a .au file that is playable.

From the AU file spec.. which is way simple by the way:
You just need to add 6 32-bit header flags.


import struct

header = [ 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 ]
o.write ( struct.pack ( ">IIIIII", *header ) )

raw = open('in.raw','rb').read()

You can probably see that this would be extremely simple to use with other audio formats too. Modify as you need.
Header Bytes:

  1. Const AU identifier: 0x2e736e64
  2. Size of Header: 24.
  3. Size of File: use 0xffffffff for unknown, or you could replace with the actual size.
  4. Audio format. 1 is uLaw. From the spec choose whatever you need if it isn’t uLaw.
  5. Sample rate. uLaw is always 8000.
  6. Channels. 1 channel in this case.
This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

One Response to Quick convert raw g711 uLaw audio to a .au file

  1. toanhoi says:

    Good idea. I want to convert this code to Java. Can you help me.
    byte [] header*= { (byte*) 0x2e736e64}; //24, 0xffffffff, 1, (byte) 8000, 1 };
    FileOutputStream out = new FileOutputStream(file);

Comments are closed.