Standard Library SunAU Redistribution

3.13.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to create an in-memory Sun AU audio file and then read its properties using the `sunau` module. The `sunau.open()` function is used for both writing and reading, similar to standard file I/O operations.

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.")

view raw JSON →