Decoder

File Decoder

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

Bases: timeside.core.decoder.Decoder

File Decoder based on Gstreamer

Parameters
uristr

uri of the media

startfloat, optional

start time of the segment in seconds

durationfloat, optional

duration of the segment in seconds

stackboolean, optional

keep decoded data in the stack

sha1boolean, 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(self)[source]

Return a user-friendly encoding string

format(self)[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(self)[source]

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

mime_type(self)[source]

Return the mime type corresponding to this decoded format

output_blocksize = 8192
pipeline = None
process(self)[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(self)[source]

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

resolution(self)[source]

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

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

Allocate internal resources and reset state, so that this processor is ready for a new run.

The channels, samplerate and/or blocksize and/or totalframes arguments may be required by processors which accept input. An error will occur if any of these arguments is passed to an output-only processor such as a decoder.

stop(self)[source]
totalframes(self)[source]

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

static version()[source]

Return the version of the processor

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
samplesnumpy 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

startfloat

start time of the segment in seconds

durationfloat

duration of the segment in seconds

format(self)[source]

Return a user-friendly file format string

get_frames(self)[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(self)[source]

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

output_blocksize = 8192
process(self)[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(self)[source]

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

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

Allocate internal resources and reset state, so that this processor is ready for a new run.

The channels, samplerate and/or blocksize and/or totalframes arguments may be required by processors which accept input. An error will occur if any of these arguments is passed to an output-only processor such as a decoder.

static version()[source]

Return the version of the processor

Live Decoder

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

Bases: object

Live source Decoder based on Gstreamer capturing audio from alsasrc

Construct a new LiveDecoder capturing audio from alsasrc

Parameters
num_buffersint, optional

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

input_srcstr, 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() # doctest: +SKIP # >>> # Show the audio as captured by the decoder # >>> import matplotlib.pyplot as plt # doctest: +SKIP # >>> plt.plot(a.results[‘waveform_analyzer’].time, # doctest: +SKIP # a.results[‘waveform_analyzer’].data) # doctest: +SKIP # >>> plt.show() # doctest: +SKIP

static id()[source]

@interfacedoc

process(self)[source]

@interfacedoc

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

@interfacedoc