- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine type of sound file using Python (sndhdr)
The sndhdr module in Python's standard library provides utility functions that read the type of sound data which is in a file. The functions return a namedtuple(), containing five attributes
filetype | string representing 'aifc', 'aiff', 'au', 'hcom', 'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'. |
framerate | the sampling_rate will be either the actual value or 0 if unknown or difficult to decode. |
nchannels | number of channels or 0 if it cannot be determined or if the value is difficult to decode |
nframes | either the number of frames or -1. |
sampwidth | bits_per_sample, will either be the sample size in bits or 'A' for A-LAW or 'U' for u-LAW. |
functions in sndhdr module
sndhdr.what()
This function determines the type of sound data stored in the file filename using whathdr(). If it succeeds, returns a namedtuple as described above, otherwise None is returned.
sndhdr.whathdr()
This function determines the type of sound data stored in a file based on the file header. This function returns a namedtuple as described above on success, or None.
Examples
>>> import sndhdr >>> sndhdr.whathdr("sample.wav") SndHeaders(filetype = 'wav', framerate = 44100, nchannels = 1, nframes = 99999, sampwidth = 16) >>> sndhdr.whathdr("sample.aiff") SndHeaders(filetype = 'aiff', framerate = 8000, nchannels = 1, nframes = 271200, sampwidth = 16) >>> sndhdr.whathdr("sample.au") SndHeaders(filetype = 'au', framerate = 8000, nchannels = 1, nframes = 103397.0, sampwidth = 'U')
- Related Articles
- Determine the type of an image using Python (imghdr)
- Determine the type of an image in Python?
- How to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)?
- Determine common type following standard coercion rules in Python
- What is sound? How can we determine the pitch in a sound?
- How to find the mime type of a file in Python?
- File Searching using Python
- How to create a duplicate file of an existing file using Python?
- Program to determine color of a chessboard square using Python
- How to Find Hash of File using Python?
- Determine whether the given object represents a scalar data-type in Python
- Determine if the type in the first argument is a subclass of second in Python
- How to Copy Odd Lines of Text File to Another File using Python
- How to Determine Last Friday’s Date using Python?
- The netrc file processing using Python

Advertisements