resample

paddle.audio.functional. resample ( waveform: Tensor, orig_freq: int, new_freq: int, lowpass_filter_width: int = 6, rolloff: float = 0.99, resampling_method: Literal['sinc_interp_hann', 'sinc_interp_kaiser'] = 'sinc_interp_hann', beta: Optional[float] = None ) → Tensor [source]

Resample the waveform from orig_freq to new_freq using bandlimited interpolation.

This function implements resampling through sinc interpolation with windowing. It first computes a resampling kernel based on the specified parameters, then applies it to the input waveform using convolution. The algorithm handles both upsampling and downsampling while minimizing aliasing artifacts.

Parameters
  • waveform (Tensor) – The input signal of dimension (…, time). Must be floating point type (float32 or float64).

  • orig_freq (int) – The original frequency of the signal. Must be positive.

  • new_freq (int) – The desired target frequency. Must be positive.

  • lowpass_filter_width (int, optional) – Controls the sharpness of the filter. Larger values give sharper filtering but are less efficient. Default: 6.

  • rolloff (float, optional) – The roll-off frequency of the filter as a fraction of the Nyquist frequency. Lower values reduce anti-aliasing but also attenuate some high frequencies. Default: 0.99.

  • resampling_method (str, optional) – The windowing method to use for filter design. Options: “sinc_interp_hann” (Hann window) or “sinc_interp_kaiser” (Kaiser window). Default: “sinc_interp_hann”.

  • beta (float, optional) – Shape parameter for the Kaiser window. Required only when resampling_method=”sinc_interp_kaiser”. If not provided for Kaiser, a default value of 14.769656459379492 is used. Default: None.

Returns

The waveform resampled to new_freq, with dimension (…, new_time).

Return type

Tensor

Raises
  • ValueError – If orig_freq or new_freq are not positive.

  • Exception – If frequencies are not integers (see note below).

  • TypeError – If waveform is not floating point.

Note

  • orig_freq and new_freq must be integers. For non-integer frequencies, convert them to integers while maintaining the ratio.

  • For repeated resampling with same parameters, use paddle.audio.transforms.Resample for better efficiency.

  • Uses windowed sinc interpolation for high-quality audio resampling.

  • This function does not support ONNX export now.

Examples

>>> import paddle
>>> from paddle.audio.functional import resample

>>> # Create a sample waveform (1 channel, 1000 samples at 16000 Hz)
>>> waveform = paddle.randn([1, 1000])

>>> # Downsample from 16000 Hz to 8000 Hz
>>> resampled = resample(waveform, 16000, 8000)
>>> print(resampled.shape)
paddle.Size([1, 500])

>>> # Upsample from 16000 Hz to 48000 Hz with custom filter width
>>> resampled = resample(waveform, 16000, 48000, lowpass_filter_width=12)
>>> print(resampled.shape)
paddle.Size([1, 3000])

>>> # Use Kaiser window resampling
>>> resampled = resample(waveform, 16000, 8000, resampling_method="sinc_interp_kaiser", beta=12.0)
>>> print(resampled.shape)
paddle.Size([1, 500])

>>> # Batch processing: multiple waveforms
>>> batch_waveforms = paddle.randn([4, 1, 1000])  # [batch, channels, time]
>>> resampled_batch = resample(batch_waveforms, 16000, 8000)
>>> print(resampled_batch.shape)
paddle.Size([4, 1, 500])