0

I'm working on a little audio project and part of it requires using wave files and flac files. Im trying to figure out how to read the metadata in each and how to add tags manually. I'm having trouble figuring out how to read the bytes as they are.

I have been referencing this page and a couple others to see the full format of a Wave file however for some wave files I get some discrepancies. I want to be able to see the hexadecimal bytes in order to see what differences are occurring.

Using simply open('fname', 'rb') and read, only returns the bytes as strings. Using struct.unpack has worked for some wave files however it is limited to printing as strings, ints, or shorts and I can't see exactly what is going wrong when I use it. Is there any other way I can read this file in hex?

Thanks

1
  • What do you mean by "read this file in hex"? Commented Aug 18, 2015 at 9:47

1 Answer 1

1

I assume that you just want to display the content of a binary file in hexadecimal. First, you do not need to use Python for that, as some editors to it natively, for example vim.

Now assuming you have a string that you got by reading a file, you can easily change it to a list of hexadecimal values:

with open('fname', 'rb') as fd:      # open the file
    data = rd.read(16)               # read 16 bytes from it
    h = [ hex(ord(b)) for b in data] # convert the bytes to their hex value
    print (h)                        # prints a list of hexadecimal codes of the read bytes
Sign up to request clarification or add additional context in comments.

1 Comment

Do you also know an idea for the reverse purpose? I have audio data in bytes format and I would like to use them. All I know is that they represent FLAC format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.