上一话题

被取代模块

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 被取代模块
  9. aifc — 读写 AIFF (音频交换文件格式) 和 AIFC 文件

aifc — 读写 AIFF (音频交换文件格式) 和 AIFC 文件 ¶

源代码: Lib/aifc.py

Deprecated since version 3.11, will be removed in version 3.13: The aifc 模块被弃用 (见 PEP 594 了解细节)。


此模块提供读写 AIFF 和 AIFF-C 文件的支持。AIFF 是音频交换文件格式,用于在文件中存储数字音频样本的格式。AIFF-C 是该格式的更新版本 (包括音频数据压缩能力)。

音频文件有很多音频数据描述参数。采样率 (或帧率) 是声音的每秒采样次数。通道数指示音频是单声道、立体声还是四声道。每帧由每通道一样本组成。样本大小是每样本的字节大小。因此,帧的组成是 nchannels * samplesize 字节,和一秒钟音频的组成是 nchannels * samplesize * framerate 字节。

例如,CD 品质音频拥有 2 字节 (16 位) 大小样本,使用 2 通道 (立体声),且拥有 44,100 帧/秒帧速率。这给出了 4 字节 (2*2) 的帧大小,且一秒钟占用 2*2*44100 字节 (176,400 字节)。

模块 aifc 定义了以下函数:

aifc. open ( file , mode = None ) ¶

打开 AIFF (音频交换文件格式) 或 AIFF-C 文件并返回具有下述方法的对象实例。自变量 file 是命名文件的字符串或 文件对象 . mode 必须为 'r' or 'rb' 当必须打开文件以供读取时,或 'w' or 'wb' 当必须打开文件以供写入时。若省略, file.mode 会被使用若存在,否则 'rb' 会被使用。当用于写入时,文件对象应该可寻址,除非提前知道总共要写入多少个样本和使用 writeframesraw() and setnframes() 。 open() 函数可以用于 with 语句。当 with 阻塞完成, close() 方法被调用。

3.4 版改变: 支持 with 语句被添加。

对象返回通过 open() 当打开文件以供读取时,拥有下列方法:

aifc. getnchannels ( ) ¶

Return the number of audio channels (1 for mono, 2 for stereo).

aifc. getsampwidth ( ) ¶

Return the size in bytes of individual samples.

aifc. getframerate ( ) ¶

Return the sampling rate (number of audio frames per second).

aifc. getnframes ( ) ¶

Return the number of audio frames in the file.

aifc. getcomptype ( ) ¶

Return a bytes array of length 4 describing the type of compression used in the audio file. For AIFF files, the returned value is b'NONE' .

aifc. getcompname ( ) ¶

Return a bytes array convertible to a human-readable description of the type of compression used in the audio file. For AIFF files, the returned value is b'not compressed' .

aifc. getparams ( ) ¶

返回 namedtuple() (nchannels, sampwidth, framerate, nframes, comptype, compname) ,相当于输出对于 get*() 方法。

aifc. getmarkers ( ) ¶

Return a list of markers in the audio file. A marker consists of a tuple of three elements. The first is the mark ID (an integer), the second is the mark position in frames from the beginning of the data (an integer), the third is the name of the mark (a string).

aifc. getmark ( id ) ¶

Return the tuple as described in getmarkers() for the mark with the given id .

aifc. readframes ( nframes ) ¶

Read and return the next nframes frames from the audio file. The returned data is a string containing for each frame the uncompressed samples of all channels.

aifc. rewind ( ) ¶

Rewind the read pointer. The next readframes() will start from the beginning.

aifc. setpos ( pos ) ¶

寻址到指定帧号。

aifc. tell ( ) ¶

返回当前帧号。

aifc. close ( ) ¶

Close the AIFF file. After calling this method, the object can no longer be used.

对象返回通过 open() when a file is opened for writing have all the above methods, except for readframes() and setpos() . In addition the following methods exist. The get*() methods can only be called after the corresponding set*() methods have been called. Before the first writeframes() or writeframesraw() , all parameters except for the number of frames must be filled in.

aifc. aiff ( ) ¶

Create an AIFF file. The default is that an AIFF-C file is created, unless the name of the file ends in '.aiff' in which case the default is an AIFF file.

aifc. aifc ( ) ¶

Create an AIFF-C file. The default is that an AIFF-C file is created, unless the name of the file ends in '.aiff' in which case the default is an AIFF file.

aifc. setnchannels ( nchannels ) ¶

Specify the number of channels in the audio file.

aifc. setsampwidth ( width ) ¶

Specify the size in bytes of audio samples.

aifc. setframerate ( rate ) ¶

Specify the sampling frequency in frames per second.

aifc. setnframes ( nframes ) ¶

Specify the number of frames that are to be written to the audio file. If this parameter is not set, or not set correctly, the file needs to support seeking.

aifc. setcomptype ( type , name ) ¶

Specify the compression type. If not specified, the audio data will not be compressed. In AIFF files, compression is not possible. The name parameter should be a human-readable description of the compression type as a bytes array, the type parameter should be a bytes array of length 4. Currently the following compression types are supported: b'NONE' , b'ULAW' , b'ALAW' , b'G722' .

aifc. setparams ( nchannels , sampwidth , framerate , comptype , compname ) ¶

Set all the above parameters at once. The argument is a tuple consisting of the various parameters. This means that it is possible to use the result of a getparams() call as argument to setparams() .

aifc. setmark ( id , pos , name ) ¶

Add a mark with the given id (larger than 0), and the given name at the given position. This method can be called at any time before close() .

aifc. tell ( )

Return the current write position in the output file. Useful in combination with setmark() .

aifc. writeframes ( data ) ¶

Write data to the output file. This method can only be called after the audio file parameters have been set.

3.4 版改变: 任何 像字节对象 现接受。

aifc. writeframesraw ( data ) ¶

像 writeframes() , except that the header of the audio file is not updated.

3.4 版改变: 任何 像字节对象 现接受。

aifc. close ( )

Close the AIFF file. The header of the file is updated to reflect the actual size of the audio data. After calling this method, the object can no longer be used.

上一话题

被取代模块

下一话题

audioop — 操纵原生音频数据

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 被取代模块
  9. aifc — 读写 AIFF (音频交换文件格式) 和 AIFC 文件

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1