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 only supports 16 or 32 bits. The documentation for Python's own wave module doesn't specify what format of data it takes.
So is it possible to do this in Python?
Another option is available in
wavio (also on PyPI: https://pypi.python.org/pypi/wavio), a small module I created as a work-around to the problem of scipy not yet supporting 24 bit WAV files. The file
wavio.py contains the function
write, which writes a numpy array to a WAV file. To write a 24-bit file, use the argument
sampwidth=3. The only dependency of
wavio is numpy;
wavio uses the standard library
wave to deal with the WAV file format.
In : import numpy as np In : import wavio In : rate = 22050 # samples per second In : T = 3 # sample duration (seconds) In : f = 440.0 # sound frequency (Hz) In : t = np.linspace(0, T, T*rate, endpoint=False) In : sig = np.sin(2 * np.pi * f * t) In : wavio.write("sine24.wav", sig, rate, sampwidth=3)