spotify / pedalboard

🎛 🔊 A Python library for audio.
https://spotify.github.io/pedalboard
GNU General Public License v3.0
5.23k stars 262 forks source link

Add stream resampler and resampling AudioFile. #145

Closed psobot closed 2 years ago

psobot commented 2 years ago

This PR adds a new class to pedalboard.io, called StreamResampler. Like it says on the tin, StreamResampler allows for resampling (changing the sample rate of) audio streams. It does so in a way that uses a constant amount of memory; meaning it can be used to resample infinite streams without requiring all of the audio to be present at once.

Like its plugin-based cousin, pedalboard.Resample, StreamResampler accepts a Resample.Quality argument to control the processing speed and quality of the resampling operation. Unlike Resample, StreamResampler accepts audio at a source_sample_rate and outputs audio at a target_sample_rate; i.e.: changing the sample rate of the audio stream, rather than just degrading the stream's quality. (see https://github.com/spotify/pedalboard/issues/82; hi @nukelash!) As such, it is not a Plugin, and cannot be inserted into Pedalboard instances, but does have process and reset methods.