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.

raw2au.py:

  1. import struct
  2.  
  3. header = [ 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 ]
  4. o=open('out.au','wb')
  5. o.write ( struct.pack ( ">IIIIII", *header ) )
  6.  
  7. raw = open('in.raw','rb').read()
  8. o.write(raw)
  9. o.close()
  10.  
  11.  

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.

1 Response to “Quick convert raw g711 uLaw audio to a .au file”


  1. toanhoi

    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);
    out.write(header);



css.php