pliers.extractors.STFTAudioExtractor

class pliers.extractors.STFTAudioExtractor(frame_size=0.5, hop_size=0.1, freq_bins=5, spectrogram=False)[source]

Bases: AudioExtractor

Short-time Fourier Transform extractor.

Parameters
  • frame_size (float) – The width of the frame/window to apply an FFT to, in seconds.

  • hop_size (float) – The step size to increment the window by on each iteration, in seconds (effectively, the sampling rate).

  • freq_bins (list or int) – The set of bins or frequency bands to extract power for. If an int is passed, this is the number of bins returned, with each bin spanning an equal range of frequencies. E.g., if bins=5 and the frequency spectrum runs from 0 to 20KHz, each bin will span 4KHz. If a list is passed, each element must be a tuple or list of lower and upper frequency bounds. E.g., passing [(0, 300), (300, 3000)] would compute power in two bands, one between 0 and 300Hz, and one between 300Hz and 3KHz.

  • spectrogram (bool) – If True, plots a spectrogram of the results.

Notes: code adapted from http://stackoverflow.com/questions/2459295/invertible-stft-and-istft-in-python

__init__(frame_size=0.5, hop_size=0.1, freq_bins=5, spectrogram=False)[source]
transform(stim, *args, **kwargs)

Executes the transformation on the passed stim(s).

Parameters
  • stims (str, Stim, list) –

    One or more stimuli to process. Must be one of:

    • A string giving the path to a file that can be read in as a Stim (e.g., a .txt file, .jpg image, etc.)

    • A Stim instance of any type.

    • An iterable of stims, where each element is either a string or a Stim.

  • validation (str) –

    String specifying how validation errors should be handled. Must be one of:

    • ’strict’: Raise an exception on any validation error

    • ’warn’: Issue a warning for all validation errors

    • ’loose’: Silently ignore all validation errors

  • args – Optional positional arguments to pass onto the internal _transform call.

  • kwargs – Optional positional arguments to pass onto the internal _transform call.