Skip to content

Commit 4ce4379

Browse files
committed
wave: add documentation on IEEE support, format API
1 parent 58339ae commit 4ce4379

2 files changed

Lines changed: 56 additions & 7 deletions

File tree

Doc/library/wave.rst

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
--------------
1010

1111
The :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:: 3.15
22+
23+
Support for reading and writing ``WAVE_FORMAT_IEEE_FLOAT`` files was added.
24+
2025
The :mod:`!wave` module defines the following function and exception:
2126

2227

@@ -98,6 +103,14 @@ Wave_read Objects
98103
Returns number of audio frames.
99104

100105

106+
.. method:: getformat()
107+
108+
Returns the frame format code.
109+
110+
This is one of ``WAVE_FORMAT_PCM``, ``WAVE_FORMAT_IEEE_FLOAT``, or
111+
``WAVE_FORMAT_EXTENSIBLE``.
112+
113+
101114
.. method:: getcomptype()
102115

103116
Returns compression type (``'NONE'`` is the only supported type).
@@ -112,8 +125,8 @@ Wave_read Objects
112125
.. method:: getparams()
113126

114127
Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
115-
framerate, nframes, comptype, compname)``, equivalent to output of the
116-
``get*()`` methods.
128+
framerate, nframes, comptype, compname, format)``, equivalent to output
129+
of the ``get*()`` methods.
117130

118131

119132
.. method:: readframes(n)
@@ -238,11 +251,27 @@ Wave_write Objects
238251
Return the human-readable compression type name.
239252

240253

254+
.. method:: setformat(format)
255+
256+
Set the frame format code.
257+
258+
Supported values are ``WAVE_FORMAT_PCM`` and
259+
``WAVE_FORMAT_IEEE_FLOAT``.
260+
261+
262+
.. method:: getformat()
263+
264+
Return the current frame format code.
265+
266+
241267
.. method:: setparams(tuple)
242268

243-
The *tuple* should be ``(nchannels, sampwidth, framerate, nframes, comptype,
244-
compname)``, with values valid for the ``set*()`` methods. Sets all
245-
parameters.
269+
The *tuple* should be
270+
``(nchannels, sampwidth, framerate, nframes, comptype, compname, format)``,
271+
with values valid for the ``set*()`` methods. Sets all parameters.
272+
273+
For backwards compatibility, a 6-item tuple without *format* is also
274+
accepted and defaults to ``WAVE_FORMAT_PCM``.
246275

247276

248277
.. method:: getparams()
@@ -279,3 +308,6 @@ Wave_write Objects
279308
Note that it is invalid to set any parameters after calling :meth:`writeframes`
280309
or :meth:`writeframesraw`, and any attempt to do so will raise
281310
:exc:`wave.Error`.
311+
312+
For ``WAVE_FORMAT_IEEE_FLOAT`` output, a ``fact`` chunk is written as
313+
required by the WAVE specification for non-PCM formats.

Doc/whatsnew/3.15.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,23 @@ typing
15181518
wave
15191519
----
15201520

1521+
* Added support for IEEE floating-point WAVE audio
1522+
(``WAVE_FORMAT_IEEE_FLOAT``) in :mod:`wave`.
1523+
1524+
* Added :meth:`wave.Wave_read.getformat`, :meth:`wave.Wave_write.getformat`,
1525+
and :meth:`wave.Wave_write.setformat` for explicit frame format handling.
1526+
1527+
* :meth:`wave.Wave_read.getparams` and :meth:`wave.Wave_write.getparams` now
1528+
include ``format`` as the seventh field in the returned named tuple.
1529+
:meth:`wave.Wave_write.setparams` accepts both 7-item tuples including
1530+
``format`` and 6-item tuples for backwards compatibility (defaulting to
1531+
``WAVE_FORMAT_PCM``).
1532+
1533+
* ``WAVE_FORMAT_IEEE_FLOAT`` output now includes a ``fact`` chunk,
1534+
as required for non-PCM WAVE formats.
1535+
1536+
(Contributed by Lionel Koenig and Michiel W. Beijen in :gh:`60729`.)
1537+
15211538
* Removed the ``getmark()``, ``setmark()`` and ``getmarkers()`` methods
15221539
of the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes,
15231540
which were deprecated since Python 3.13.

0 commit comments

Comments
 (0)