如何从 Python 中调用音频插件?

How to call audio plugins from within Python?

我注意到一些开源 DAW(例如 Ardor 和 Audacity)能够访问用户在其系统上安装的音频插件(例如 VST、AU)。这让我觉得 "there ought to be a way" 这样做一般。

具体来说,我想从我自己的音频处理应用程序中调用一些插件,我正在 Python 中编写该应用程序。是否有推荐的方法或库可以用于此?

我自己的搜索几乎一无所获。我见过的唯一相关的 post 是 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(似乎是为 Windows 设置的),但到目前为止我还没有任何工作,主要是因为我对纯粹的 "bulk" 的 JUCE。

有什么建议吗?

也许唯一剩下的选择是 start from scratch by writing one's own VST host,然后像从 Python 中调用任何外部 C++ 代码一样继续进行。我只是想在重新发明轮子之前先问一下,因为通常情况下 "whatever you want to do, someone else has already written a Python package for it." ;-)

...两年后,这里有一个答案:

Igor Gadelha 写了一个 GitHub repo dpm that includes his vstRender class,他用 JUCE 写的。目前它只适用于单声道插件。 我写了一些简单的代码来说明如何使用 vstRender,Igor 包含在 他的 "contrib" 部分:run_plugin.py.

几年前,我编写了 some Python code 来加载合成器 VST,调整其参数并为给定的 note/velocity/duration 生成声音。它非常有限,但可以作为一个起点。

因为 VST 2.4 已经过时了 C,我可以使用 ctypes 标准库在纯 Python 中编写整个内容。然而,这有不支持 VST 3 的缺点。

Spotify 已发布 pedalboard, a pip-installable Python library based on JUCE,支持在 macOS、Windows 和 Linux 上加载和 运行 音频插件。所有平台都支持 VST3 插件,macOS 支持音频单元。 (截至2021年9月,Pedalboard仅支持音频效果,但贡献者未来可能会增加对乐器插件的支持。)

使用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)

其他分享的库都很棒。我想分享 DawDreamer,这是我作为 Renderman 的进化版开发的。它有很多特点:

  • 音频处理器的组合图(不仅仅是单个线性链)
  • 音频播放
  • VST2 乐器(部分 VST3 乐器目前可能无法使用)
  • VST2 和 VST3 效果
  • FAUST effects and polyphonic instruments
  • Time-stretching and looping 根据 Ableton Live 变形标记
  • 变调(使用 Rubberband 库)
  • 参数自动化
  • 同时渲染多个处理器
  • 完全支持 Linux (Dockerfile)、macOS 和 Windows
  • pip/PyPi 安装

有些人表示对 LV2 插件感兴趣,我还没有测试过。我建议尝试将 Faust 作为开源替代品,但我也会开始测试 LV2。

我希望尽快展示强化学习环境。