ertk.preprocessing.spectrogram.SpectrogramExtractorConfig

class ertk.preprocessing.spectrogram.SpectrogramExtractorConfig(kind: str = 'mel', pre_emphasis: float = 0, window_size: float = 0.025, window_shift: float = 0.01, win_length_samp: int | None = None, hop_length_samp: int | None = None, n_mels: int = 128, htk_mel: bool = False, n_fft: int = 2048, n_chroma: int = 12, clip_db: float | None = None, fmin: float = 0, fmax: float | None = 8000, power: int = 2, to_log: str | None = 'db', mel_norm: str = 'slaney')

Bases: ERTKConfig

Configuration for SpectrogramExtractor.

__init__(kind: str = 'mel', pre_emphasis: float = 0, window_size: float = 0.025, window_shift: float = 0.01, win_length_samp: int | None = None, hop_length_samp: int | None = None, n_mels: int = 128, htk_mel: bool = False, n_fft: int = 2048, n_chroma: int = 12, clip_db: float | None = None, fmin: float = 0, fmax: float | None = 8000, power: int = 2, to_log: str | None = 'db', mel_norm: str = 'slaney') None

Methods

__init__([kind, pre_emphasis, window_size, ...])

Inherited Methods

default()

Create default config.

from_config(config)

Create config object from any compatible config.

from_file(path)

Create config from YAML file and optionlly override some values.

merge_with_args(args)

Merge config with command-line arguments.

merge_with_config(config)

Merge other config into this config.

to_dictconfig()

Convert config to DictConfig.

to_file(path)

Write config to YAML file.

to_string()

Generate YAML string representation of config.

Attributes

clip_db

Whether to clip noise floor at a given level in dB below maximum.

fmax

Maximum frequency for mel bands.

fmin

Minimum frequency for mel bands.

hop_length_samp

The hop size in samples.

htk_mel

Use HTK formula for mel calculation.

kind

The kind of spectrogram to calculate.

mel_norm

Normalisation to apply to mel filters.

n_chroma

Number of chroma bands.

n_fft

Number of FFT bins.

n_mels

Number of mel bands.

power

Raise spectrogram magnitudes to this power.

pre_emphasis

Amount of pre-emphasis to apply.

to_log

Whether to convert spectrogram to logarithmic domain.

win_length_samp

The window length in samples.

window_shift

Amount window moves each frame, in seconds.

window_size

Size of window in seconds.

clip_db: float | None = None

Whether to clip noise floor at a given level in dB below maximum. Default is None which does no clipping. This is only used if to_db is True.

fmax: float | None = 8000

Maximum frequency for mel bands. Default is 8000.

fmin: float = 0

Minimum frequency for mel bands. Default is 0.

hop_length_samp: int | None = None

The hop size in samples. This overrides window_shift if given.

htk_mel: bool = False

Use HTK formula for mel calculation.

kind: str = 'mel'

The kind of spectrogram to calculate. “mel” calculates a mel spectrogram, whereas “stft” just uses linear frequency.

mel_norm: str = 'slaney'

Normalisation to apply to mel filters. Default is “slaney” as in librosa.

n_chroma: int = 12

Number of chroma bands.

n_fft: int = 2048

Number of FFT bins. Default is to use the next power of 2 greater than window_size * sr.

n_mels: int = 128

Number of mel bands.

power: int = 2

Raise spectrogram magnitudes to this power. Default is 2 which is the usual power spectrogram.

pre_emphasis: float = 0

Amount of pre-emphasis to apply. Default is 0 (no pre-emphasis).

to_log: str | None = 'db'

Whether to convert spectrogram to logarithmic domain. Default is db which converts to dB units. If to_log=='log' then the natual logarithm is taken. Note that this argument is mainly only useful if power == 2.

win_length_samp: int | None = None

The window length in samples. This overrides window_size if given.

window_shift: float = 0.01

Amount window moves each frame, in seconds. Default is 0.01 (10 ms).

window_size: float = 0.025

Size of window in seconds. Default is 0.025 (25 ms).