I want to create 32bit float WAV files in Python (2.x). While \"standard\" WAV files usually use int, many professional audio applications process (and save) audio data as float
Here's my contribution... includes arbitrary word size and arbitrary number of channels. I've taken the liberty of changing float32_wav_file to include a file save for testing. Note that the multichannel data portion of the file structure interleaved. That loop could be be greatly pythonized I'm sure.
# see http://stackoverflow.com/questions/15576798/create-32bit-float-wav-file-in-python
# see... http://blog.theroyweb.com/extracting-wav-file-header-information-using-a-python-script
import struct
def float32_wav_file(file_name, sample_array, sample_rate):
(M,N)=sample_array.shape
#print "len sample_array=(%d,%d)" % (M,N)
byte_count = M * N * 4 # (len(sample_array)) * 4 # 32-bit floats
wav_file = ""
# write the header
wav_file += struct.pack('