brain_pipe.preprocessing.stimulus.audio.spectrogram.LibrosaMelSpectrogram¶
- class LibrosaMelSpectrogram(stimulus_data_key='stimulus_data', stimulus_sr_key='stimulus_sr', output_key='spectrogram_data', output_sr_key='spectrogram_sr', power_factor=1.0, sort_fn=None, librosa_kwargs={}, **kwargs)¶
Bases:
PipelineStep
Calculates mel spectrogram using librosa.
Code was based on the ICASSP 2023 auditory EEG challenge: https://github.com/exporl/auditory-eeg-challenge-2023-code/blob/main/ task1_match_mismatch/util/mel_spectrogram.py
- __init__(stimulus_data_key='stimulus_data', stimulus_sr_key='stimulus_sr', output_key='spectrogram_data', output_sr_key='spectrogram_sr', power_factor=1.0, sort_fn=None, librosa_kwargs={}, **kwargs)¶
Calculate the mel spectrogram of a raw speech file.
- Parameters:
stimulus_data_key (str) – The key in the data dictionary that contains the stimulus data
stimulus_sr_key (str) – The key in the data dictionary that contains the stimulus sampling rate
output_key (str) – The key in the data dictionary to store the spectrogram
power_factor (float) – The power factor for each sample
sort_fn (Callable) – A function to sort the kwargs for librosa.feature.melspectrogram when when parsing the kwargs. This is useful when the callables are used that depend on other kwargs.
librosa_kwargs (Union[Dict[str, Any], Callable]) – Keyword arguments to pass to librosa.feature.melspectrogram. Can also be a callable that takes in data_dict and returns a dict of kwargs.
kwargs (dict) – Additional keyword arguments for the PipelineStep
Methods
__init__
([stimulus_data_key, ...])Calculate the mel spectrogram of a raw speech file.
parse_dict_keys
(key[, name, ...])Parse a key or a sequence of keys.
parse_librosa_kwargs
(data_dict)Parse kwargs for Librosa's melspectrogram function.
- parse_dict_keys(key: str | Sequence[str] | Mapping[str, str], name='key', require_ordered_dict=False) OrderedDict[str, str] ¶
Parse a key or a sequence of keys.
- Parameters:
- Returns:
A mapping of input keys to output keys.
- Return type:
- Raises:
TypeError – If the key is not a string, a sequence of strings or a mapping of strings. If the key is a mapping but require_ordered_dict is True and the mapping is not an OrderedDict.