Shortcuts

ChromaSpectrogram

class torchaudio.prototype.transforms.ChromaSpectrogram(sample_rate: int, n_fft: int, *, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, pad: int = 0, 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', n_chroma: int = 12, tuning: float = 0.0, ctroct: float = 5.0, octwidth: ~typing.Optional[float] = 2.0, norm: int = 2, base_c: bool = True)[source]

Generates chromagram for audio signal.

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd

Composes torchaudio.transforms.Spectrogram() and and torchaudio.prototype.transforms.ChromaScale().

Parameters:
  • sample_rate (int) – Sample rate of audio signal.

  • n_fft (int, optional) – Size of FFT, creates n_fft // 2 + 1 bins.

  • 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)

  • pad (int, optional) – Two sided padding of signal. (Default: 0)

  • 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 is True. (Default: "reflect")

  • n_chroma (int, optional) – Number of chroma. (Default: 12)

  • tuning (float, optional) – Tuning deviation from A440 in fractions of a chroma bin. (Default: 0.0)

  • ctroct (float, optional) – Center of Gaussian dominance window to weight filters by, in octaves. (Default: 5.0)

  • octwidth (float or None, optional) – Width of Gaussian dominance window to weight filters by, in octaves. If None, then disable weighting altogether. (Default: 2.0)

  • norm (int, optional) – order of norm to normalize filter bank by. (Default: 2)

  • base_c (bool, optional) – If True, then start filter bank at C. Otherwise, start at A. (Default: True)

Example
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True)
>>> transform = transforms.ChromaSpectrogram(sample_rate=sample_rate, n_fft=400)
>>> chromagram = transform(waveform)  # (channel, n_chroma, time)
forward(waveform: Tensor) Tensor[source]
Parameters:

waveform (Tensor) – Tensor of audio of dimension (…, time).

Returns:

Chromagram of size (…, n_chroma, time).

Return type:

Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources