Skip to content

Commit 9ba5bbc

Browse files
committed
Added parameter to pass through primary and secondary stem filepaths, fixed bug with log handlers
1 parent 52fd80c commit 9ba5bbc

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

audio_separator/separator.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(
2222
model_name="UVR_MDXNET_KARA_2",
2323
model_file_dir="/tmp/audio-separator-models/",
2424
output_dir=None,
25+
primary_stem_path=None,
26+
secondary_stem_path=None,
2527
use_cuda=False,
2628
use_coreml=False,
2729
output_format="WAV",
@@ -41,7 +43,9 @@ def __init__(
4143
self.log_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(module)s - %(message)s")
4244

4345
self.log_handler.setFormatter(self.log_formatter)
44-
self.logger.addHandler(self.log_handler)
46+
47+
if not self.logger.hasHandlers():
48+
self.logger.addHandler(self.log_handler)
4549

4650
self.logger.debug(
4751
f"Separator instantiating with input file: {audio_file_path}, model_name: {model_name}, output_dir: {output_dir}, use_cuda: {use_cuda}, output_format: {output_format}"
@@ -52,6 +56,8 @@ def __init__(
5256
self.output_dir = output_dir
5357
self.use_cuda = use_cuda
5458
self.use_coreml = use_coreml
59+
self.primary_stem_path = primary_stem_path
60+
self.secondary_stem_path = secondary_stem_path
5561

5662
# Create the model directory if it does not exist
5763
os.makedirs(self.model_file_dir, exist_ok=True)
@@ -206,17 +212,21 @@ def separate(self):
206212

207213
if not self.output_single_stem or self.output_single_stem.lower() == self.primary_stem.lower():
208214
self.logger.info(f"Saving {self.primary_stem} stem...")
209-
primary_stem_path = os.path.join(f"{self.audio_file_base}_({self.primary_stem})_{self.model_name}.{self.output_format.lower()}")
210-
self.write_audio(primary_stem_path, self.primary_source, samplerate)
211-
output_files.append(primary_stem_path)
215+
if not self.primary_stem_path:
216+
self.primary_stem_path = os.path.join(
217+
f"{self.audio_file_base}_({self.primary_stem})_{self.model_name}.{self.output_format.lower()}"
218+
)
219+
self.write_audio(self.primary_stem_path, self.primary_source, samplerate)
220+
output_files.append(self.primary_stem_path)
212221

213222
if not self.output_single_stem or self.output_single_stem.lower() == self.secondary_stem.lower():
214223
self.logger.info(f"Saving {self.secondary_stem} stem...")
215-
secondary_stem_path = os.path.join(
216-
f"{self.audio_file_base}_({self.secondary_stem})_{self.model_name}.{self.output_format.lower()}"
217-
)
218-
self.write_audio(secondary_stem_path, self.secondary_source, samplerate)
219-
output_files.append(secondary_stem_path)
224+
if not self.secondary_stem_path:
225+
self.secondary_stem_path = os.path.join(
226+
f"{self.audio_file_base}_({self.secondary_stem})_{self.model_name}.{self.output_format.lower()}"
227+
)
228+
self.write_audio(self.secondary_stem_path, self.secondary_source, samplerate)
229+
output_files.append(self.secondary_stem_path)
220230

221231
torch.cuda.empty_cache()
222232
return output_files

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "audio-separator"
3-
version = "0.7.2"
3+
version = "0.7.3"
44
description = "Easy to use vocal separation on CLI or as a python package, using the amazing MDX-Net models from UVR trained by @Anjok07"
55
authors = ["Andrew Beveridge <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)