Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

legacy dependencies #148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ currently supports:
- `Core Audio`_ on Mac OS X via `ctypes`_. (PyObjC not required.)
- `MAD`_ via the `pymad`_ bindings.
- `FFmpeg`_ or `Libav`_ via its command-line interface.
- The standard library `wave`_, `aifc`_, and `sunau`_ modules (for
uncompressed audio formats).
- The standard library `wave`_ module (for
uncompressed audio formats). Legacy formats `aifc`_ and `sunau`_ are also optionally supported, see the note below.

.. _Gstreamer: http://gstreamer.freedesktop.org/
.. _gst-python: http://gstreamer.freedesktop.org/modules/gst-python.html
Expand Down Expand Up @@ -73,6 +73,18 @@ that you have a broken installation of `FFmpeg`_. To check, try typing
FFmpeg with your OS's package manager (e.g., apt or yum) or `using Conda
<https://anaconda.org/conda-forge/ffmpeg>`_.

Legacy formats
--------------
The `aifc`_ and `sunau`_ modules were deprecated and removed from the standard
Python distribution in version 3.13.
Support for `aifc` and `sunau` formats is still available through `deadlib`_.
To install audioread with continued support for these formats, you can
use the following command::

python -m pip install audioread[legacy]

.. _deadlib: https://github.com/youknowone/python-deadlib

Version History
---------------

Expand Down
53 changes: 34 additions & 19 deletions audioread/rawread.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# included in all copies or substantial portions of the Software.

"""Uses standard-library modules to read AIFF, AIFF-C, and WAV files."""
import aifc
import audioop
import struct
import sunau
import wave
import warnings

from .exceptions import DecodeError
from .base import AudioFile
Expand Down Expand Up @@ -54,20 +53,13 @@ def byteswap(s):
class RawAudioFile(AudioFile):
"""An AIFF, WAV, or Au file that can be read by the Python standard
library modules ``wave``, ``aifc``, and ``sunau``.

On Python 3.13 and later, ``aifc`` and ``sunau`` support require
installing the ``standard-aifc`` and ``standard-sunau`` packages, respectively.
"""
def __init__(self, filename):
self._fh = open(filename, 'rb')

try:
self._file = aifc.open(self._fh)
except aifc.Error:
# Return to the beginning of the file to try the next reader.
self._fh.seek(0)
else:
self._needs_byteswap = True
self._check()
return

try:
self._file = wave.open(self._fh)
except wave.Error:
Expand All @@ -78,15 +70,38 @@ def __init__(self, filename):
self._check()
return

# The following are deprecated formats and may not be supported
try:
self._file = sunau.open(self._fh)
except sunau.Error:
self._fh.seek(0)
pass
import aifc
except ImportError:
warnings.warn("aifc module not found; AIFF files will not be supported. "
"You may need to install the standard-aifc package.")
else:
self._needs_byteswap = True
self._check()
return
try:
self._file = aifc.open(self._fh)
except aifc.Error:
# Return to the beginning of the file to try the next reader.
self._fh.seek(0)
else:
self._needs_byteswap = True
self._check()
return

try:
import sunau
except ImportError:
warnings.warn("sunau module not found; Au files will not be supported. "
"You may need to install the standard-sunau package.")
else:
try:
self._file = sunau.open(self._fh)
except sunau.Error:
self._fh.seek(0)
pass
else:
self._needs_byteswap = True
self._check()
return

# None of the three libraries could open the file.
self._fh.close()
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ authors = [
{name = "Adrian Sampson", email = "[email protected]"}
]
readme = "README.rst"
requires-python = ">=3.6"
requires-python = ">=3.8"
dependencies = [
"audioop-lts; python_version >= '3.13'"
]
dynamic = ["version", "description"]
urls.Home = "https://github.com/beetbox/audioread"
classifiers = [
Expand All @@ -19,6 +22,8 @@ classifiers = [
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'License :: OSI Approved :: MIT License',
]
license = {file = "LICENSE"}
Expand All @@ -27,3 +32,7 @@ license = {file = "LICENSE"}
test = [
"tox"
]
legacy = [
"standard-aifc; python_version >= '3.13'",
"standard-sunau; python_version >= '3.13'"
]