Package echonest :: Module audio :: Class AudioData
[hide private]
[frames] | no frames]

Class AudioData

source code


Handles audio data transparently. A smart audio container with accessors that include:

sampleRate
samples per second
numChannels
number of channels
data
a numpy.array
Instance Methods [hide private]
 
__init__(self, filename=None, ndarray=None, shape=None, sampleRate=None, numChannels=None)
Given an input ndarray, import the sample values and shape (if none is specified) of the input numpy.array.
source code
call graph 
 
__getitem__(self, index)
Fetches a frame or slice.
source code
call graph 
 
getslice(self, index)
Help __getitem__ return a new AudioData for a given slice
source code
call graph 
 
getsample(self, index)
Help __getitem__ return a frame (all channels for a given sample index)
source code
 
__add__(self, as2)
Returns a new AudioData from the concatenation of the two arguments.
source code
 
append(self, as2)
Appends the input to the end of this AudioData.
source code
call graph 
 
__len__(self) source code
 
encode(self, filename)
Output an MP3 or WAVE file according to the filename's extension.
source code
call graph 
 
encode_mp3(self, mp3_path)
Help encode() write out an MP3 file via LAME.
source code
call graph 
 
encode_wav(self, filename=None)
Help encode() write out a WAVE file.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename=None, ndarray=None, shape=None, sampleRate=None, numChannels=None)
(Constructor)

source code 
call graph 

Given an input ndarray, import the sample values and shape (if none is specified) of the input numpy.array.

Given a filename (and no input ndarray), load the MP3, WAVE or AIFF file into the data, auto-detecting the file extension, sample rate, and number of channels.

Parameters:
  • filename - a path to an audio file for loading its sample data into the AudioData.data
  • ndarray - a numpy.array instance with sample data
  • shape - a tuple of array dimensions
  • sampleRate - sample rate, in Hz
  • numChannels - number of channels
Overrides: object.__init__

__getitem__(self, index)
(Indexing operator)

source code 
call graph 
Fetches a frame or slice. Returns an individual frame (if the index is a time offset float or an integer sample number) or a slice if the index is an AudioQuantum (or quacks like one).

encode(self, filename)

source code 
call graph 
Output an MP3 or WAVE file according to the filename's extension. If no appropriate extension is given, then force an MP3 output.