update pedalboard and librosa and use recent interfaces, plus require matplotlib in packages.txt

#1
by cerkut - opened
Files changed (2) hide show
  1. app.py +157 -0
  2. requirements.txt +3 -2
app.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import soundfile as sf
3
+ from pedalboard import (
4
+ Pedalboard,
5
+ Chorus,
6
+ Compressor,
7
+ Convolution,
8
+ Distortion,
9
+ Gain,
10
+ HighpassFilter,
11
+ LadderFilter,
12
+ Limiter,
13
+ LowpassFilter,
14
+ NoiseGate,
15
+ Phaser,
16
+ Reverb,
17
+ )
18
+
19
+
20
+ objects_and_init_kwargs = [
21
+ (
22
+ Chorus,
23
+ {
24
+ "rate_hz": 1.0,
25
+ "depth": 0.25,
26
+ "centre_delay_ms": 7.0,
27
+ "feedback": 0.0,
28
+ "mix": 0.5,
29
+ },
30
+ ),
31
+ (Compressor, {"threshold_db": 0, "ratio": 1, "attack_ms": 1.0, "release_ms": 100}),
32
+ # TODO - maybe add a few impulse responses to a folder + let folks cycle through them.
33
+ # (Convolution, {'impulse_response_filename': None, 'mix': 1.0}),
34
+ (Distortion, {"drive_db": 25}),
35
+ (Gain, {"gain_db": 1.0}),
36
+ (HighpassFilter, {"cutoff_frequency_hz": 50}),
37
+ (LadderFilter, {"mode": LadderFilter.LPF12, "cutoff_hz": 200, "drive": 1.0}),
38
+ (Limiter, {"threshold_db": -10.0, "release_ms": 100.0}),
39
+ (LowpassFilter, {"cutoff_frequency_hz": 50}),
40
+ (
41
+ NoiseGate,
42
+ {"threshold_db": -100.0, "ratio": 10, "attack_ms": 1.0, "release_ms": 100.0},
43
+ ),
44
+ (
45
+ Phaser,
46
+ {
47
+ "rate_hz": 1.0,
48
+ "depth": 0.5,
49
+ "centre_frequency_hz": 1300.0,
50
+ "feedback": 0.0,
51
+ "mix": 0.5,
52
+ },
53
+ ),
54
+ (
55
+ Reverb,
56
+ {
57
+ "room_size": 0.5,
58
+ "damping": 0.5,
59
+ "wet_level": 0.33,
60
+ "dry_level": 0.4,
61
+ "width": 1.0,
62
+ "freeze_mode": 0.0,
63
+ },
64
+ ),
65
+ ]
66
+
67
+ name_to_object_init_kwargs = {
68
+ obj.__name__: (obj, kwargs) for obj, kwargs in objects_and_init_kwargs
69
+ }
70
+
71
+
72
+ def get_transform_names(augmentations):
73
+ transform_names = [st.sidebar.selectbox("Select transformation โ„–1:", augmentations)]
74
+ while transform_names[-1] != "None":
75
+ transform_names.append(
76
+ st.sidebar.selectbox(
77
+ f"Select transformation โ„–{len(transform_names) + 1}:",
78
+ ["None"] + augmentations,
79
+ )
80
+ )
81
+ transform_names = transform_names[:-1]
82
+ return transform_names
83
+
84
+
85
+ def get_transforms():
86
+ transform_names = get_transform_names(sorted(name_to_object_init_kwargs.keys()))
87
+
88
+ transforms = []
89
+ for i, name in enumerate(transform_names):
90
+ st.sidebar.markdown("---")
91
+ st.sidebar.markdown(f"#### transformation โ„–{i + 1}: {name}")
92
+ obj, kwargs = name_to_object_init_kwargs[name]
93
+
94
+ # ๐Ÿšจ OMG pls no ๐Ÿคฎ. It doesn't have to be this way. Do anything but this. ๐Ÿšจ
95
+ inputs = {}
96
+ for k, v in kwargs.items():
97
+ if k in ["mix", "room_size", "damping", "wet_level", "dry_level", "width", "freeze_mode", 'feedback']:
98
+ x = st.sidebar.slider(k, 0.0, 1.0, 0.1, key=f"{k}_{i}")
99
+ elif k in ['threshold_db', 'gain_db']:
100
+ x = st.sidebar.slider(k, -20., 20., 0., key=f"{k}_{i}")
101
+ elif k in ['rate_hz', 'centre_delay_ms', 'depth']:
102
+ x = st.sidebar.slider(k, 0., 10., 0.5, key=f"{k}_{i}")
103
+ elif k in ['drive_db']:
104
+ x = st.sidebar.slider(k, 0., 20., 0., key=f"{k}_{i}")
105
+ elif k in ['release']:
106
+ x = st.sidebar.slider(k, 0.01, 5000., 100., key=f"{k}_{i}")
107
+ elif k in ['ratio', 'drive']:
108
+ x = st.sidebar.slider(k, 1.0, 20., 4., key=f"{k}_{i}")
109
+ elif k in ['attack_ms', 'release_ms']:
110
+ x = st.sidebar.slider(k, 0.1, 2000., key=f"{k}_{i}")
111
+ elif k in ['cutoff_frequency_hz', 'cutoff_hz', 'centre_frequency_hz']:
112
+ x = st.sidebar.slider(k, 20, 20000, key=f"{k}_{i}")
113
+ elif k in ['mode']:
114
+ choices = [LadderFilter.LPF12, LadderFilter.HPF12, LadderFilter.BPF12, LadderFilter.LPF24, LadderFilter.HPF24, LadderFilter.BPF24]
115
+ x = st.sidebar.selectbox(k, choices)
116
+ else:
117
+ x = type(v)(st.sidebar.text_input(k, value=v))
118
+ inputs[k] = x
119
+
120
+ # st.json(inputs)
121
+ transforms.append(obj(**inputs))
122
+ return transforms
123
+
124
+
125
+ # ๐Ÿšจ TODO - messy. clean me pls.
126
+
127
+ audio_file = open('./example.wav', 'rb')
128
+ audio_bytes = audio_file.read()
129
+
130
+ st.markdown("## Input Audio")
131
+ st.audio(audio_bytes, format='audio/ogg')
132
+
133
+ # Run the audio through this pedalboard!
134
+ audio, sample_rate = sf.read('./example.wav')
135
+ # board = Pedalboard(get_transforms(), sample_rate=sample_rate)
136
+ board = Pedalboard(get_transforms())
137
+ effected = board(audio,sample_rate)
138
+
139
+ # Write the audio back as a wav file:
140
+ with sf.SoundFile('./outputs.wav', 'w', samplerate=sample_rate, channels=len(effected.shape)) as f:
141
+ f.write(effected)
142
+
143
+
144
+ audio_file = open('./outputs.wav', 'rb')
145
+ audio_bytes = audio_file.read()
146
+
147
+ st.markdown("## Effected Audio")
148
+ st.audio(audio_bytes, format='audio/wav')
149
+
150
+
151
+ from matplotlib import pyplot as plt
152
+ import librosa
153
+ import librosa.display
154
+
155
+ fig = plt.figure(figsize=(14, 5))
156
+ librosa.display.waveshow(effected, sr=sample_rate)
157
+ st.pyplot(fig)
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
- streamlit==0.80.0
2
  pysoundfile
3
  pedalboard
4
- librosa
 
 
1
+ streamlit
2
  pysoundfile
3
  pedalboard
4
+ librosa
5
+ matplotlib