99--------------
1010
1111The :mod: `!wave ` module provides a convenient interface to the Waveform Audio
12- "WAVE" (or "WAV") file format. Only uncompressed PCM encoded wave files are
13- supported.
12+ "WAVE" (or "WAV") file format.
13+
14+ The module supports uncompressed PCM and IEEE floating-point WAV formats.
1415
1516.. versionchanged :: 3.12
1617
1718 Support for ``WAVE_FORMAT_EXTENSIBLE `` headers was added, provided that the
1819 extended format is ``KSDATAFORMAT_SUBTYPE_PCM ``.
1920
21+ .. versionchanged :: next
22+
23+ Support for reading and writing ``WAVE_FORMAT_IEEE_FLOAT `` files was added.
24+
2025The :mod: `!wave ` module defines the following function and exception:
2126
2227
@@ -60,6 +65,21 @@ The :mod:`!wave` module defines the following function and exception:
6065 specification or hits an implementation deficiency.
6166
6267
68+ .. data :: WAVE_FORMAT_PCM
69+
70+ Format code for uncompressed PCM audio.
71+
72+
73+ .. data :: WAVE_FORMAT_IEEE_FLOAT
74+
75+ Format code for IEEE floating-point audio.
76+
77+
78+ .. data :: WAVE_FORMAT_EXTENSIBLE
79+
80+ Format code for WAVE extensible headers.
81+
82+
6383.. _wave-read-objects :
6484
6585Wave_read Objects
@@ -98,6 +118,14 @@ Wave_read Objects
98118 Returns number of audio frames.
99119
100120
121+ .. method :: getformat()
122+
123+ Returns the frame format code.
124+
125+ This is one of :data: `WAVE_FORMAT_PCM `,
126+ :data: `WAVE_FORMAT_IEEE_FLOAT `, or :data: `WAVE_FORMAT_EXTENSIBLE `.
127+
128+
101129 .. method :: getcomptype()
102130
103131 Returns compression type (``'NONE' `` is the only supported type).
@@ -112,8 +140,8 @@ Wave_read Objects
112140 .. method :: getparams()
113141
114142 Returns a :func: `~collections.namedtuple ` ``(nchannels, sampwidth,
115- framerate, nframes, comptype, compname) ``, equivalent to output of the
116- ``get*() `` methods.
143+ framerate, nframes, comptype, compname) ``, equivalent to output
144+ of the ``get*() `` methods.
117145
118146
119147 .. method :: readframes(n)
@@ -190,6 +218,9 @@ Wave_write Objects
190218
191219 Set the sample width to *n * bytes.
192220
221+ For :data: `WAVE_FORMAT_IEEE_FLOAT `, only 4-byte (32-bit) and
222+ 8-byte (64-bit) sample widths are supported.
223+
193224
194225 .. method :: getsampwidth()
195226
@@ -238,11 +269,32 @@ Wave_write Objects
238269 Return the human-readable compression type name.
239270
240271
272+ .. method :: setformat(format)
273+
274+ Set the frame format code.
275+
276+ Supported values are :data: `WAVE_FORMAT_PCM ` and
277+ :data: `WAVE_FORMAT_IEEE_FLOAT `.
278+
279+ When setting :data: `WAVE_FORMAT_IEEE_FLOAT `, the sample width must be
280+ 4 or 8 bytes.
281+
282+
283+ .. method :: getformat()
284+
285+ Return the current frame format code.
286+
287+
241288 .. method :: setparams(tuple)
242289
243- The *tuple * should be ``(nchannels, sampwidth, framerate, nframes, comptype,
244- compname) ``, with values valid for the ``set*() `` methods. Sets all
245- parameters.
290+ The *tuple * should be
291+ ``(nchannels, sampwidth, framerate, nframes, comptype, compname, format) ``,
292+ with values valid for the ``set*() `` methods. Sets all parameters.
293+
294+ For backwards compatibility, a 6-item tuple without *format * is also
295+ accepted and defaults to :data: `WAVE_FORMAT_PCM `.
296+
297+ For ``format=WAVE_FORMAT_IEEE_FLOAT ``, *sampwidth * must be 4 or 8.
246298
247299
248300 .. method :: getparams()
@@ -279,3 +331,6 @@ Wave_write Objects
279331 Note that it is invalid to set any parameters after calling :meth: `writeframes `
280332 or :meth: `writeframesraw `, and any attempt to do so will raise
281333 :exc: `wave.Error `.
334+
335+ For :data: `WAVE_FORMAT_IEEE_FLOAT ` output, a ``fact `` chunk is written as
336+ required by the WAVE specification for non-PCM formats.
0 commit comments