Waveform.resample_by_mode()

Waveform.resample_by_mode(resample_mode)

Resamples the waveform with the resampler of your choice.

Babycat comes with different backends for resampling audio waveforms from one frame rate to another frame rate.

By default, Babycat resamples audio using libsamplerate at its highest-quality setting. Babycat also comes with two other resampling backends that are often faster–but produce slightly lower quality output.

Example

Resample from 44,100 hz to 88,200 hz.

>>> from babycat import Waveform
>>> from babycat.resample_mode import *
>>>
>>> waveform = Waveform.from_frames_of_silence(
...     frame_rate_hz=44100,
...     num_channels=2,
...     num_frames=1000,
... )
>>> waveform
<babycat.Waveform: 1000 frames, 2 channels, 44100 hz>
>>> resampled = waveform.resample_by_mode(
...     frame_rate_hz=11025,
...     resample_mode=RESAMPLE_MODE_BABYCAT_SINC,
... )
<babycat.Waveform: 250 frames, 2 channels, 11025 hz>
Parameters
  • frame_rate_hz (int) – The target frame rate to resample to.

  • resample_mode (int) – The resampler to use. This has to be one of the constants in babycat.resample_mode.

Returns

A new waveform resampled at the given frame rate.

Return type

Waveform

Raises