BarkSpectrogram¶
- class torchaudio.prototype.transforms.BarkSpectrogram(sample_rate: int = 16000, n_fft: int = 400, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, f_min: float = 0.0, f_max: ~typing.Optional[float] = None, pad: int = 0, n_barks: int = 128, window_fn: ~typing.Callable[[...], ~torch.Tensor] = <built-in method hann_window of type object>, power: float = 2.0, normalized: bool = False, wkwargs: ~typing.Optional[dict] = None, center: bool = True, pad_mode: str = 'reflect', bark_scale: str = 'traunmuller')[source]¶
Create BarkSpectrogram for a raw audio signal.
This is a composition of
torchaudio.transforms.Spectrogram()
and andtorchaudio.transforms.BarkScale()
.- Sources
https://www.fon.hum.uva.nl/praat/manual/BarkSpectrogram.html
Traunmüller, Hartmut. “Analytical Expressions for the Tonotopic Sensory Scale.” Journal of the Acoustical
Society of America. Vol. 88, Issue 1, 1990, pp. 97–100.
https://ccrma.stanford.edu/courses/120-fall-2003/lecture-5.html
- Parameters:
sample_rate (int, optional) – Sample rate of audio signal. (Default:
16000
)n_fft (int, optional) – Size of FFT, creates
n_fft // 2 + 1
bins. (Default:400
)win_length (int or None, optional) – Window size. (Default:
n_fft
)hop_length (int or None, optional) – Length of hop between STFT windows. (Default:
win_length // 2
)f_min (float, optional) – Minimum frequency. (Default:
0.
)f_max (float or None, optional) – Maximum frequency. (Default:
None
)pad (int, optional) – Two sided padding of signal. (Default:
0
)n_mels (int, optional) – Number of mel filterbanks. (Default:
128
)window_fn (Callable[..., torch.Tensor], optional) – A function to create a window tensor that is applied/multiplied to each frame/window. (Default:
torch.hann_window
)power (float, optional) – Exponent for the magnitude spectrogram, (must be > 0) e.g., 1 for energy, 2 for power, etc. (Default:
2
)normalized (bool, optional) – Whether to normalize by magnitude after stft. (Default:
False
)wkwargs (Dict[..., ...] or None, optional) – Arguments for window function. (Default:
None
)center (bool, optional) – whether to pad
waveform
on both sides so that the \(t\)-th frame is centered at time \(t \times \text{hop\_length}\). (Default:True
)pad_mode (string, optional) – controls the padding method used when
center
isTrue
. (Default:"reflect"
)bark_scale (str, optional) – Scale to use:
traunmuller
,schroeder
orwang
. (Default:traunmuller
)
- Example
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.BarkSpectrogram(sample_rate) >>> bark_specgram = transform(waveform) # (channel, n_barks, time)
See also
torchaudio.functional.melscale_fbanks()
- The function used to generate the filter banks.- forward(waveform: Tensor) Tensor [source]¶
- Parameters:
waveform (torch.Tensor) – torch.Tensor of audio of dimension (…, time).
- Returns:
Bark frequency spectrogram of size (…,
n_barks
, time).- Return type: