Overview¶
import audio.wave
from numpy import *
df = 44100
dt = 1.0 / df
f = 440.0
T = 3.0
t = r_[0.0:T:dt]
sound = sin(2*pi*f*t)
audio.wave.write(sound, "A4.wav")
audio.wave.write¶
Wave Audio File Format Writer
Arguments¶
-
data: the audio data.The data should be either a 1-dim. numpy array or a 2-dim numpy array with a dimension of 1 (mono) or 2 (stereo) along the first axis.
-
output: a bitstream, filename, file object orNone(default).The object where the data is written in the WAVE format. An empty bitstream is created if no output is specified.
-
df: an integer, the sample rate (default:44100). -
scale: the scaling policy:None,TrueorFalse.This argument determines the linear transformation that scales
databefore it is rounded and clipped the to 16-bit integer range. The following table displays what value is mapped to2**15givenscaleand the type ofdata.-
scale = None:2**15is mapped to1.0 -
scale = True:amax(abs(data))is mapped to1.0 -
scale = False:2**15is mapped to2**15
scalescaling (float) scaling (integer) None1.0to2**152**15to2**15Trueamax(abs(data))to2**15amax(abs(data))to2**15False2**15to2**152**15to2**15Advanced scaling policies can be specified:
-
if
scaleis a number,datais multiplied by this number before the conversion to 16-bit integers. For example, for an array of floats, thescale = Nonepolicy could be implemented by settingscale = 2**15. -
if
scaleis a function, it is given thedataargument and should return a scale number. For example, the policyscale = Trueis equivalent to the selection of the scaling function defined byscale(data) = 2**15 / amax(data).
-
Returns¶
stream: an output stream if no output was specified,Noneotherwise.
See Also¶
audio.wave.read,bitstream.Bitstream.
audio.wave.read¶
Wave Audio File Format Reader
Arguments¶
-
input: the source of the WAVE data: a filename, file or a bitstream. -
scale: the scaling policy:None(the default),TrueorFalse.This argument determines the linear transformation that scales the array of 16-bit signed integers stored in
inputbefore it is returned. The following table displays the scaling that corresponds to three standard policies:scalescaling None2**15to1.0Trueamax(abs(data))to1.0False2**15to2**15Advanced scaling policies can be specified:
-
if
scaleis a number, it is used as a multiplier on the 16-bit
integer data. For example,scale = Nonecorresponds toscale = 1.0 / float(2**15)andscale = Falsetoscale = 1. -
if
scaleis a function, it is given thedataargument and should return a scale multiplier. For example, the settingscale = Trueis a shortcut for the function defined byscale(data) = 1.0 / amax(abs(data)).
-
-
returns: a string of comma-separated variable names. Whenreturnsis a single variable name, without a trailing comma, the value with this name is returned ; otherwise the named value(s) is (are) returned as a tuple.
Returns¶
The set of returned values is selected by the returns argument among:
-
data: the audio data, as a 2-dim numpy array with a dimension of 1 (mono) or 2 (stereo) along the first axe. Its data type depends on the scaling policy. -
df: the sampling rate, an integer.
See Also¶
audio.wave.write,bitstream.BitStream.