pythonaudiopluginsaudiounitvst

How to call audio plugins from within Python?


I've noticed that some open source DAWs such as Ardour and Audacity are able to access audio plugins (e.g. VST, AU) that the user has installed on their system. This makes me think that "there ought to be a way" to do this in general.

Specifically, I'd like to call some plugins from within my own audio-processing application, which I'm writing in Python. Is there a recommended method or library that one can use for this?

My own searches have turned up nearly nothing. The only relevant post I've seen is this one but it's 5 years old. There is some mention of using JUCE and there are some 2-year-old Python bindings called PyJUCE (which seem to be setup for Windows), but so far I haven't gotten anything working, mostly due my poor acclimation to the sheer "bulk" of JUCE.

Any suggestions?

Perhaps the only remaining option is to start from scratch by writing one's own VST host, and then proceed as one would when calling any external C++ code from within Python. I just thought I'd ask before reinventing the wheel, because it's often the case that "whatever you want to do, someone else has already written a Python package for it." ;-)


Solution

  • Spotify has released pedalboard, a pip-installable Python library based on JUCE with support for loading and running audio plugins on macOS, Windows, and Linux. VST3 plugins are supported on all platforms, and Audio Units are supported on macOS. (As of September 2021, Pedalboard only supports audio effects, but contributors may add support for instrument plug-ins in the future.)

    An example of using pedalboard:

    # After installing with `pip install pedalboard`:
    
    import soundfile as sf
    from pedalboard import Pedalboard, Compressor, Chorus, Distortion, Reverb
    
    audio, sample_rate = soundfile.read('some-file.wav')
    
    # Make a Pedalboard object, containing multiple plugins:
    board = Pedalboard([
        Compressor(threshold_db=-50, ratio=25),
        Distortion(drive_db=30),
        Chorus(),
        load_plugin("./VSTs/SomePlugin.vst3"), # Load a VST3 plugin
        Reverb(room_size=0.25),
    ], sample_rate=sample_rate)
    
    # Run the audio through this pedalboard!
    effected = board(audio)