Class: TorchAudio::Transforms::Spectrogram

Inherits:
Torch::NN::Module
  • Object
show all
Defined in:
lib/torchaudio/transforms/spectrogram.rb

Instance Method Summary collapse

Constructor Details

#initialize(n_fft: 400, win_length: nil, hop_length: nil, pad: 0, window_fn: Torch.method(:hann_window), power: 2.0, normalized: false, wkwargs: nil) ⇒ Spectrogram

Returns a new instance of Spectrogram.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/torchaudio/transforms/spectrogram.rb', line 4

def initialize(
  n_fft: 400, win_length: nil, hop_length: nil, pad: 0,
  window_fn: Torch.method(:hann_window), power: 2.0, normalized: false, wkwargs: nil
)

  super()
  @n_fft = n_fft
  # number of FFT bins. the returned STFT result will have n_fft // 2 + 1
  # number of frequecies due to onesided=True in torch.stft
  @win_length = win_length || n_fft
  @hop_length = hop_length || @win_length.div(2) # floor division
  window = wkwargs.nil? ? window_fn.call(@win_length) : window_fn.call(@win_length, **wkwargs)
  register_buffer("window", window)
  @pad = pad
  @power = power
  @normalized = normalized
end

Instance Method Details

#forward(waveform) ⇒ Object



22
23
24
# File 'lib/torchaudio/transforms/spectrogram.rb', line 22

def forward(waveform)
  F.spectrogram(waveform, @pad, @window, @n_fft, @hop_length, @win_length, @power, @normalized)
end