Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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." ;-)

like image 691
sh37211 Avatar asked May 31 '16 21:05

sh37211


3 Answers

...Two years later, here's an answer:

Igor Gadelha wrote a GitHub repo dpm that includes his vstRender class, which he wrote in JUCE. Currently it only works for mono plugins. I wrote some simple code to illustrate how to use vstRender, which Igor included in his "contrib" section: run_plugin.py.

like image 107
sh37211 Avatar answered Nov 11 '22 05:11

sh37211


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)
like image 20
Peter Sobot Avatar answered Nov 11 '22 05:11

Peter Sobot


The other libraries shared are great. I want to share DawDreamer, which I developed as an evolution of Renderman. It has many features:

  • Composing graphs of audio processors (not just a single linear chain)
  • Audio playback
  • VST2 instruments (some VST3 instruments may not work at the moment)
  • VST2 and VST3 effects
  • FAUST effects and polyphonic instruments
  • Time-stretching and looping according to Ableton Live warp markers
  • Pitch-warping (with Rubberband Library)
  • Parameter automation
  • Rendering multiple processors simultaneously
  • Full support on Linux (Dockerfile), macOS, and Windows
  • pip/PyPi installation

Some people have expressed an interest in LV2 plugins, which I haven't tested. I would suggest trying Faust as an open-source alternative, but I'll get to testing LV2 too.

I hope to demonstrate a reinforcement learning environment soon.

like image 2
David Braun Avatar answered Nov 11 '22 06:11

David Braun