speechbrain.utils.callchains module

Chaining together callables, if some require relative lengths

Summary

Classes:

LengthsCapableChain

Chain together callables.

Functions:

lengths_arg_exists

Check if func takes lengths keyword argument.

lengths_arg_name

Return the name of the relative-lengths argument of func, if any.

Reference

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

Check if func takes lengths keyword argument.

Parameters:

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

Return type:

True if func takes lengths keyword argument.

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

Return the name of the relative-lengths argument of func, if any.

Both lengths (the general SpeechBrain convention) and wav_lens (the name used by e.g. the HuggingFace integration lobes) are recognized.

Parameters:

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

Returns:

The name of the lengths argument, or None if func does not take one.

Return type:

str or None

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.

__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’ (or ‘wav_lens’) argument. In SpeechBrain the convention is to use relative lengths.

Returns:

  • The input as processed by each function. If no functions were given,

  • simply returns the input.

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