💾 Archived View for tris.fyi › pydoc › sndhdr captured on 2023-04-26 at 13:31:59. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Back to module index

Go to module by name

sndhdr

Routines to help recognizing sound files.

Function whathdr() recognizes various types of sound file headers.
It understands almost all headers that SOX can decode.

The return tuple contains the following items, in this order:
- file type (as SOX understands it)
- sampling rate (0 if unknown or hard to decode)
- number of channels (0 if unknown or hard to decode)
- number of frames in the file (-1 if unknown or hard to decode)
- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW

If the file doesn't have a recognizable type, it returns None.
If the file can't be opened, OSError is raised.

To compute the total time, divide the number of frames by the
sampling rate (a frame contains a sample for each channel).

Function what() calls whathdr().  (It used to also use some
heuristics for raw data, but this doesn't work very well.)

Finally, the function test() is a simple main program that calls
what() for all files mentioned on the argument list.  For directory
arguments it calls what() for all files in that directory.  Default
argument is "." (testing all files in the current directory).  The
option -r tells it to recurse down directories found inside
explicitly given directories.

Classes

SndHeaders

SndHeaders(filetype, framerate, nchannels, nframes, sampwidth)
count(self, value, /)

  Return number of occurrences of value.
index(self, value, start=0, stop=9223372036854775807, /)

  Return first index of value.

  Raises ValueError if the value is not present.
filetype = _tuplegetter(0, "The value for type indicates the data type\nand will be one of the strings 'aifc', 'aiff', 'au','hcom',\n'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'.")
  The value for type indicates the data type
  and will be one of the strings 'aifc', 'aiff', 'au','hcom',
  'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'.
framerate = _tuplegetter(1, 'The sampling_rate will be either the actual\nvalue or 0 if unknown or difficult to decode.')
  The sampling_rate will be either the actual
  value or 0 if unknown or difficult to decode.
nchannels = _tuplegetter(2, 'The number of channels or 0 if it cannot be\ndetermined or if the value is difficult to decode.')
  The number of channels or 0 if it cannot be
  determined or if the value is difficult to decode.
nframes = _tuplegetter(3, 'The value for frames will be either the number\nof frames or -1.')
  The value for frames will be either the number
  of frames or -1.
sampwidth = _tuplegetter(4, "Either the sample size in bits or\n'A' for A-LAW or 'U' for u-LAW.")
  Either the sample size in bits or
  'A' for A-LAW or 'U' for u-LAW.

Functions

get_long_be

get_long_be(b)

get_long_le

get_long_le(b)

get_short_be

get_short_be(b)

get_short_le

get_short_le(b)

namedtuple

namedtuple(typename, field_names, *, rename=False, defaults=None, module=None)

  Returns a new subclass of tuple with named fields.

      >>> Point = namedtuple('Point', ['x', 'y'])
      >>> Point.__doc__                   # docstring for the new class
      'Point(x, y)'
      >>> p = Point(11, y=22)             # instantiate with positional args or keywords
      >>> p[0] + p[1]                     # indexable like a plain tuple
      33
      >>> x, y = p                        # unpack like a regular tuple
      >>> x, y
      (11, 22)
      >>> p.x + p.y                       # fields also accessible by name
      33
      >>> d = p._asdict()                 # convert to a dictionary
      >>> d['x']
      11
      >>> Point(**d)                      # convert from a dictionary
      Point(x=11, y=22)
      >>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
      Point(x=100, y=22)

    

test

test()

test_8svx

test_8svx(h, f)

test_aifc

test_aifc(h, f)

test_au

test_au(h, f)

test_hcom

test_hcom(h, f)

test_sndr

test_sndr(h, f)

test_sndt

test_sndt(h, f)

test_voc

test_voc(h, f)

test_wav

test_wav(h, f)

testall

testall(list, recursive, toplevel)

what

what(filename)

  Guess the type of a sound file.

whathdr

whathdr(filename)

  Recognize sound headers.

Other members

tests = [<function test_aifc at 0x7f75e0c3f6d0>, <function test_au at 0x7f75e0c3f9a0>, <function test_hcom at 0x7f75e0c3fd00>, <function test_voc at 0x7f75e0c3fd90>, <function test_wav at 0x7f75e0c3fe20>, <function test_8svx at 0x7f75e0c3feb0>, <function test_sndt at 0x7f75e0c3ff40>, <function test_sndr at 0x7f75e0c48040>]