Standard Library SunAU Redistribution
The `standard-sunau` library is a redistribution of the `sunau` module, which was formerly part of the Python standard library. It provides an interface for reading and writing Sun AU audio files (`.au` format). The original `sunau` module was deprecated in Python 3.11 and completely removed in Python 3.13 as part of PEP 594. This package allows legacy projects or those needing Sun AU file support to continue using the module by installing it as a PyPI dependency. It is currently at version 3.13.0 and is part of the 'dead battery' project, focused on redistributing removed standard library modules with minimal maintenance.
Warnings
- breaking The `sunau` module was officially removed from the Python standard library in Python 3.13 (after being deprecated in 3.11) as per PEP 594. Applications relying on `sunau` in Python 3.13 or newer must explicitly install `standard-sunau` via pip.
- gotcha This `standard-sunau` package is a redistribution of a module removed from the standard library, primarily intended for compatibility. It is not actively developed for new features or significant improvements. For advanced or modern audio processing needs, consider more actively maintained Python audio libraries.
- gotcha The `sunau.open()` function does not support simultaneous read/write ('r+' or 'w+') modes. You must open the file explicitly in either read ('r' or 'rb') or write ('w' or 'wb') mode.
- gotcha The `sunau` module's `getmarkers()` method always returns `None`, and `getmark()` raises an error. These methods are present for compatibility with the `aifc` module but are not implemented for Sun AU files.
Install
-
pip install standard-sunau
Imports
- sunau
import sunau
Quickstart
import sunau
import io
# Create a dummy in-memory AU file for demonstration
output_buffer = io.BytesIO()
with sunau.open(output_buffer, 'wb') as w:
w.setnchannels(1)
w.setsampwidth(2) # 2 bytes = 16-bit
w.setframerate(8000)
# Write 100 frames of silence (two zero bytes per frame)
w.writeframes(b'\x00\x00' * 100)
# Rewind the buffer to read from the beginning
output_buffer.seek(0)
# Now read the dummy AU file
with sunau.open(output_buffer, 'rb') as r:
print(f"Number of channels: {r.getnchannels()}")
print(f"Sample width (bytes): {r.getsampwidth()}")
print(f"Frame rate (Hz): {r.getframerate()}")
print(f"Number of frames: {r.getnframes()}")
print(f"Compression type: {r.getcomptype()}")
print(f"Compression name: {r.getcompname()}")
# Read some frames (e.g., 50 frames)
frames = r.readframes(50)
print(f"Read {len(frames) // r.getsampwidth()} frames of audio data.")