sndhdr — Determine type of sound file

Source code:Lib/sndhdr.py

Deprecated since version 3.11:Thesndhdr module is deprecated(seePEP 594 for details and alternatives).


Thesndhdr provides utility functions which attempt to determine the typeof sound data which is in a file. When these functions are able to determinewhat type of sound data is stored in a file, they return anamedtuple(), containing five attributes: (filetype,framerate,nchannels,nframes,sampwidth). The value fortypeindicates the data type and will be one of the strings'aifc','aiff','au','hcom','sndr','sndt','voc','wav','8svx','sb','ub', or'ul'. Thesampling_rate will be either the actualvalue or0 if unknown or difficult to decode. Similarly,channels will beeither the number of channels or0 if it cannot be determined or if thevalue is difficult to decode. The value forframes will be either the numberof frames or-1. The last item in the tuple,bits_per_sample, will eitherbe the sample size in bits or'A' for A-LAW or'U' for u-LAW.

sndhdr.what(filename)

Determines the type of sound data stored in the filefilename usingwhathdr(). If it succeeds, returns a namedtuple as described above, otherwiseNone is returned.

Changed in version 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 byfilename. This function returns a namedtuple asdescribed above on success, orNone.

Changed in version 3.5:Result changed from a tuple to a namedtuple.