If file is a string, open the file by that name, otherwise treat it as a
file-like object. mode can be:

'rb'

Read only mode.

'wb'

Write only mode.

Note that it does not allow read/write WAV files.

A mode of 'rb' returns a Wave_read object, while a mode of
'wb' returns a Wave_write object. If mode is omitted and a
file-like object is passed as file, file.mode is used as the default
value for mode.

If you pass in a file-like object, the wave object will not close it when its
close() method is called; it is the caller’s responsibility to close
the file object.

For seekable output streams, the wave header will automatically be updated
to reflect the number of frames actually written. For unseekable streams, the
nframes value must be accurate when the first frame data is written. An
accurate nframes value can be achieved either by calling
setnframes() or setparams() with the number
of frames that will be written before close() is called and
then using writeframesraw() to write the frame data, or by
calling writeframes() with all of the frame data to be
written. In the latter case writeframes() will calculate
the number of frames in the data and set nframes accordingly before writing
the frame data.

Wave_write objects, as returned by open(), have the following methods:

Make sure nframes is correct, and close the file if it was opened by
wave. This method is called upon object collection. It will raise
an exception if the output stream is not seekable and nframes does not
match the number of frames actually written.

Write audio frames and make sure nframes is correct. It will raise an
error if the output stream is not seekable and the total number of frames
that have been written after data has been written does not match the
previously set value for nframes.