Spaces:
Sleeping
Sleeping
Update effects.py
Browse files- effects.py +81 -0
effects.py
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# effects.py
|
| 2 |
+
|
| 3 |
+
from pedalboard import Pedalboard, Reverb, Delay, Chorus, Compressor, Gain, HighpassFilter, LowpassFilter
|
| 4 |
+
from pedalboard.io import AudioFile
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def add_vocal_effects(input_file, output_file,
|
| 8 |
+
reverb_room_size=0.6, vocal_reverb_dryness=0.8, reverb_damping=0.6, reverb_wet_level=0.35,
|
| 9 |
+
delay_seconds=0.4, delay_mix=0.25,
|
| 10 |
+
compressor_threshold_db=-25, compressor_ratio=3.5,
|
| 11 |
+
compressor_attack_ms=10, compressor_release_ms=60,
|
| 12 |
+
gain_db=3):
|
| 13 |
+
|
| 14 |
+
effects = [HighpassFilter()]
|
| 15 |
+
|
| 16 |
+
effects.append(Reverb(
|
| 17 |
+
room_size=reverb_room_size,
|
| 18 |
+
damping=reverb_damping,
|
| 19 |
+
wet_level=reverb_wet_level,
|
| 20 |
+
dry_level=vocal_reverb_dryness,
|
| 21 |
+
))
|
| 22 |
+
|
| 23 |
+
effects.append(Compressor(
|
| 24 |
+
threshold_db=compressor_threshold_db,
|
| 25 |
+
ratio=compressor_ratio,
|
| 26 |
+
attack_ms=compressor_attack_ms,
|
| 27 |
+
release_ms=compressor_release_ms,
|
| 28 |
+
))
|
| 29 |
+
|
| 30 |
+
if delay_seconds > 0 or delay_mix > 0:
|
| 31 |
+
effects.append(Delay(delay_seconds=delay_seconds, mix=delay_mix))
|
| 32 |
+
|
| 33 |
+
if gain_db:
|
| 34 |
+
effects.append(Gain(gain_db=gain_db))
|
| 35 |
+
|
| 36 |
+
board = Pedalboard(effects)
|
| 37 |
+
|
| 38 |
+
with AudioFile(input_file) as f:
|
| 39 |
+
with AudioFile(output_file, 'w', f.samplerate, f.num_channels) as o:
|
| 40 |
+
while f.tell() < f.frames:
|
| 41 |
+
chunk = f.read(int(f.samplerate))
|
| 42 |
+
effected = board(chunk, f.samplerate, reset=False)
|
| 43 |
+
o.write(effected)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def add_instrumental_effects(input_file, output_file,
|
| 47 |
+
highpass_freq=100, lowpass_freq=12000,
|
| 48 |
+
reverb_room_size=0.5, reverb_damping=0.5, reverb_wet_level=0.25,
|
| 49 |
+
compressor_threshold_db=-20, compressor_ratio=2.5,
|
| 50 |
+
compressor_attack_ms=15, compressor_release_ms=80,
|
| 51 |
+
gain_db=2):
|
| 52 |
+
|
| 53 |
+
effects = [
|
| 54 |
+
HighpassFilter(cutoff_frequency_hz=highpass_freq),
|
| 55 |
+
LowpassFilter(cutoff_frequency_hz=lowpass_freq),
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
effects.append(Reverb(
|
| 59 |
+
room_size=reverb_room_size,
|
| 60 |
+
damping=reverb_damping,
|
| 61 |
+
wet_level=reverb_wet_level,
|
| 62 |
+
))
|
| 63 |
+
|
| 64 |
+
effects.append(Compressor(
|
| 65 |
+
threshold_db=compressor_threshold_db,
|
| 66 |
+
ratio=compressor_ratio,
|
| 67 |
+
attack_ms=compressor_attack_ms,
|
| 68 |
+
release_ms=compressor_release_ms,
|
| 69 |
+
))
|
| 70 |
+
|
| 71 |
+
if gain_db:
|
| 72 |
+
effects.append(Gain(gain_db=gain_db))
|
| 73 |
+
|
| 74 |
+
board = Pedalboard(effects)
|
| 75 |
+
|
| 76 |
+
with AudioFile(input_file) as f:
|
| 77 |
+
with AudioFile(output_file, 'w', f.samplerate, f.num_channels) as o:
|
| 78 |
+
while f.tell() < f.frames:
|
| 79 |
+
chunk = f.read(int(f.samplerate))
|
| 80 |
+
effected = board(chunk, f.samplerate, reset=False)
|
| 81 |
+
o.write(effected)
|