blob: 6bfa9a9fd210bef3fee5aaffa7c2054853d7175c [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`sndhdr` --- Determine type of sound file
2==============================================
3
4.. module:: sndhdr
5 :synopsis: Determine type of a sound file.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Georg Brandl116aa622007-08-15 14:28:22 +00007.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
Christian Heimes5b5e81c2007-12-31 16:14:33 +00008.. Based on comments in the module source file.
Georg Brandl116aa622007-08-15 14:28:22 +00009
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040010**Source code:** :source:`Lib/sndhdr.py`
11
Georg Brandl116aa622007-08-15 14:28:22 +000012.. index::
13 single: A-LAW
14 single: u-LAW
15
Raymond Hettinger469271d2011-01-27 20:38:46 +000016--------------
17
Georg Brandl116aa622007-08-15 14:28:22 +000018The :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
R David Murray4487dd02014-10-09 16:59:30 -040020what 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*
Georg Brandl116aa622007-08-15 14:28:22 +000023indicates 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
R David Murray4487dd02014-10-09 16:59:30 -040036 :func:`whathdr`. If it succeeds, returns a namedtuple as described above, otherwise
Georg Brandl116aa622007-08-15 14:28:22 +000037 ``None`` is returned.
38
R David Murray4487dd02014-10-09 16:59:30 -040039 .. versionchanged:: 3.5
40 Result changed from a tuple to a namedtuple.
41
Georg Brandl116aa622007-08-15 14:28:22 +000042
43.. function:: whathdr(filename)
44
45 Determines the type of sound data stored in a file based on the file header.
R David Murray4487dd02014-10-09 16:59:30 -040046 The name of the file is given by *filename*. This function returns a namedtuple as
Georg Brandl116aa622007-08-15 14:28:22 +000047 described above on success, or ``None``.
48
R David Murray4487dd02014-10-09 16:59:30 -040049 .. versionchanged:: 3.5
50 Result changed from a tuple to a namedtuple.
51