The sndhdr module

This sndhdr module, shown in Example 9-2, can be used to identify different audio file formats and extract basic information about a file's contents.

If successful, the what function returns a 5-tuple, containing the filetype, the sampling rate, the number of channels, the number of frames in the file (1 means unknown), and the number of bits per sample.

Example 9-2. Using the sndhdr Module

File: sndhdr-example-1.py

import sndhdr

result = sndhdr.what("samples/sample.wav")

if result:
 print "file format:", result
else:
 print "cannot identify file"

file format: ('wav', 44100, 1, -1, 16)

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net