speechbrain.utils.callchains module

Chaining together callables, if some require relative lengths

Summary

Classes:

LengthsCapableChain

Chain together callables.

Functions:

lengths_arg_exists

Returns True if func takes lengths keyword argument.

Reference

speechbrain.utils.callchains.lengths_arg_exists(func)[source]

Returns True if func takes lengths keyword argument.

Parameters:

func (callable) – The function, method, or other callable to search for the lengths arg.

class speechbrain.utils.callchains.LengthsCapableChain(*funcs)[source]

Bases: object

Chain together callables. Can handle relative lengths.

This is a more light-weight version of speechbrain.nnet.containers.LengthsCapableSequential

Parameters:

*funcs (list, optional) – Any number of functions or other callables, given in order of execution.

Returns:

The input as processed by each function. If no functions were given, simply returns the input.

Return type:

Any

__call__(x, lengths=None)[source]

Run the chain of callables on the given input

Parameters:
  • x (Any) – The main input

  • lengths (Any) – The lengths argument which will be conditionally passed to any functions in the chain that take a ‘lengths’ argument. In SpeechBrain the convention is to use relative lengths.

Note

By convention, if a callable in the chain returns multiple outputs (returns a tuple), only the first output is passed to the next callable in the chain.

append(func)[source]

Add a function to the chain