blob: 8535193e73f32c92216c5c833f019e08856ff032 [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
13The :mod:`sndhdr` provides utility functions which attempt to determine the type
14of sound data which is in a file. When these functions are able to determine
15what type of sound data is stored in a file, they return a tuple ``(type,
16sampling_rate, channels, frames, bits_per_sample)``. The value for *type*
17indicates the data type and will be one of the strings ``'aifc'``, ``'aiff'``,
18``'au'``, ``'hcom'``, ``'sndr'``, ``'sndt'``, ``'voc'``, ``'wav'``, ``'8svx'``,
19``'sb'``, ``'ub'``, or ``'ul'``. The *sampling_rate* will be either the actual
20value or ``0`` if unknown or difficult to decode. Similarly, *channels* will be
21either the number of channels or ``0`` if it cannot be determined or if the
22value is difficult to decode. The value for *frames* will be either the number
23of frames or ``-1``. The last item in the tuple, *bits_per_sample*, will either
24be the sample size in bits or ``'A'`` for A-LAW or ``'U'`` for u-LAW.
25
26
27.. function:: what(filename)
28
29 Determines the type of sound data stored in the file *filename* using
30 :func:`whathdr`. If it succeeds, returns a tuple as described above, otherwise
31 ``None`` is returned.
32
33
34.. function:: whathdr(filename)
35
36 Determines the type of sound data stored in a file based on the file header.
37 The name of the file is given by *filename*. This function returns a tuple as
38 described above on success, or ``None``.
39