sndhdr
— Determine type of sound file确定声音文件的类型¶
Source code: Lib/sndhdr.py
Deprecated since version 3.11: The sndhdr
module is deprecated (see PEP 594 for details).sndhdr
模块已弃用(有关详细信息,请参阅PEP 594)。
The sndhdr
provides utility functions which attempt to determine the type of sound data which is in a file. sndhdr
提供了实用程序函数,这些函数试图确定文件中声音数据的类型。When these functions are able to determine what type of sound data is stored in a file, they return a 当这些函数能够确定文件中存储的声音数据类型时,它们会返回一个namedtuple()
, containing five attributes: (filetype
, framerate
, nchannels
, nframes
, sampwidth
). namedtuple()
,其中包含五个属性:(filetype、framerate、nchannels、nframes、sampwidth)。The value for type indicates the data type and will be one of the strings type的值表示数据类型,将是字符串'aifc'
, 'aiff'
, 'au'
, 'hcom'
, 'sndr'
, 'sndt'
, 'voc'
, 'wav'
, '8svx'
, 'sb'
, 'ub'
, or 'ul'
. 'aifc'
、'aiff'
、'au'
、'hcom'
、'sndr'
、'sndt'
、'voc'
、'wav'
、'8svx'
、'sb'
、'ub'
或'ul'
之一。The sampling_rate will be either the actual value or sampling_rate将是实际值,如果未知或难以解码,则为0
if unknown or difficult to decode. 0
。Similarly, channels will be either the number of channels or 类似地,如果无法确定或值难以解码,则channels将为信道数或0
if it cannot be determined or if the value is difficult to decode. 0
。The value for frames will be either the number of frames or frames的值将是帧数或-1
. -1
。The last item in the tuple, bits_per_sample, will either be the sample size in bits or 元组中的最后一项bits_per_sample将是以位为单位的样本大小,A-LAW为'A'
for A-LAW or 'U'
for u-LAW.'A'
,U-LAW为为'U'
。
-
sndhdr.
what
(filename)¶ Determines the type of sound data stored in the file filename using使用whathdr()
.whathdr()
确定存储在filename中的声音数据的类型。If it succeeds, returns a namedtuple as described above, otherwise如果成功,则返回如上所述的namedtuple,否则返回None
is returned.None
。Changed in version 3.5:版本3.5中更改:Result changed from a tuple to a namedtuple.结果从元组更改为命名元组。
-
sndhdr.
whathdr
(filename)¶ Determines the type of sound data stored in a file based on the file header.根据文件头确定存储在文件中的声音数据的类型。The name of the file is given by filename.文件名由filename提供。This function returns a namedtuple as described above on success, or此函数在成功或None
.None
时返回如上所述的namedtuple。Changed in version 3.5:版本3.5中更改:Result changed from a tuple to a namedtuple.结果从元组更改为命名元组。