1:mod:`sndhdr` --- Determine type of sound file 2============================================== 3 4.. module:: sndhdr 5 :synopsis: Determine type of a sound file. 6 7.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> 8.. Based on comments in the module source file. 9 10**Source code:** :source:`Lib/sndhdr.py` 11 12.. index:: 13 single: A-LAW 14 single: u-LAW 15 16-------------- 17 18The :mod:`sndhdr` provides utility functions which attempt to determine the type 19of sound data which is in a file. When these functions are able to determine 20what type of sound data is stored in a file, they return a 21:func:`~collections.namedtuple`, containing five attributes: (``filetype``, 22``framerate``, ``nchannels``, ``nframes``, ``sampwidth``). The value for *type* 23indicates the data type and will be one of the strings ``'aifc'``, ``'aiff'``, 24``'au'``, ``'hcom'``, ``'sndr'``, ``'sndt'``, ``'voc'``, ``'wav'``, ``'8svx'``, 25``'sb'``, ``'ub'``, or ``'ul'``. The *sampling_rate* will be either the actual 26value or ``0`` if unknown or difficult to decode. Similarly, *channels* will be 27either the number of channels or ``0`` if it cannot be determined or if the 28value is difficult to decode. The value for *frames* will be either the number 29of frames or ``-1``. The last item in the tuple, *bits_per_sample*, will either 30be the sample size in bits or ``'A'`` for A-LAW or ``'U'`` for u-LAW. 31 32 33.. function:: what(filename) 34 35 Determines the type of sound data stored in the file *filename* using 36 :func:`whathdr`. If it succeeds, returns a namedtuple as described above, otherwise 37 ``None`` is returned. 38 39 .. versionchanged:: 3.5 40 Result changed from a tuple to a namedtuple. 41 42 43.. function:: whathdr(filename) 44 45 Determines the type of sound data stored in a file based on the file header. 46 The name of the file is given by *filename*. This function returns a namedtuple as 47 described above on success, or ``None``. 48 49 .. versionchanged:: 3.5 50 Result changed from a tuple to a namedtuple. 51 52