💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](ossaudiodev.xhtml "ossaudiodev --- Access to OSS-compatible audio devices") | - [上一页](imghdr.xhtml "imghdr --- 推测图像类型") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [多媒体服务](mm.xhtml) » - $('.inline-search').show(0); | # [`sndhdr`](#module-sndhdr "sndhdr: Determine type of a sound file.") --- 推测声音文件的类型 **源代码** [Lib/sndhdr.py](https://github.com/python/cpython/tree/3.7/Lib/sndhdr.py) \[https://github.com/python/cpython/tree/3.7/Lib/sndhdr.py\] - - - - - - [`sndhdr`](#module-sndhdr "sndhdr: Determine type of a sound file.") 提供了企图猜测文件中的声音数据类型的功能函数。当这些函数可以推测出存储在文件中的声音数据的类型是,它们返回一个 [`collections.namedtuple()`](collections.xhtml#collections.namedtuple "collections.namedtuple"),包含了五种属性:(`filetype`, `framerate`, `nchannels`, `nframes`, `sampwidth`)。这些 *type* 的值表示数据的类型,会是以下字符串之一: `'aifc'`, `'aiff'`, `'au'`, `'hcom'`, `'sndr'`, `'sndt'`, `'voc'`, `'wav'`, `'8svx'`, `'sb'`, `'ub'`, or `'ul'` 。 *sampling\_rate* 可能是实际值或者当未知或者难以解码时的 `0`。类似的, *channels* 也会返回实际值或者在无法推测或者难以解码时返回 `0`。 *frames* 则是实际值或 `-1`。 元组的最后一项, *bits\_per\_sample* 将会为比特表示的 sample 大小或者 A-LAW 时为 `'A'`, u-LAW 时为 `'U'`。 `sndhdr.``what`(*filename*)使用 [`whathdr()`](#sndhdr.whathdr "sndhdr.whathdr") 推测存储在 *filename* 文件中的声音数据的类型。如果成功,返回上述的命名元组,否则返回 `None`。 在 3.5 版更改: 将结果从元组改为命名元组。 `sndhdr.``whathdr`(*filename*)基于文件头推测存储在文件中的声音数据类型。文件名由 *filename* 给出。这个函数在成功时返回上述命名元组,或者在失败时返回 `None`。 在 3.5 版更改: 将结果从元组改为命名元组。 ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](ossaudiodev.xhtml "ossaudiodev --- Access to OSS-compatible audio devices") | - [上一页](imghdr.xhtml "imghdr --- 推测图像类型") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [多媒体服务](mm.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。