Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
aa00058
1
Parent(s):
a9d7ba1
melodyflow loudness fix
Browse files
app.py
CHANGED
|
@@ -188,12 +188,21 @@ def transform_with_melodyflow_api(audio_path, variation, custom_prompt="", solve
|
|
| 188 |
# Result is a tuple of 3 audio files (variations)
|
| 189 |
# We'll use the first variation
|
| 190 |
if result and len(result) > 0 and result[0]:
|
| 191 |
-
# Save the result locally
|
| 192 |
output_filename = f"melodyflow_{variation}_{random.randint(1000, 9999)}.wav"
|
| 193 |
|
| 194 |
-
#
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
return output_filename, status_msg
|
| 199 |
else:
|
|
|
|
| 188 |
# Result is a tuple of 3 audio files (variations)
|
| 189 |
# We'll use the first variation
|
| 190 |
if result and len(result) > 0 and result[0]:
|
| 191 |
+
# Save the result locally with loudness normalization
|
| 192 |
output_filename = f"melodyflow_{variation}_{random.randint(1000, 9999)}.wav"
|
| 193 |
|
| 194 |
+
# Load the result and apply consistent loudness normalization
|
| 195 |
+
transformed_audio, sr = torchaudio.load(result[0])
|
| 196 |
+
|
| 197 |
+
# Re-save with same loudness strategy as your MusicGen (no headroom)
|
| 198 |
+
audio_write(
|
| 199 |
+
output_filename.replace('.wav', ''),
|
| 200 |
+
transformed_audio,
|
| 201 |
+
sr,
|
| 202 |
+
strategy="loudness",
|
| 203 |
+
loudness_compressor=True
|
| 204 |
+
# Note: no loudness_headroom_db parameter like Facebook uses
|
| 205 |
+
)
|
| 206 |
|
| 207 |
return output_filename, status_msg
|
| 208 |
else:
|