0

I want to write a byte array to file. This is code in the web http://allmybrain.com/2012/03/16/quick-convert-raw-g711-ulaw-audio-to-a-au-file/

    import struct
    header = [ 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 ]
    o=open('out.au','wb')
    o.write ( struct.pack ( ">IIIIII", *header ) )
    raw = open('in.raw','rb').read()
    o.write(raw)
    o.close()

And I converted to java :

            byte []  header= {   0x2e736e64, 24, 0xffffffff, 1, 8000, 1 };
        FileOutputStream out = new FileOutputStream(file);
        out.write(header);

But it is error. Can you help me to fix it. Thanks

4
  • You need to specify what the error is. Commented May 5, 2012 at 11:56
  • Hint: 0x2e736e64 isn't a valid value for a byte... Commented May 5, 2012 at 11:57
  • Yes, I want to write 0x2e736e64 as byte array . I using (byte )0x2e736e64. But data is lost. ASCII is ".snd" Commented May 5, 2012 at 12:42
  • @toanhoi check stackoverflow.com/questions/3516021/… Commented May 5, 2012 at 14:31

1 Answer 1

6

In your python code your are writting 32bits integers and not 8bits bytes; You can have the same result with this code :

 byte []  header= {   0x2e, 0x73, 0x6e, 0x64,
                      0x0,  0x0,  0x0,  24,
                      -1,  -1,    -1,   -1,
                      0,   0,     0,    1,
                      0,   0,     0x1f, 0x40,
                      0,   0,     0,    1 };
 FileOutputStream out = new FileOutputStream(file);
 out.write(header);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.