Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,9 +132,7 @@ def match_loudness(audio_path, target_lufs=-14.0):
|
|
| 132 |
adjusted.export(out_path, format="wav")
|
| 133 |
return out_path
|
| 134 |
|
| 135 |
-
#
|
| 136 |
-
def auto_eq(audio, genre="Pop"):
|
| 137 |
-
# Define eq_map at the global scope
|
| 138 |
eq_map = {
|
| 139 |
"Pop": [(200, 500, -3), (2000, 4000, +4)],
|
| 140 |
"EDM": [(60, 250, +6), (8000, 12000, +3)],
|
|
@@ -157,6 +155,23 @@ eq_map = {
|
|
| 157 |
"Funk": [(80, 200, +5), (1000, 3000, +3)],
|
| 158 |
"Default": []
|
| 159 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
from scipy.signal import butter, sosfilt
|
| 161 |
def band_eq(samples, sr, lowcut, highcut, gain):
|
| 162 |
sos = butter(10, [lowcut, highcut], btype='band', output='sos', fs=sr)
|
|
|
|
| 132 |
adjusted.export(out_path, format="wav")
|
| 133 |
return out_path
|
| 134 |
|
| 135 |
+
# Define eq_map at the global scope
|
|
|
|
|
|
|
| 136 |
eq_map = {
|
| 137 |
"Pop": [(200, 500, -3), (2000, 4000, +4)],
|
| 138 |
"EDM": [(60, 250, +6), (8000, 12000, +3)],
|
|
|
|
| 155 |
"Funk": [(80, 200, +5), (1000, 3000, +3)],
|
| 156 |
"Default": []
|
| 157 |
}
|
| 158 |
+
|
| 159 |
+
# Auto-EQ per Genre function
|
| 160 |
+
def auto_eq(audio, genre="Pop"):
|
| 161 |
+
from scipy.signal import butter, sosfilt
|
| 162 |
+
|
| 163 |
+
def band_eq(samples, sr, lowcut, highcut, gain):
|
| 164 |
+
sos = butter(10, [lowcut, highcut], btype='band', output='sos', fs=sr)
|
| 165 |
+
filtered = sosfilt(sos, samples)
|
| 166 |
+
return samples + gain * filtered
|
| 167 |
+
|
| 168 |
+
samples, sr = audiosegment_to_array(audio)
|
| 169 |
+
samples = samples.astype(np.float64)
|
| 170 |
+
for band in eq_map.get(genre, []):
|
| 171 |
+
low, high, gain = band
|
| 172 |
+
samples = band_eq(samples, sr, low, high, gain)
|
| 173 |
+
return array_to_audiosegment(samples.astype(np.int16), sr, channels=audio.channels)
|
| 174 |
+
|
| 175 |
from scipy.signal import butter, sosfilt
|
| 176 |
def band_eq(samples, sr, lowcut, highcut, gain):
|
| 177 |
sos = butter(10, [lowcut, highcut], btype='band', output='sos', fs=sr)
|