Standard Library `aifc` Redistribution

3.13.0 · maintenance · verified Sat Apr 11

standard-aifc is a redistribution of the `aifc` module, which was part of the Python standard library until its removal in Python 3.13. It provides functionality for reading and writing AIFF (Audio Interchange File Format) and AIFF-C files. Maintained by the `python-deadlib` project, its purpose is to make these removed 'dead batteries' available via PyPI for continued compatibility. The current version is 3.13.0, representing a re-packaging effort rather than active feature development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple AIFF file with dummy audio data and then read its audio parameters using the `aifc` module.

import aifc
import os

output_file = "test_audio.aiff"

# Parameters for a dummy AIFF file
nchannels = 1  # Mono
sampwidth = 2  # 2 bytes per sample (16-bit)
framerate = 44100  # 44.1 kHz
nframes = 44100 * 1  # 1 second of audio

try:
    # 1. Create a dummy AIFF file
    with aifc.open(output_file, 'wb') as af:
        af.setnchannels(nchannels)
        af.setsampwidth(sampwidth)
        af.setframerate(framerate)
        af.setnframes(nframes)
        # Write dummy silent frames
        dummy_frame = b'\x00' * (nchannels * sampwidth)
        af.writeframes(dummy_frame * nframes)

    print(f"Created dummy AIFF file: {output_file}")

    # 2. Read parameters from the created AIFF file
    with aifc.open(output_file, 'rb') as af_read:
        print(f"\nReading from {output_file}:")
        print(f"  Channels: {af_read.getnchannels()}")
        print(f"  Sample width (bytes): {af_read.getsampwidth()}")
        print(f"  Frame rate (Hz): {af_read.getframerate()}")
        print(f"  Number of frames: {af_read.getnframes()}")
        print(f"  Compression type: {af_read.getcomptype().decode('utf-8')}")

except aifc.Error as e:
    print(f"An aifc error occurred: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(output_file):
        os.remove(output_file)
        print(f"Cleaned up {output_file}")

view raw JSON →