Standard Library `aifc` Redistribution
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
- breaking The original `aifc` module was removed from the Python standard library starting with Python 3.13. Direct `import aifc` will fail in Python 3.13+ environments unless `standard-aifc` (or an equivalent) is installed.
- deprecated The `aifc` module was officially deprecated in the Python standard library from version 3.11, signaling its eventual removal. While `standard-aifc` provides a means to continue using it, it should be considered a legacy component.
- gotcha Avoid `from aifc import *`. The `aifc` module defines its own `open()` function which, if imported unqualified, will shadow the built-in `open()` function, leading to unexpected behavior and errors when trying to open non-AIFF files.
- gotcha The `standard-aifc` package is a compatibility redistribution and is explicitly stated by its maintainers to not accept new features or anything beyond minimal compatibility work. It is not actively developed for new functionalities or extensive bug fixes.
- gotcha The `aifc.open()` function is strict about file modes, only accepting `'r'`, `'rb'`, `'w'`, or `'wb'`. Using other modes (e.g., `'a'`) will result in an `aifc.Error`. Additionally, the module might not correctly parse AIFF/AIFF-C files with uncommon or malformed compression type headers (e.g., 'raw ' instead of 'NONE').
Install
-
pip install standard-aifc
Imports
- aifc
import aifc
- open
aifc.open('file.aiff', 'rb')
Quickstart
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}")