创新互联Python教程:sndhdr—-推测声音文件的类型

sndhdr —- 推测声音文件的类型

源代码 Lib/sndhdr.py

从版本 3.11 开始标记为过时,将在版本 3.13 中移除。: sndhdr 模块已被弃用(请参阅 PEP 594 了解详情及其替代品)。


sndhdr 提供了企图猜测文件中的声音数据类型的功能函数。当这些函数可以推测出存储在文件中的声音数据的类型是,它们返回一个 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 也会返回实际值或者在无法推测或者难以解码时返回 0frames 则是实际值或 -1。 元组的最后一项, bits_per_sample 将会为比特表示的 sample 大小或者 A-LAW 时为 'A', u-LAW 时为 'U'

sndhdr.what(filename)

使用 whathdr() 推测存储在 filename 文件中的声音数据的类型。如果成功,返回上述的命名元组,否则返回 None

在 3.5 版更改: 将结果从元组改为命名元组。

sndhdr.whathdr(filename)

基于文件头推测存储在文件中的声音数据类型。文件名由 filename 给出。这个函数在成功时返回上述命名元组,或者在失败时返回 None

在 3.5 版更改: 将结果从元组改为命名元组。

The following sound header types are recognized, as listed below with the return value from whathdr(): and what():

Value

Sound header format

‘aifc’

Compressed Audio Interchange Files

‘aiff’

Audio Interchange Files

‘au’

Au Files

‘hcom’

HCOM Files

‘sndt’

Sndtool Sound Files

‘voc’

Creative Labs Audio Files

‘wav’

Waveform Audio File Format Files

‘8svx’

8-Bit Sampled Voice Files

‘sb’

Signed Byte Audio Data Files

‘ub’

UB Files

‘ul’

uLAW Audio Files

sndhdr.tests

A list of functions performing the individual tests. Each function takes two arguments: the byte-stream and an open file-like object. When what() is called with a byte-stream, the file-like object will be None.

The test function should return a string describing the image type if the test succeeded, or None if it failed.

Example:

 
 
 
 
  1. >>> import sndhdr
  2. >>> imghdr.what('bass.wav')
  3. 'wav'
  4. >>> imghdr.whathdr('bass.wav')
  5. 'wav'

分享名称:创新互联Python教程:sndhdr—-推测声音文件的类型
文章分享:http://www.csdahua.cn/qtweb/news48/429448.html

网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网