sndhdr
--- 推測聲音文件的類型?
源代碼 Lib/sndhdr.py
Deprecated since version 3.11, will be removed in version 3.13: The sndhdr
module is deprecated
(see PEP 594 for details and alternatives).
sndhdr
提供了企圖猜測文件中的聲音數(shù)據(jù)類型的功能函數(shù)。當這些函數(shù)可以推測出存儲在文件中的聲音數(shù)據(jù)的類型是,它們返回一個 collections.namedtuple()
,包含了五種屬性:(filetype
, framerate
, nchannels
, nframes
, sampwidth
)。這些 type 的值表示數(shù)據(jù)的類型,會是以下字符串之一: '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()
推測存儲在 filename 文件中的聲音數(shù)據(jù)的類型。如果成功,返回上述的命名元組,否則返回None
。在 3.5 版更改: 將結(jié)果從元組改為命名元組。
- sndhdr.whathdr(filename)?
基于文件頭推測存儲在文件中的聲音數(shù)據(jù)類型。文件名由 filename 給出。這個函數(shù)在成功時返回上述命名元組,或者在失敗時返回
None
。在 3.5 版更改: 將結(jié)果從元組改為命名元組。