开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.7.4
/
Doc
/
library
/
sunau.rst
python3.7.4
/
Doc
/
library
/
sunau.rst
sunau.rst 7.25 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月17日 13:49 +08:00 . git init

:mod:`sunau` --- Read and write Sun AU files

.. module:: sunau
 :synopsis: Provide an interface to the Sun AU sound format.

.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>

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


The :mod:`sunau` module provides a convenient interface to the Sun AU sound format. Note that this module is interface-compatible with the modules :mod:`aifc` and :mod:`wave`.

An audio file consists of a header followed by the data. The fields of the header are:

Field Contents
magic word The four bytes .snd.
header size Size of the header, including info, in bytes.
data size Physical size of the data, in bytes.
encoding Indicates how the audio samples are encoded.
sample rate The sampling rate.
# of channels The number of channels in the samples.
info ASCII string giving a description of the audio file (padded with null bytes).

Apart from the info field, all header fields are 4 bytes in size. They are all 32-bit unsigned integers encoded in big-endian byte order.

The :mod:`sunau` module defines the following functions:

.. function:: open(file, mode)

 If *file* is a string, open the file by that name, otherwise treat it as a
 seekable file-like object. *mode* can be any of

 ``'r'``
 Read only mode.

 ``'w'``
 Write only mode.

 Note that it does not allow read/write files.

 A *mode* of ``'r'`` returns an :class:`AU_read` object, while a *mode* of ``'w'``
 or ``'wb'`` returns an :class:`AU_write` object.


.. function:: openfp(file, mode)

 A synonym for :func:`.open`, maintained for backwards compatibility.

 .. deprecated-removed:: 3.7 3.9


The :mod:`sunau` module defines the following exception:

.. exception:: Error

 An error raised when something is impossible because of Sun AU specs or
 implementation deficiency.


The :mod:`sunau` module defines the following data items:

.. data:: AUDIO_FILE_MAGIC

 An integer every valid Sun AU file begins with, stored in big-endian form. This
 is the string ``.snd`` interpreted as an integer.


.. data:: AUDIO_FILE_ENCODING_MULAW_8
 AUDIO_FILE_ENCODING_LINEAR_8
 AUDIO_FILE_ENCODING_LINEAR_16
 AUDIO_FILE_ENCODING_LINEAR_24
 AUDIO_FILE_ENCODING_LINEAR_32
 AUDIO_FILE_ENCODING_ALAW_8

 Values of the encoding field from the AU header which are supported by this
 module.


.. data:: AUDIO_FILE_ENCODING_FLOAT
 AUDIO_FILE_ENCODING_DOUBLE
 AUDIO_FILE_ENCODING_ADPCM_G721
 AUDIO_FILE_ENCODING_ADPCM_G722
 AUDIO_FILE_ENCODING_ADPCM_G723_3
 AUDIO_FILE_ENCODING_ADPCM_G723_5

 Additional known values of the encoding field from the AU header, but which are
 not supported by this module.


AU_read Objects

AU_read objects, as returned by :func:`.open` above, have the following methods:

.. method:: AU_read.close()

 Close the stream, and make the instance unusable. (This is called automatically
 on deletion.)


.. method:: AU_read.getnchannels()

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


.. method:: AU_read.getsampwidth()

 Returns sample width in bytes.


.. method:: AU_read.getframerate()

 Returns sampling frequency.


.. method:: AU_read.getnframes()

 Returns number of audio frames.


.. method:: AU_read.getcomptype()

 Returns compression type. Supported compression types are ``'ULAW'``, ``'ALAW'``
 and ``'NONE'``.


.. method:: AU_read.getcompname()

 Human-readable version of :meth:`getcomptype`. The supported types have the
 respective names ``'CCITT G.711 u-law'``, ``'CCITT G.711 A-law'`` and ``'not
 compressed'``.


.. method:: AU_read.getparams()

 Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
 framerate, nframes, comptype, compname)``, equivalent to output of the
 :meth:`get\*` methods.


.. method:: AU_read.readframes(n)

 Reads and returns at most *n* frames of audio, as a :class:`bytes` object. The data
 will be returned in linear format. If the original data is in u-LAW format, it
 will be converted.


.. method:: AU_read.rewind()

 Rewind the file pointer to the beginning of the audio stream.

The following two methods define a term "position" which is compatible between them, and is otherwise implementation dependent.

.. method:: AU_read.setpos(pos)

 Set the file pointer to the specified position. Only values returned from
 :meth:`tell` should be used for *pos*.


.. method:: AU_read.tell()

 Return current file pointer position. Note that the returned value has nothing
 to do with the actual position in the file.

The following two functions are defined for compatibility with the :mod:`aifc`, and don't do anything interesting.

.. method:: AU_read.getmarkers()

 Returns ``None``.


.. method:: AU_read.getmark(id)

 Raise an error.


AU_write Objects

AU_write objects, as returned by :func:`.open` above, have the following methods:

.. method:: AU_write.setnchannels(n)

 Set the number of channels.


.. method:: AU_write.setsampwidth(n)

 Set the sample width (in bytes.)

 .. versionchanged:: 3.4
 Added support for 24-bit samples.


.. method:: AU_write.setframerate(n)

 Set the frame rate.


.. method:: AU_write.setnframes(n)

 Set the number of frames. This can be later changed, when and if more frames
 are written.


.. method:: AU_write.setcomptype(type, name)

 Set the compression type and description. Only ``'NONE'`` and ``'ULAW'`` are
 supported on output.


.. method:: AU_write.setparams(tuple)

 The *tuple* should be ``(nchannels, sampwidth, framerate, nframes, comptype,
 compname)``, with values valid for the :meth:`set\*` methods. Set all
 parameters.


.. method:: AU_write.tell()

 Return current position in the file, with the same disclaimer for the
 :meth:`AU_read.tell` and :meth:`AU_read.setpos` methods.


.. method:: AU_write.writeframesraw(data)

 Write audio frames, without correcting *nframes*.

 .. versionchanged:: 3.4
 Any :term:`bytes-like object` is now accepted.


.. method:: AU_write.writeframes(data)

 Write audio frames and make sure *nframes* is correct.

 .. versionchanged:: 3.4
 Any :term:`bytes-like object` is now accepted.


.. method:: AU_write.close()

 Make sure *nframes* is correct, and close the file.

 This method is called upon deletion.

Note that it is invalid to set any parameters after calling :meth:`writeframes` or :meth:`writeframesraw`.

Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.7.4.git
git@gitee.com:python_sourcecode/python3.7.4.git
python_sourcecode
python3.7.4
python3.7.4
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /