original_docstring: Resamples the waveform at the new frequency.
  
          This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
          LinearResample (resample a signal at linearly spaced intervals to
          up/downsample a signal). LinearResample (LR) means that the output
          signal is at linearly spaced intervals (i.e the output signal has a
          frequency of `new_freq`). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          (almost directly from torchaudio.compliance.kaldi)
  
          https://ccrma.stanford.edu/~jos/resample/
          Theory_Ideal_Bandlimited_Interpolation.html
  
          https://github.com/kaldi-asr/kaldi/blob/master/src/feat/resample.h#L56
  
          Arguments
          ---------
          waveforms : tensor
              The batch of audio signals to resample.
  
          Returns
          -------
          The waveforms at the new frequency.
          
docstring: Resamples the waveform at the new frequency.
  This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
  LinearResample (resample a signal at linearly spaced intervals to
  up/downsample a signal). LinearResample (LR) means that the output
  signal is at linearly spaced intervals . It uses sinc/bandlimited interpolation to
  upsample/downsample the signal.
  
  
  
  
  
  
  
  Arguments
  
  waveforms : tensor
  The batch of audio signals to resample.
  
  Returns
  
  The waveforms at the new frequency.
docstring_tokens: Resamples the waveform at the new frequency . This matches Kaldi ' s OfflineFeatureTpl ResampleWaveform which uses a LinearResample ( resample a signal at linearly spaced intervals to up / downsample a signal ) . LinearResample ( LR ) means that the output signal is at linearly spaced intervals . It uses sinc / bandlimited interpolation to upsample / downsample the signal . Arguments waveforms : tensor The batch of audio signals to resample . Returns The waveforms at the new frequency .
code: def _perform_resample(self, waveforms):
          """Resamples the waveform at the new frequency.
  
          This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
          LinearResample (resample a signal at linearly spaced intervals to
          up/downsample a signal). LinearResample (LR) means that the output
          signal is at linearly spaced intervals (i.e the output signal has a
          frequency of `new_freq`). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          (almost directly from torchaudio.compliance.kaldi)
  
          https://ccrma.stanford.edu/~jos/resample/
          Theory_Ideal_Bandlimited_Interpolation.html
  
          https://github.com/kaldi-asr/kaldi/blob/master/src/feat/resample.h#L56
  
          Arguments
          ---------
          waveforms : tensor
              The batch of audio signals to resample.
  
          Returns
          -------
          The waveforms at the new frequency.
          """
  
          # Compute output size and initialize
          batch_size, num_channels, wave_len = waveforms.size()
          window_size = self.weights.size(1)
          tot_output_samp = self._output_samples(wave_len)
          resampled_waveform = torch.zeros(
              (batch_size, num_channels, tot_output_samp),
              device=waveforms.device,
          )
          self.weights = self.weights.to(waveforms.device)
  
          # Check weights are on correct device
          if waveforms.device != self.weights.device:
              self.weights = self.weights.to(waveforms.device)
  
          # eye size: (num_channels, num_channels, 1)
          eye = torch.eye(num_channels, device=waveforms.device).unsqueeze(2)
  
          # Iterate over the phases in the polyphase filter
          for i in range(self.first_indices.size(0)):
              wave_to_conv = waveforms
              first_index = int(self.first_indices[i].item())
              if first_index >= 0:
                  # trim the signal as the filter will not be applied
                  # before the first_index
                  wave_to_conv = wave_to_conv[..., first_index:]
  
              # pad the right of the signal to allow partial convolutions
              # meaning compute values for partial windows (e.g. end of the
              # window is outside the signal length)
              max_index = (tot_output_samp - 1) // self.output_samples
              end_index = max_index * self.conv_stride + window_size
              current_wave_len = wave_len - first_index
              right_padding = max(0, end_index + 1 - current_wave_len)
              left_padding = max(0, -first_index)
              wave_to_conv = torch.nn.functional.pad(
                  wave_to_conv, (left_padding, right_padding)
              )
              conv_wave = torch.nn.functional.conv1d(
                  input=wave_to_conv,
                  weight=self.weights[i].repeat(num_channels, 1, 1),
                  stride=self.conv_stride,
                  groups=num_channels,
              )
  
              # we want conv_wave[:, i] to be at
              # output[:, i + n*conv_transpose_stride]
              dilated_conv_wave = torch.nn.functional.conv_transpose1d(
                  conv_wave, eye, stride=self.conv_transpose_stride
              )
  
              # pad dilated_conv_wave so it reaches the output length if needed.
              left_padding = i
              previous_padding = left_padding + dilated_conv_wave.size(-1)
              right_padding = max(0, tot_output_samp - previous_padding)
              dilated_conv_wave = torch.nn.functional.pad(
                  dilated_conv_wave, (left_padding, right_padding)
              )
              dilated_conv_wave = dilated_conv_wave[..., :tot_output_samp]
  
              resampled_waveform += dilated_conv_wave
  
          return resampled_waveform
code_tokens: def _perform_resample ( self , waveforms ) : batch_size , num_channels , wave_len = waveforms . size ( ) window_size = self . weights . size ( 1 ) tot_output_samp = self . _output_samples ( wave_len ) resampled_waveform = torch . zeros ( ( batch_size , num_channels , tot_output_samp ) , device = waveforms . device , ) self . weights = self . weights . to ( waveforms . device ) if waveforms . device != self . weights . device : self . weights = self . weights . to ( waveforms . device ) eye = torch . eye ( num_channels , device = waveforms . device ) . unsqueeze ( 2 ) for i in range ( self . first_indices . size ( 0 ) ) : wave_to_conv = waveforms first_index = int ( self . first_indices [ i ] . item ( ) ) if first_index >= 0 : wave_to_conv = wave_to_conv [ ... , first_index : ] max_index = ( tot_output_samp - 1 ) // self . output_samples end_index = max_index * self . conv_stride + window_size current_wave_len = wave_len - first_index right_padding = max ( 0 , end_index + 1 - current_wave_len ) left_padding = max ( 0 , - first_index ) wave_to_conv = torch . nn . functional . pad ( wave_to_conv , ( left_padding , right_padding ) ) conv_wave = torch . nn . functional . conv1d ( input = wave_to_conv , weight = self . weights [ i ] . repeat ( num_channels , 1 , 1 ) , stride = self . conv_stride , groups = num_channels , ) dilated_conv_wave = torch . nn . functional . conv_transpose1d ( conv_wave , eye , stride = self . conv_transpose_stride ) left_padding = i previous_padding = left_padding + dilated_conv_wave . size ( - 1 ) right_padding = max ( 0 , tot_output_samp - previous_padding ) dilated_conv_wave = torch . nn . functional . pad ( dilated_conv_wave , ( left_padding , right_padding ) ) dilated_conv_wave = dilated_conv_wave [ ... , : tot_output_samp ] resampled_waveform += dilated_conv_wave return resampled_waveform
short_docstring: Resamples the waveform at the new frequency.
short_docstring_tokens: Resamples the waveform at the new frequency .
comment: """Resamples the waveform at the new frequency.
  
          This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
          LinearResample (resample a signal at linearly spaced intervals to
          up/downsample a signal). LinearResample (LR) means that the output
          signal is at linearly spaced intervals (i.e the output signal has a
          frequency of `new_freq`). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          (almost directly from torchaudio.compliance.kaldi)
  
          https://ccrma.stanford.edu/~jos/resample/
          Theory_Ideal_Bandlimited_Interpolation.html
  
          https://github.com/kaldi-asr/kaldi/blob/master/src/feat/resample.h#L56
  
          Arguments
          ---------
          waveforms : tensor
              The batch of audio signals to resample.
  
          Returns
          -------
          The waveforms at the new frequency.
          """$SEP$# Compute output size and initialize$SEP$# Check weights are on correct device$SEP$# eye size: (num_channels, num_channels, 1)$SEP$# Iterate over the phases in the polyphase filter$SEP$# trim the signal as the filter will not be applied$SEP$# before the first_index$SEP$# pad the right of the signal to allow partial convolutions$SEP$# meaning compute values for partial windows (e.g. end of the$SEP$# window is outside the signal length)$SEP$# we want conv_wave[:, i] to be at$SEP$# output[:, i + n*conv_transpose_stride]$SEP$# pad dilated_conv_wave so it reaches the output length if needed.