pedalboard
是用來處理音訊的 Python 函式庫:讀取、寫入、渲染、新增效果等。它支援最受歡迎的音訊檔案格式和許多開箱即用的常見音訊效果,還允許使用 VST3® 和 Audio Unit 格式載入第三方軟體樂器和效果。
pedalboard
由 Spotify 的音訊智慧實驗室構建,可在 Python 和 TensorFlow 中使用工作室品質的音訊效果。在 Spotify 內部, pedalboard
用於資料增強,以改進機器學習模型並幫助支援 Spotify 的 AI DJ 和 AI 語音翻譯等功能。 pedalboard
還有助於內容創建過程,無需使用數位音訊工作站即可為音訊添加效果。
O(1)
記憶體使用量對音訊檔案和串流進行動態重採樣AudioStream
實現即時音訊效果Chorus
、 Distortion
、 Phaser
、 Clipping
Compressor
、 Gain
、 Limiter
HighpassFilter
、 LadderFilter
、 LowpassFilter
Convolution
、 Delay
、 Reverb
PitchShift
GSMFullRateCompressor
、 MP3Compressor
Resample
、 Bitcrush
pedalboard.load_plugin
)multiprocessing
!tf.data
管道中使用! pedalboard
可透過 PyPI 使用(透過 Platform Wheels):
pip install pedalboard # That's it! No other dependencies required.
如果您是 Python 新手,請按照 INSTALLATION.md 取得可靠指南。
pedalboard
使用 Python 3.8、3.9、3.10、3.11、3.12 和 3.13 進行了全面測試。
x86_64
(Intel/AMD) 和aarch64
(ARM/Apple Silicon) 建造的平台manylinux
和musllinux
輪子amd64
(x86-64、Intel/AMD)的平台輪注意:如果您更願意觀看影片而不是閱讀範例或文檔,請觀看 YouTube 上的使用 Python 中的音訊 (feat. Pedalboard) 。
from pedalboard import Pedalboard , Chorus , Reverb
from pedalboard . io import AudioFile
# Make a Pedalboard object, containing multiple audio plugins:
board = Pedalboard ([ Chorus (), Reverb ( room_size = 0.25 )])
# Open an audio file for reading, just like a regular file:
with AudioFile ( 'some-file.wav' ) as f :
# Open an audio file to write to:
with AudioFile ( 'output.wav' , 'w' , f . samplerate , f . num_channels ) as o :
# Read one second of audio at a time, until the file is empty:
while f . tell () < f . frames :
chunk = f . read ( f . samplerate )
# Run the audio through our pedalboard:
effected = board ( chunk , f . samplerate , reset = False )
# Write the output to our output file:
o . write ( effected )
注意:有關如何透過 Pedalboard 插件處理音訊的更多信息,包括
reset
參數的工作原理,請參閱pedalboard.Plugin.process
的文檔。
# Don't do import *! (It just makes this example smaller)
from pedalboard import *
from pedalboard . io import AudioFile
# Read in a whole file, resampling to our desired sample rate:
samplerate = 44100.0
with AudioFile ( 'guitar-input.wav' ). resampled_to ( samplerate ) as f :
audio = f . read ( f . frames )
# Make a pretty interesting sounding guitar pedalboard:
board = Pedalboard ([
Compressor ( threshold_db = - 50 , ratio = 25 ),
Gain ( gain_db = 30 ),
Chorus (),
LadderFilter ( mode = LadderFilter . Mode . HPF12 , cutoff_hz = 900 ),
Phaser (),
Convolution ( "./guitar_amp.wav" , 1.0 ),
Reverb ( room_size = 0.25 ),
])
# Pedalboard objects behave like lists, so you can add plugins:
board . append ( Compressor ( threshold_db = - 25 , ratio = 10 ))
board . append ( Gain ( gain_db = 10 ))
board . append ( Limiter ())
# ... or change parameters easily:
board [ 0 ]. threshold_db = - 40
# Run the audio through this pedalboard!
effected = board ( audio , samplerate )
# Write the audio back as a wav file:
with AudioFile ( 'processed-output.wav' , 'w' , samplerate , effected . shape [ 0 ]) as f :
f . write ( effected )
from pedalboard import Pedalboard , Reverb , load_plugin
from pedalboard . io import AudioFile
from mido import Message # not part of Pedalboard, but convenient!
# Load a VST3 or Audio Unit plugin from a known path on disk:
instrument = load_plugin ( "./VSTs/Magical8BitPlug2.vst3" )
effect = load_plugin ( "./VSTs/RoughRider3.vst3" )
print ( effect . parameters . keys ())
# dict_keys([
# 'sc_hpf_hz', 'input_lvl_db', 'sensitivity_db',
# 'ratio', 'attack_ms', 'release_ms', 'makeup_db',
# 'mix', 'output_lvl_db', 'sc_active',
# 'full_bandwidth', 'bypass', 'program',
# ])
# Set the "ratio" parameter to 15
effect . ratio = 15
# Render some audio by passing MIDI to an instrument:
sample_rate = 44100
audio = instrument (
[ Message ( "note_on" , note = 60 ), Message ( "note_off" , note = 60 , time = 5 )],
duration = 5 , # seconds
sample_rate = sample_rate ,
)
# Apply effects to this audio:
effected = effect ( audio , sample_rate )
# ...or put the effect into a chain with other plugins:
board = Pedalboard ([ effect , Reverb ()])
# ...and run that pedalboard with the same VST instance!
effected = board ( audio , sample_rate )
此範例透過在相同音訊上並行運行多個踏板來建立延遲變調效果。 Pedalboard
物件本身就是Plugin
對象,因此您可以根據需要嵌套它們:
from pedalboard import Pedalboard , Compressor , Delay , Distortion , Gain , PitchShift , Reverb , Mix
passthrough = Gain ( gain_db = 0 )
delay_and_pitch_shift = Pedalboard ([
Delay ( delay_seconds = 0.25 , mix = 1.0 ),
PitchShift ( semitones = 7 ),
Gain ( gain_db = - 3 ),
])
delay_longer_and_more_pitch_shift = Pedalboard ([
Delay ( delay_seconds = 0.5 , mix = 1.0 ),
PitchShift ( semitones = 12 ),
Gain ( gain_db = - 6 ),
])
board = Pedalboard ([
# Put a compressor at the front of the chain:
Compressor (),
# Run all of these pedalboards simultaneously with the Mix plugin:
Mix ([
passthrough ,
delay_and_pitch_shift ,
delay_longer_and_more_pitch_shift ,
]),
# Add a reverb on the final mix:
Reverb ()
])
pedalboard
支援透過AudioStream
物件串流即時音頻,允許透過在 Python 中添加效果來即時操作音頻。
from pedalboard import Pedalboard , Chorus , Compressor , Delay , Gain , Reverb , Phaser
from pedalboard . io import AudioStream
# Open up an audio stream:
with AudioStream (
input_device_name = "Apogee Jam+" , # Guitar interface
output_device_name = "MacBook Pro Speakers"
) as stream :
# Audio is now streaming through this pedalboard and out of your speakers!
stream . plugins = Pedalboard ([
Compressor ( threshold_db = - 50 , ratio = 25 ),
Gain ( gain_db = 30 ),
Chorus (),
Phaser (),
Convolution ( "./guitar_amp.wav" , 1.0 ),
Reverb ( room_size = 0.25 ),
])
input ( "Press enter to stop streaming..." )
# The live AudioStream is now closed, and audio has stopped.
tf.data
管道中使用 Pedalboard import tensorflow as tf
sr = 48000
# Put whatever plugins you like in here:
plugins = pedalboard . Pedalboard ([ pedalboard . Gain (), pedalboard . Reverb ()])
# Make a dataset containing random noise:
# NOTE: for real training, here's where you'd want to load your audio somehow:
ds = tf . data . Dataset . from_tensor_slices ([ np . random . rand ( sr )])
# Apply our Pedalboard instance to the tf.data Pipeline:
ds = ds . map ( lambda audio : tf . numpy_function ( plugins . process , [ audio , sr ], tf . float32 ))
# Create and train a (dummy) ML model on this audio:
model = tf . keras . models . Sequential ([ tf . keras . layers . InputLayer ( input_shape = ( sr ,)), tf . keras . layers . Dense ( 1 )])
model . compile ( loss = "mse" )
model . fit ( ds . map ( lambda effected : ( effected , 1 )). batch ( 1 ), epochs = 10 )
更多範例請參閱:
歡迎對pedalboard
做出貢獻!有關詳細信息,請參閱 CONTRIBUTING.md。
要在學術著作中引用pedalboard
,請使用 Zenodo 上的條目:
透過 BibTeX 引用:
@software{sobot_peter_2023_7817838,
author = {Sobot, Peter},
title = {Pedalboard},
month = jul,
year = 2021,
publisher = {Zenodo},
doi = {10.5281/zenodo.7817838},
url = {https://doi.org/10.5281/zenodo.7817838}
}
pedalboard
版權所有 2021-2024 Spotify AB。
pedalboard
根據 GNU 通用公共授權 v3 獲得許可。 pedalboard
包含許多靜態編譯的函式庫,並附有以下授權:
PitchShift
外掛程式和time_stretch
函數使用 Rubber Band Library,該程式庫在商業許可證和 GPLv2(或更新版本)下獲得雙重許可。 FFTW 也用於加速 Rubber Band,並根據 GPLv2(或更新版本)獲得許可。MP3Compressor
外掛程式使用 LAME 專案中的 libmp3lame,該專案在 LGPLv2 下獲得許可,並升級到 GPLv3 以包含在該專案中(經 LGPLv2 允許)。GSMFullRateCompressor
外掛程式使用 libgsm,它在 ISC 授權下獲得許可並與 GPLv3 相容。VST 是 Steinberg Media Technologies GmbH 的註冊商標。