Skip to content

Commit 8b0d9b0

Browse files
committed
Added download only function, fixed bug in VR arch
1 parent c62ca74 commit 8b0d9b0

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

audio_separator/separator/architectures/vr_separator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def separate(self, audio_file_path):
181181
if self.output_single_stem and (self.output_single_stem.lower() != self.primary_stem_name.lower() and self.output_single_stem.lower() != self.secondary_stem_name.lower()):
182182
# If so, reset output_single_stem to None to save both stems
183183
self.output_single_stem = None
184-
self.logger.warning(f"The output_single_stem setting '{self.output_single_stem}' does not match any of the output files: '{self.primary_stem_name}' and '{self.secondary_stem_name}'. For this model '{self.model_name}' with architecture '{self.arch_name}', the output_single_stem setting will be ignored and all output files will be saved.")
184+
self.logger.warning(f"The output_single_stem setting '{self.output_single_stem}' does not match any of the output files: '{self.primary_stem_name}' and '{self.secondary_stem_name}'. For this model '{self.model_name}', the output_single_stem setting will be ignored and all output files will be saved.")
185185

186186
# Save and process the primary stem if needed
187187
if not self.output_single_stem or self.output_single_stem.lower() == self.primary_stem_name.lower():

audio_separator/separator/separator.py

+20
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,23 @@ def separate(self, audio_file_path):
718718
self.logger.info(f'Separation duration: {time.strftime("%H:%M:%S", time.gmtime(int(time.perf_counter() - separate_start_time)))}')
719719

720720
return output_files
721+
722+
def download_model_and_data(self, model_filename):
723+
"""
724+
Downloads the model file without loading it into memory.
725+
"""
726+
self.logger.info(f"Downloading model {model_filename}...")
727+
728+
model_filename, model_type, model_friendly_name, model_path, yaml_config_filename = self.download_model_files(model_filename)
729+
730+
if model_path.lower().endswith(".yaml"):
731+
yaml_config_filename = model_path
732+
733+
if yaml_config_filename is not None:
734+
model_data = self.load_model_data_from_yaml(yaml_config_filename)
735+
else:
736+
model_data = self.load_model_data_using_hash(model_path)
737+
738+
model_data_dict_size = len(model_data)
739+
740+
self.logger.info(f"Model downloaded, type: {model_type}, friendly name: {model_friendly_name}, model_path: {model_path}, model_data: {model_data_dict_size} items")

audio_separator/utils/cli.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ def main():
3838
output_format_help = "output format for separated files, any common format (default: %(default)s). Example: --output_format=MP3"
3939
output_dir_help = "directory to write output files (default: <current dir>). Example: --output_dir=/app/separated"
4040
model_file_dir_help = "model files directory (default: %(default)s). Example: --model_file_dir=/app/models"
41+
download_model_only_help = "Download a single model file only, without performing separation."
4142

4243
io_params = parser.add_argument_group("Separation I/O Params")
43-
io_params.add_argument("-m", "--model_filename", default="model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt", help=model_filename_help)
44+
io_params.add_argument("-m", "--model_filename", default="model_bs_roformer_ep_317_sdr_12.9755.yaml", help=model_filename_help)
4445
io_params.add_argument("--output_format", default="FLAC", help=output_format_help)
4546
io_params.add_argument("--output_dir", default=None, help=output_dir_help)
4647
io_params.add_argument("--model_file_dir", default="/tmp/audio-separator-models/", help=model_file_dir_help)
48+
io_params.add_argument("--download_model_only", action="store_true", help=download_model_only_help)
4749

4850
invert_spect_help = "invert secondary stem using spectogram (default: %(default)s). Example: --invert_spect"
4951
normalization_help = "max peak amplitude to normalize input and output audio to (default: %(default)s). Example: --normalization=0.7"
@@ -130,12 +132,19 @@ def main():
130132
print(json.dumps(separator.list_supported_model_files(), indent=4, sort_keys=True))
131133
sys.exit(0)
132134

135+
if args.download_model_only:
136+
logger.info(f"Separator version {package_version} downloading model {args.model_filename} to directory {args.model_file_dir}")
137+
separator = Separator(log_formatter=log_formatter, log_level=log_level, model_file_dir=args.model_file_dir)
138+
separator.download_model_and_data(args.model_filename)
139+
logger.info(f"Model {args.model_filename} downloaded successfully.")
140+
sys.exit(0)
141+
142+
logger.info(f"Separator version {package_version} beginning with input file: {args.audio_file}")
143+
133144
if not hasattr(args, "audio_file"):
134145
parser.print_help()
135146
sys.exit(1)
136147

137-
logger.info(f"Separator version {package_version} beginning with input file: {args.audio_file}")
138-
139148
separator = Separator(
140149
log_formatter=log_formatter,
141150
log_level=log_level,

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "audio-separator"
7-
version = "0.17.6"
7+
version = "0.18.0"
88
description = "Easy to use audio stem separation, using various models from UVR trained primarily by @Anjok07"
99
authors = ["Andrew Beveridge <[email protected]>"]
1010
license = "MIT"

0 commit comments

Comments
 (0)