github-actions[bot]
commited on
Commit
·
207cecb
1
Parent(s):
dc58474
Sync from GitHub: eebedee86b0a587bb5ba0d09a2c9b9c613e53af4
Browse files- main.py +3 -2
- services/audio_separator.py +8 -2
main.py
CHANGED
|
@@ -158,7 +158,7 @@ def process_audio(file_id: str, background_tasks: BackgroundTasks, mode: str = "
|
|
| 158 |
def progress_cb(step, prog):
|
| 159 |
update_progress(file_id, step, prog)
|
| 160 |
|
| 161 |
-
stems = separator.separate(input_path, output_dir, callback=progress_cb, mode=mode)
|
| 162 |
|
| 163 |
update_progress(file_id, "Analyzing Rhythm...", 50)
|
| 164 |
|
|
@@ -197,7 +197,8 @@ def process_audio(file_id: str, background_tasks: BackgroundTasks, mode: str = "
|
|
| 197 |
"stems": stems_url,
|
| 198 |
"midi": midi_files,
|
| 199 |
"bpm": bpm,
|
| 200 |
-
"beats": beats
|
|
|
|
| 201 |
}
|
| 202 |
print(f"Final Data for {file_id}: {final_data}") # Debug
|
| 203 |
update_progress(file_id, "Completed", 100, status="completed", data=final_data)
|
|
|
|
| 158 |
def progress_cb(step, prog):
|
| 159 |
update_progress(file_id, step, prog)
|
| 160 |
|
| 161 |
+
stems, duration = separator.separate(input_path, output_dir, callback=progress_cb, mode=mode)
|
| 162 |
|
| 163 |
update_progress(file_id, "Analyzing Rhythm...", 50)
|
| 164 |
|
|
|
|
| 197 |
"stems": stems_url,
|
| 198 |
"midi": midi_files,
|
| 199 |
"bpm": bpm,
|
| 200 |
+
"beats": beats,
|
| 201 |
+
"duration": duration
|
| 202 |
}
|
| 203 |
print(f"Final Data for {file_id}: {final_data}") # Debug
|
| 204 |
update_progress(file_id, "Completed", 100, status="completed", data=final_data)
|
services/audio_separator.py
CHANGED
|
@@ -124,7 +124,8 @@ class AudioSeparator:
|
|
| 124 |
self._save_audio(source, sr, stem_path)
|
| 125 |
results[name] = stem_path
|
| 126 |
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
def _process_guitar(self, source, sr, output_dir):
|
| 130 |
"""
|
|
@@ -226,7 +227,12 @@ class AudioSeparator:
|
|
| 226 |
# source is tensor (channels, samples) on device
|
| 227 |
# Move to cpu
|
| 228 |
source = source.cpu()
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
# Save using soundfile
|
| 231 |
# source is (channels, samples) -> need (samples, channels)
|
| 232 |
import soundfile as sf
|
|
|
|
| 124 |
self._save_audio(source, sr, stem_path)
|
| 125 |
results[name] = stem_path
|
| 126 |
|
| 127 |
+
input_duration = len(wav_np) / sr
|
| 128 |
+
return results, input_duration
|
| 129 |
|
| 130 |
def _process_guitar(self, source, sr, output_dir):
|
| 131 |
"""
|
|
|
|
| 227 |
# source is tensor (channels, samples) on device
|
| 228 |
# Move to cpu
|
| 229 |
source = source.cpu()
|
| 230 |
+
|
| 231 |
+
# Normalize to prevent clipping (limit to -1dB peak)
|
| 232 |
+
peak = source.abs().max()
|
| 233 |
+
if peak > 0.89: # approx -1dB
|
| 234 |
+
source = source / peak * 0.89
|
| 235 |
+
|
| 236 |
# Save using soundfile
|
| 237 |
# source is (channels, samples) -> need (samples, channels)
|
| 238 |
import soundfile as sf
|