blob: f36df68703474524877fa9a7c961fdf05b6925be [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.
6.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
Christian Heimes5b5e81c2007-12-31 16:14:33 +00007.. Based on comments in the module source file.
Georg Brandl116aa622007-08-15 14:28:22 +00008
9.. index::
10 single: A-LAW
11 single: u-LAW
12
Raymond Hettinger469271d2011-01-27 20:38:46 +000013**Source code:** :source:`Lib/sndhdr.py`
14
15--------------
16
Georg Brandl116aa622007-08-15 14:28:22 +000017The :mod:`sndhdr` provides utility functions which attempt to determine the type
18of sound data which is in a file. When these functions are able to determine
19what type of sound data is stored in a file, they return a tuple ``(type,
20sampling_rate, channels, frames, bits_per_sample)``. The value for *type*
21indicates the data type and will be one of the strings ``'aifc'``, ``'aiff'``,
22``'au'``, ``'hcom'``, ``'sndr'``, ``'sndt'``, ``'voc'``, ``'wav'``, ``'8svx'``,
23``'sb'``, ``'ub'``, or ``'ul'``. The *sampling_rate* will be either the actual
24value or ``0`` if unknown or difficult to decode. Similarly, *channels* will be
25either the number of channels or ``0`` if it cannot be determined or if the
26value is difficult to decode. The value for *frames* will be either the number
27of frames or ``-1``. The last item in the tuple, *bits_per_sample*, will either
28be the sample size in bits or ``'A'`` for A-LAW or ``'U'`` for u-LAW.
29
30
31.. function:: what(filename)
32
33 Determines the type of sound data stored in the file *filename* using
34 :func:`whathdr`. If it succeeds, returns a tuple as described above, otherwise
35 ``None`` is returned.
36
37
38.. function:: whathdr(filename)
39
40 Determines the type of sound data stored in a file based on the file header.
41 The name of the file is given by *filename*. This function returns a tuple as
42 described above on success, or ``None``.
43