Spaces:
Running
Running
jhj0517
commited on
Commit
·
b14146c
1
Parent(s):
fbcbf8a
Use original samplerate
Browse files
modules/uvr/music_separator.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# Credit to Team UVR : https://github.com/Anjok07/ultimatevocalremovergui
|
| 2 |
from typing import Optional
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
import os
|
| 5 |
import torch
|
|
@@ -16,7 +17,7 @@ class MusicSeparator:
|
|
| 16 |
self.available_devices = ["cpu", "cuda"]
|
| 17 |
self.model_dir = model_dir
|
| 18 |
self.output_dir = output_dir
|
| 19 |
-
self.
|
| 20 |
self.available_models = ["UVR-MDX-NET-Inst_1", "UVR-MDX-NET-Inst_HQ_1"]
|
| 21 |
self.default_model = self.available_models[0]
|
| 22 |
self.current_model_size = self.default_model
|
|
@@ -52,6 +53,9 @@ class MusicSeparator:
|
|
| 52 |
if device is None:
|
| 53 |
device = self.device
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
model_config = {
|
| 56 |
"segment": segment_size,
|
| 57 |
"split": True
|
|
@@ -73,8 +77,8 @@ class MusicSeparator:
|
|
| 73 |
instrumental_output_path = os.path.join(self.output_dir, "instrumental", filename)
|
| 74 |
vocals_output_path = os.path.join(self.output_dir, "vocals", filename)
|
| 75 |
|
| 76 |
-
sf.write(instrumental_output_path, instrumental,
|
| 77 |
-
sf.write(vocals_output_path, vocals,
|
| 78 |
|
| 79 |
return instrumental, vocals
|
| 80 |
|
|
|
|
| 1 |
# Credit to Team UVR : https://github.com/Anjok07/ultimatevocalremovergui
|
| 2 |
from typing import Optional
|
| 3 |
+
import torchaudio
|
| 4 |
import soundfile as sf
|
| 5 |
import os
|
| 6 |
import torch
|
|
|
|
| 17 |
self.available_devices = ["cpu", "cuda"]
|
| 18 |
self.model_dir = model_dir
|
| 19 |
self.output_dir = output_dir
|
| 20 |
+
self.audio_info = None
|
| 21 |
self.available_models = ["UVR-MDX-NET-Inst_1", "UVR-MDX-NET-Inst_HQ_1"]
|
| 22 |
self.default_model = self.available_models[0]
|
| 23 |
self.current_model_size = self.default_model
|
|
|
|
| 53 |
if device is None:
|
| 54 |
device = self.device
|
| 55 |
|
| 56 |
+
self.audio_info = torchaudio.info(audio_file_path)
|
| 57 |
+
sample_rate = self.audio_info.sample_rate
|
| 58 |
+
|
| 59 |
model_config = {
|
| 60 |
"segment": segment_size,
|
| 61 |
"split": True
|
|
|
|
| 77 |
instrumental_output_path = os.path.join(self.output_dir, "instrumental", filename)
|
| 78 |
vocals_output_path = os.path.join(self.output_dir, "vocals", filename)
|
| 79 |
|
| 80 |
+
sf.write(instrumental_output_path, instrumental, sample_rate, format="WAV")
|
| 81 |
+
sf.write(vocals_output_path, vocals, sample_rate, format="WAV")
|
| 82 |
|
| 83 |
return instrumental, vocals
|
| 84 |
|