Recommendations welcome on how to slice a .wav1 file into time-delimited segments using a Python library.
1 The actual file type isn’t really that material, I’m sure I’ll be able to convert between different types if needed.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would suggest looking at the data structure for a given file, and ‘cutting’ the data at an appropriate point along the line so no frames are chopped off early.
This would mean looking at the frequency of the recording and the bit rate, and using that to get the size (in bits) of each frame. Then you can take segments of audio without cutting individual frame data.
Have a look at this SO posting. It suggests treating your audio as a binary read string. As it’s a string you can basically copy, cut and move the string as you want to a new output file.
Check this one out: http://docs.python.org/library/binascii.html
Also worth looking at: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
Either that or just keep it as binary and use byte arrays. Need to think about the header file and what happens to that, although each format is different. MP3 is easy to keep the header as it is interleaved amongst the data:
http://en.wikipedia.org/wiki/Mp3#File_structure
Ok, a bunch of stuff.
FINALLY: One you’ll no doubt have seen already: http://sourceforge.net/projects/audiotools/
Updated….
Use the
bits_per_sample()method in the audio tools link from sourceforge.net—
Returns the number of bits-per-sample in this audio file as a positive integer.Then divide your audio into a byte array using that info and some of the info from above. You can then at least reconstruct accurately some RAW audio data.
You can take the length of the file in bits and divide it by 16. You can then use a method divide the array according to time in milliseconds. It sounds complicated but it’s really rudimentary maths.