New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pedalboard objects are not pickleable or serializable #96
Comments
Thanks @adhooge! Pedalboard objects are definitely not (yet) pickleable; I'm usually a bit wary of pickling (due to the nasty edge-cases that can arise) but I think it'd be reasonable in this case. It'd be possible to add this functionality by:
There's also a couple of complications to consider, like what happens when pickling/unpickling a plugin that references an external file? (i.e.: |
Thanks for your answer! I did not think about the possible issue of Plugins with external files, it would indeed require further consideration. |
Hi! I did not try changing the entire module since I'm not familiar with C/C++ bindings in Python but I've written simple helper functions for accessing the parameters of plugins. It's kinda ugly and I don't think it works on complex plugins but it is working fine with the default plugins (
The output of Minimal working example:
|
I guess the main goal of serialization is to re-load a given set of transformations, e.g. when stored in a cache together with the audio files. One way is to serialize to YAML, which has the advantage that it is also human readable. You can achieve this by deriving your classes from audobject.Object. If you want to handle random arguments, you also need to have another object handling those. Let's imagine we have a transform transform = pedalboard.PinkNoise(snr_db=pedalboard.observe.List([-5, 0, 10, 20])) You can then store it to a YAML file: transform.to_yaml('transform.yaml') and load it from the YAML file: import audobject
transform = audobject.from_yaml('transform.yaml') The corresponding YAML file looks like this: $pedalboard.PinkNoise==0.7.0:
snr_db:
$pedalboard.observe.List==0.7.0:
elements:
- -5
- 0
- 10
- 20 |
Here are some other tangentially related notes from another issue, about serialising plugin parameters to json, and loading them back again:
|
We have recently released https://github.com/audeering/auglib for audio augmentations. You can use auglib.transform.Function as a wrapper for pedalboard transforms and then serialize them. You can also include random parameters in a transform: import auglib
import pedalboard
def pedalboard_transform(signal, sampling_rate, threshold_db, ratio, room_size):
r"""Custom augmentation using pedalboard."""
import pedalboard
board = pedalboard.Pedalboard(
[
pedalboard.Compressor(threshold_db=threshold_db, ratio=ratio),
pedalboard.Chorus(),
pedalboard.Phaser(),
pedalboard.Reverb(room_size=room_size),
],
)
return board(signal, sampling_rate)
transform = auglib.transform.Compose(
[
auglib.transform.Function(
pedalboard_transform,
function_args={
"threshold_db": auglib.observe.IntUni(-55, -45),
"ratio": auglib.observe.IntUni(20, 30),
"room_size": auglib.observe.FloatNorm(0.25, 0.02),
},
),
auglib.transform.NormalizeByPeak(),
]
) Serialize it to a YAML file. transform.to_yaml("transform.yaml") Inspect the YAML file with open("transform.yaml", "r") as f:
print(f.read()) which returns
Load transform from YAML file import audobject
transform = audobject.from_yaml("transform.yaml") |
First of all, thanks a lot for the amazing library, it's a great help!
While toying around, I wanted to store
Pedalboard
instances by directly dumping them usingpickle
(https://docs.python.org/3/library/pickle.html).This fails yielding a
TypeError: cannot pickle 'Pedalboard' object
.After doing some research it might be due to the fact that
Pedalboard.__dict__
is an empty dictionary and thus nothing can be pickled.Besides, the
__reduce__
method called bypickle
for dumping yields the following error:I don't know if that is a relevant issue, I think it would be great to be able to save Pedalboard instances in some way. Maybe pickling it is not the correct way to do it and there exists another technique?
I'd love to help fixing that issue if it is considered relevant.
The text was updated successfully, but these errors were encountered: