1. mirror
  2. cpython


cpython / Doc / library / aifc.rst

:mod:`aifc` --- Read and write AIFF and AIFC files

Source code: :source:`Lib/aifc.py`

This module provides support for reading and writing AIFF and AIFF-C files. AIFF is Audio Interchange File Format, a format for storing digital audio samples in a file. AIFF-C is a newer version of the format that includes the ability to compress the audio data.


Some operations may only work under IRIX; these will raise :exc:`ImportError` when attempting to import the :mod:`cl` module, which is only available on IRIX.

Audio files have a number of parameters that describe the audio data. The sampling rate or frame rate is the number of times per second the sound is sampled. The number of channels indicate if the audio is mono, stereo, or quadro. Each frame consists of one sample per channel. The sample size is the size in bytes of each sample. Thus a frame consists of nchannels**samplesize* bytes, and a second's worth of audio consists of nchannels**samplesize***framerate* bytes.

For example, CD quality audio has a sample size of two bytes (16 bits), uses two channels (stereo) and has a frame rate of 44,100 frames/second. This gives a frame size of 4 bytes (2*2), and a second's worth occupies 2*2*44100 bytes (176,400 bytes).

Module :mod:`aifc` defines the following function:

Objects returned by :func:`.open` when a file is opened for reading have the following methods:

Objects returned by :func:`.open` when a file is opened for writing have all the above methods, except for :meth:`readframes` and :meth:`setpos`. In addition the following methods exist. The :meth:`get\*` methods can only be called after the corresponding :meth:`set\*` methods have been called. Before the first :meth:`writeframes` or :meth:`writeframesraw`, all parameters except for the number of frames must be filled in.