Skip to main content

A package to read Broadcast Wave files

Project description

SVSound

This is Python package for reading Broadcast Wave Files in various formats along with metadata written by several recording devices. The content in this module was forked from Mark Sprague's collection of sound recording and analysis modules and intended for use by his students. This package is available to everyone under the GPL 3.0 license.

Versions

  • 0.0.1 - initial release
  • 0.0.2 - Corrected a bug that caused the end of a wave file to be truncated.
  • 0.0.3 - Corrected a bug causing incorrect partial file read; include ID3 contents (in binary form) in info.
  • 0.0.4 - Now skips over nonstandard file chunks without producing errors.

wavefile Module

The module wavefile contains programs for reading Broadcast Wave (.wav) files. The following propriatory boadcast wave file formats are currently supported:

  • generic - generic Windows WAVE file format containing the basic infromation in the WAVE format chunk. No additional metadata is read.

  • decimus - Windows WAVE file written by the Decimus® passive acoustics monitoring system and other devices that use the SA Instrumentation DAQ card. Metadata is extracted from the filename, which includes a timestamp, into the info dictionary.

  • icListen - WAVE files written by icListen® recording devices. Metadata in the INFO chunk is read into the info dictionary.

  • zoom - WAVE files written by ZOOM® recording devices. Metadata from the bext chunk and the iXML chunk is read into the info dictionary.

Functions

read( )

info, wave = read(filename, t0, t1, wavetype, chunk_b, verbose)

Read a WAV file and return the file information and waveform data. This function includes support for single and multiple channel files encoded in linear PCM format with the following data formats (all little-endian):

  • 8 bit signed integer
  • 16 bit signed integer
  • 24 bit signed integer
  • 32 bit signed integer
  • 32 bit floating point
  • 64 bit floating point

Input parameters

filename - string with the name of the input WAV file

t0 - start time in seconds for returned data (default: 0)

t1 - end time in seconds for returned data. Value of -1 represents the end of the file. (default: -1)

wavetype - string representing the type of WAV file (default: None). Currnetly supported types are 'generic', 'decimus', 'icListen', and 'zoom'. If the value is None, the wavetype is determined using identify.

chunk_b - number of bytes for each data chunk read from the file (default: 3072)

verbose - give verbose status updates (default: False)

Output

info - dictionary with file information and metadata (if available)

wave - Numpy array with waveform data values. For a single channel file, wave is a flat, 1-D array. For a multichannel recording each channel is a row in wave, so wave[0] is the first channel, wave[1] the second channel, etc.

identify( )

wavetype = identify(file)

Identify the type of WAV file and return its type. Files that are unable to be identified are classified as generic. The wave type identification allows the extraction of proprietary metadata stored in the file and filename.

Input parameter

file - filehandle for the WAV file to be identified

Output

wavetype - string with the name of the wave file type.

wave_chunk( )

Read a WAVE file in chunks (not all at once) and return all the data. This is a back-end to the read function and is not intended for high-level use.

recorders Subpackage

The subpackage recorders contains modules with specific get_info() functions for each supported recorder type. Currently supported recorders are described in the wavefile Module introduction (above). Each get_info() function has the same input and output parameters and usage.

info = get_info(file, info)

Read the information in a generic WAV file, and return the contents. Only the standard information in the fmt chunk is included in the info dictionary.

Input Parameters

file - filehandle of an open WAV file

info - (optional) dictionary that may contain file information from other sources. Defaults to an empty dictionary.

Output

info - dictionary with information read from the file. If an info dictionary was supplied as an input parameter, entires that were not changed are also included.

Standard info dictionary keys and values returned for all file types:

"bits" - integer with the number of bits in each sample.

"block_align" - number of bytes sampled at the same time (all channels combined) in the data

"byte_per_s" - integer number of bytes per second recorded

"chan" - integer number of channels in the file

"compress" - integer Wave file compression index. Only 1 (uncompressed integer data) and 3 (uncompressed floating point data) are currently supported.

"data0" - integer byte address of the first sample in the file

"filesize" - integer size of the file in bytes

"fs" - integer sample rate in samples/second

"Nsamples" - integer number of samples in the file (in each channel)

"wavetype" - string with the name file type read.

Other keys and values in the info dictionary are recorder-specific and depend on the wavetype value.

Recorder-Specific info keys and values

Decimus

Recordings identified as Decimus recordings have info["wavetype"] set to "decimus". Otherwise, info contains only the standard info keys and values.

Generic

Recordings classified as generic have info["wavetype"] set to "generic", and info contains only the standard info keys and values.

icListen

Recordings identified as icListen recordings have info["wavetype"] set to "icListen". In addition, each key/value pair encoded in the INFO chunk in the file is added to info. See the icListen documentation for details on these parameters.

The value info["cal"] contains a float64 calibration value for the data. Multiply data samples by this value to obtain calibrated values in micropascals.

Zoom

Recordings identified as Zoom recordings have info["wavetype"] set to "zoom". The following information encoded in the bext chunk is added to info as keys and values. (See Zoom documentation for details.)

"CodingHistory" - coding history string

"desc" - recording description string

"LoudnessRange" - int16 recording loudness range value

"LoudnessValue" - int16 recording loudness value

"MaxMomentaryLoudness" - int16 recording maximum momentary loudness value

"MaxShortTermLoudness" - int16 recording maximum short term loudness value

"MaxTruePeakLevel" - int16 recording maximum maximum true peak level

"OriginationDate" - recording origination date string

"OriginationTime" - recording origination time string

"Originator" - recording originator string

"OriginatorReference" - recording originator reference string

"TimeReferenceHigh" - int32 time of high sample in recording

"TimeReferenceLow" - int32 time of low sample in recording

"UMID" - UMID string

"Version" - int16 version number

The contents in the entire iXML block are stored in info["iXML"] as a string.

Usage Example

Read data from a single-channel file and plot it vs. time.

>>> from __future__ import division
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from SVSound import wavefile
>>> info, data = wavefile.read('filename.wav')
>>> info['chan']
1
>>> times = np.arange(data.size / info['fs'])
>>> plt.plot(times, data)
...

Note that the data in a multichannel recording has rows for each channel, so data[0] is the first channel, data[1] the second channel, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svsound-0.0.4.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

svsound-0.0.4-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file svsound-0.0.4.tar.gz.

File metadata

  • Download URL: svsound-0.0.4.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200712 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.6

File hashes

Hashes for svsound-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3f0400cdba92e3d76a0ee934464ee83e392ff2c352acbebff4e1d04d048e26c7
MD5 caa22976bc3c6bb14707ca0ecad9486a
BLAKE2b-256 bbb7b28965109dfdae0ccc090ce293d228679771759a91185cd5fc397481139f

See more details on using hashes here.

File details

Details for the file svsound-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: svsound-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200712 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.6

File hashes

Hashes for svsound-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 da185d5c49181015d97f62b65f3c200a03318dbac1c9af978a389b5655759a40
MD5 fcc9976d7ca1336c5fd387dd6486d348
BLAKE2b-256 a1df919d5590b5481b5df0a8ad9961685aac6b957a6d07ade83d5afc2927bbd0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page