source: trunk/essentials/dev-lang/python/Doc/lib/libaifc.tex@ 3226

Last change on this file since 3226 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 7.4 KB
Line 
1\section{\module{aifc} ---
2 Read and write AIFF and AIFC files}
3
4\declaremodule{standard}{aifc}
5\modulesynopsis{Read and write audio files in AIFF or AIFC format.}
6
7
8This module provides support for reading and writing AIFF and AIFF-C
9files. AIFF is Audio Interchange File Format, a format for storing
10digital audio samples in a file. AIFF-C is a newer version of the
11format that includes the ability to compress the audio data.
12\index{Audio Interchange File Format}
13\index{AIFF}
14\index{AIFF-C}
15
16\strong{Caveat:} Some operations may only work under IRIX; these will
17raise \exception{ImportError} when attempting to import the
18\module{cl} module, which is only available on IRIX.
19
20Audio files have a number of parameters that describe the audio data.
21The sampling rate or frame rate is the number of times per second the
22sound is sampled. The number of channels indicate if the audio is
23mono, stereo, or quadro. Each frame consists of one sample per
24channel. The sample size is the size in bytes of each sample. Thus a
25frame consists of \var{nchannels}*\var{samplesize} bytes, and a
26second's worth of audio consists of
27\var{nchannels}*\var{samplesize}*\var{framerate} bytes.
28
29For example, CD quality audio has a sample size of two bytes (16
30bits), uses two channels (stereo) and has a frame rate of 44,100
31frames/second. This gives a frame size of 4 bytes (2*2), and a
32second's worth occupies 2*2*44100 bytes (176,400 bytes).
33
34Module \module{aifc} defines the following function:
35
36\begin{funcdesc}{open}{file\optional{, mode}}
37Open an AIFF or AIFF-C file and return an object instance with
38methods that are described below. The argument \var{file} is either a
39string naming a file or a file object. \var{mode} must be \code{'r'}
40or \code{'rb'} when the file must be opened for reading, or \code{'w'}
41or \code{'wb'} when the file must be opened for writing. If omitted,
42\code{\var{file}.mode} is used if it exists, otherwise \code{'rb'} is
43used. When used for writing, the file object should be seekable,
44unless you know ahead of time how many samples you are going to write
45in total and use \method{writeframesraw()} and \method{setnframes()}.
46\end{funcdesc}
47
48Objects returned by \function{open()} when a file is opened for
49reading have the following methods:
50
51\begin{methoddesc}[aifc]{getnchannels}{}
52Return the number of audio channels (1 for mono, 2 for stereo).
53\end{methoddesc}
54
55\begin{methoddesc}[aifc]{getsampwidth}{}
56Return the size in bytes of individual samples.
57\end{methoddesc}
58
59\begin{methoddesc}[aifc]{getframerate}{}
60Return the sampling rate (number of audio frames per second).
61\end{methoddesc}
62
63\begin{methoddesc}[aifc]{getnframes}{}
64Return the number of audio frames in the file.
65\end{methoddesc}
66
67\begin{methoddesc}[aifc]{getcomptype}{}
68Return a four-character string describing the type of compression used
69in the audio file. For AIFF files, the returned value is
70\code{'NONE'}.
71\end{methoddesc}
72
73\begin{methoddesc}[aifc]{getcompname}{}
74Return a human-readable description of the type of compression used in
75the audio file. For AIFF files, the returned value is \code{'not
76compressed'}.
77\end{methoddesc}
78
79\begin{methoddesc}[aifc]{getparams}{}
80Return a tuple consisting of all of the above values in the above
81order.