sndhdrDetermine 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(),其中包含五个属性:(filetypeframeratenchannelsnframessampwidth)。The value for type indicates the data type and will be one of the strings 'aifc', 'aiff', 'au', 'hcom', 'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'. type的值表示数据类型,将是字符串'aifc''aiff''au''hcom''sndr''sndt''voc''wav''8svx''sb''ub''ul'之一。The sampling_rate will be either the actual value or 0 if unknown or difficult to decode. sampling_rate将是实际值,如果未知或难以解码,则为0Similarly, channels will be either the number of channels or 0 if it cannot be determined or if the value is difficult to decode. 类似地,如果无法确定或值难以解码,则channels将为信道数或0The value for frames will be either the number of frames or -1. frames的值将是帧数或-1The last item in the tuple, bits_per_sample, will either be the sample size in bits or 'A' for A-LAW or 'U' for u-LAW.元组中的最后一项bits_per_sample将是以位为单位的样本大小,A-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 None is returned.如果成功,则返回如上所述的namedtuple,否则返回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.结果从元组更改为命名元组。