
Rewind the file pointer to the beginning of the audio stream.įollowing code reads some of the parameters of WAV file.

Reads and returns at most n frames of audio, as a bytes object.

Returns a namedtuple() (nchannels, sampwidth, framerate, nframes, comptype, compname), equivalent to output of the get*() methods. Returns compression type ('NONE' is the only supported type). Returns number of audio channels (1 for mono, 2 for stereo). Obj.close() Wave_read object methods close()Ĭlose the stream if it was opened by wave module. Write audio frames and make sure they are correct.įollowing code creates a WAV file with random short integer bytes of 99999 seconds duration. At the moment, only compression type NONE is supported, meaning no compression.Īccepts parameter tuple (nchannels, sampwidth, framerate, nframes, comptype, compname) Set the compression type and description. Wave_write object has following methods close() obj = wave.open('sound.wav','wb')Ī mode of 'rb' returns a Wave_read object, while a mode of 'wb' returns a Wave_write object. The mode can be 'wb' for writing audio data or 'rb' for reading. The function needs two parameters - first the file name and second the mode.

This function opens a file to read/write audio data. The file is opened in 'write' or read mode just as with built-in open() function, but with open() function in wave module wave.open() The functions in this module can write audio data in raw format to a file like object and read the attributes of a WAV file. The wave module in Python's standard library is an easy interface to the audio WAV format.
