Decoder package

File Decoder

class timeside.plugins.decoder.file.FileDecoder(uri, start=0, duration=None, stack=False, sha1=None)[source]

Bases: timeside.core.decoder.Decoder

File Decoder based on Gstreamer

Parameters:

uri : str

uri of the media

start : float, optional

start time of the segment in seconds

duration : float, optional

duration of the segment in seconds

stack : boolean, optional

keep decoded data in the stack

sha1 : boolean, optional

compute the sha1 hash of the data

Examples

>>> import timeside
>>> from timeside.core import get_processor
>>> from timeside.core.tools.test_samples import samples
>>> audio_source = samples['sweep.wav']
>>> FileDecoder = get_processor('file_decoder')  # Get the decoder class
>>> # Use decoder with default parameters
>>> decoder = FileDecoder(uri=audio_source)
>>> analyzer = get_processor('level')()  # Pick a arbitrary analyzer
>>> pipe =(decoder | analyzer)
>>> pipe.run()  # Run the pipe for the given audio source
encoding()[source]

Return a user-friendly encoding string

format()[source]

Return a user-friendly file format string

static id()[source]

Short alphanumeric, lower-case string which uniquely identify this processor, suitable for use as an HTTP/GET argument value, in filenames, etc…

mainloopthread = None
metadata()[source]

Return the metadata embedded into the encoded stream, if any.

mime_type()[source]

Return the mime type corresponding to this decoded format

output_blocksize = 8192
pipeline = None
process(decoder)[source]

Process input frames and return a (output_frames, eod) tuple. Both input and output frames are 2D numpy arrays, where columns are channels, and containing an undetermined number of frames. eod=True means that the end-of-data has been reached.

Output-only processors (such as decoders) will raise an exception if the frames argument is not None. All processors (even encoders) return data, even if that means returning the input unchanged.

Warning: it is required to call setup() before this method.

release()[source]

Release resources owned by this processor. The processor cannot be used anymore after calling this method.

resolution()[source]

Return the sample width (8, 16, etc..) of original audio file/stream, or None if not applicable/known

setup(channels=None, samplerate=None, blocksize=None)[source]
stop()[source]
totalframes()[source]

The total number of frames that this processor will output, or None if the number is unknown.

Array Decoder

class timeside.plugins.decoder.array.ArrayDecoder(samples, samplerate=44100, start=0, duration=None)[source]

Bases: timeside.core.decoder.Decoder

Decoder taking Numpy array as input

Construct a new ArrayDecoder from an numpy array

Parameters:

samples : numpy array of dimension 1 (mono) or 2 (multichannel)

if shape = (n) or (n,1) : n samples, mono if shape = (n,m) : n samples with m channels

start : float

start time of the segment in seconds

duration : float

duration of the segment in seconds

format()[source]

Return a user-friendly file format string

get_frames()[source]

Define an iterator that will return frames at the given blocksize

static id()[source]

Short alphanumeric, lower-case string which uniquely identify this processor, suitable for use as an HTTP/GET argument value, in filenames, etc…

metadata()[source]

Return the metadata embedded into the encoded stream, if any.

output_blocksize = 8192
process()[source]

Process input frames and return a (output_frames, eod) tuple. Both input and output frames are 2D numpy arrays, where columns are channels, and containing an undetermined number of frames. eod=True means that the end-of-data has been reached.

Output-only processors (such as decoders) will raise an exception if the frames argument is not None. All processors (even encoders) return data, even if that means returning the input unchanged.

Warning: it is required to call setup() before this method.

release()[source]

Release resources owned by this processor. The processor cannot be used anymore after calling this method.

setup(channels=None, samplerate=None, blocksize=None)[source]

Live Decoder

class timeside.plugins.decoder.live.LiveDecoder(num_buffers=-1, input_src='alsasrc')[source]

Bases: timeside.plugins.decoder.file.FileDecoder

Live source Decoder based on Gstreamer capturing audio from alsasrc

Construct a new LiveDecoder capturing audio from alsasrc
Parameters:

num_buffers : int, optional

Number of buffers to output before sending End Of Stream signal (-1 = unlimited). (Allowed values: >= -1, Default value: -1)

input_src : str, optional

Gstreamer source element default to ‘alsasrc’ possible values : ‘autoaudiosrc’, ‘alsasrc’, ‘osssrc’

Examples

>>> import timeside
>>> from timeside.core import get_processor
>>> live_decoder = get_processor('live_decoder')(num_buffers=5)
>>> waveform = get_processor('waveform_analyzer')()
>>> mp3_encoder = timeside.plugins.encoder.mp3.Mp3Encoder('/tmp/test_live.mp3',
...                                               overwrite=True)
>>> pipe = (live_decoder | waveform | mp3_encoder)
>>> pipe.run()  
>>> # Show the audio as captured by the decoder
>>> import matplotlib.pyplot as plt 
>>> plt.plot(a.results['waveform_analyzer'].time, 
         a.results['waveform_analyzer'].data) 
>>> plt.show() 
static id()[source]

Short alphanumeric, lower-case string which uniquely identify this processor, suitable for use as an HTTP/GET argument value, in filenames, etc…

process()[source]

Process input frames and return a (output_frames, eod) tuple. Both input and output frames are 2D numpy arrays, where columns are channels, and containing an undetermined number of frames. eod=True means that the end-of-data has been reached.

Output-only processors (such as decoders) will raise an exception if the frames argument is not None. All processors (even encoders) return data, even if that means returning the input unchanged.

Warning: it is required to call setup() before this method.

release()[source]
setup(channels=None, samplerate=None, blocksize=None)[source]