I want to generate a 24-bit WAV-format audio file using Python 2.7 from an array of floating point values between -1 and 1. I can\'t use scipy.io.wavfile.write because it on
You should try scikits.audiolab:
import numpy as np
from scikits.audiolab import Sndfile, Format
sig = np.array([0, 1, 0, -1, 0], dtype=np.float32)
f = Sndfile('test_pcm24.wav', 'w', Format('wav', 'pcm24'), 1, 44100)
f.write_frames(sig)
f.close() # use contextlib.closing in real code
And to read it again:
f = Sndfile('test_pcm24.wav')
sig = f.read_frames(f.nframes, dtype=np.float32)
f.close() # use contextlib.closing in real code
scikits.audiolab
uses libsndfile, so in addition to WAV files, you can also use FLAC, OGG and some more file formats.