mirror of
https://github.com/Anjok07/ultimatevocalremovergui.git
synced 2025-02-22 05:09:35 +01:00
Added CLI Support
This commit is contained in:
parent
1ce4949639
commit
c0239f6888
@ -11,7 +11,7 @@ from PySide2.QtWinExtras import (QWinTaskbarButton)
|
||||
# -Root imports-
|
||||
from .resources.resources_manager import ResourcePaths
|
||||
from .windows import (mainwindow, settingswindow)
|
||||
from .inference import converter_v4_copy as converter_v4
|
||||
from .inference import converter_v4
|
||||
# -Other-
|
||||
import datetime as dt
|
||||
from collections import defaultdict
|
||||
@ -263,7 +263,7 @@ class CustomApplication(QtWidgets.QApplication):
|
||||
resType = resType.lower().replace(' ', '_')
|
||||
seperation_data['resType'] = resType
|
||||
|
||||
if set(converter_v4.default_data.keys()) != set(seperation_data.keys()):
|
||||
if set(seperation_data.keys()) != set(converter_v4.default_data.keys()):
|
||||
self.debug_to_command(f'Extracted Keys do not equal keys set by default converter!\nExtracted Keys: {sorted(list(seperation_data.keys()))}\nShould be Keys: {sorted(list(converter_v4.default_data.keys()))}',
|
||||
priority=1)
|
||||
|
||||
|
@ -80,7 +80,6 @@ class VocalRemover:
|
||||
# Updated on every conversion or loop
|
||||
self.loop_data = {
|
||||
# File specific
|
||||
'file_path': None,
|
||||
'file_base_name': None,
|
||||
'file_num': 0,
|
||||
# Loop specific
|
||||
@ -108,6 +107,8 @@ class VocalRemover:
|
||||
'wav_instrument': None,
|
||||
'y_spec': None,
|
||||
'v_spec': None,
|
||||
# Spectogram from last seperation
|
||||
'temp_spectogramm': None,
|
||||
}
|
||||
|
||||
def seperate_files(self):
|
||||
@ -166,26 +167,27 @@ class VocalRemover:
|
||||
file_num is used to determine progress
|
||||
"""
|
||||
|
||||
self.loop_data['file_num'] = file_num
|
||||
file_data = self._get_path_data(file_path)
|
||||
# -Update file specific variables-
|
||||
self.loop_data['file_path'] = file_data['file_path']
|
||||
self.loop_data['file_base_name'] = file_data['file_base_name']
|
||||
self.loop_data['file_num'] = file_num
|
||||
self.loop_data['music_file'] = file_path
|
||||
self.loop_data['file_base_name'] = self._get_file_base_name(file_path)
|
||||
|
||||
for loop_num in range(self.general_data['total_loops']):
|
||||
self.loop_data['loop_num'] = loop_num
|
||||
# -Get loop specific variables-
|
||||
command_base_text = self._get_base_text()
|
||||
model_device, music_file = self._get_model_device_file()
|
||||
model_device = self._get_model_device_file()
|
||||
constants = self._get_constants(model_device['model_name'])
|
||||
# -Update loop specific variables
|
||||
self.loop_data['constants'] = constants
|
||||
self.loop_data['command_base_text'] = command_base_text
|
||||
self.loop_data['model_device'] = model_device
|
||||
self.loop_data['music_file'] = music_file
|
||||
|
||||
# -Seperation-
|
||||
self._load_wave_source()
|
||||
if not self.loop_data['loop_num']:
|
||||
print('A')
|
||||
# First loop
|
||||
self._load_wave_source()
|
||||
self._wave_to_spectogram()
|
||||
if self.seperation_data['postProcess']:
|
||||
# Postprocess
|
||||
@ -196,7 +198,6 @@ class VocalRemover:
|
||||
# End of seperation
|
||||
if self.seperation_data['outputImage']:
|
||||
self._save_mask()
|
||||
os.remove('temp.wav')
|
||||
|
||||
self.write_to_gui(text='Completed Seperation!\n',
|
||||
progress_step=1)
|
||||
@ -394,7 +395,7 @@ class VocalRemover:
|
||||
|
||||
return seperation_params
|
||||
|
||||
def _get_model_device_file(self) -> Tuple[dict, str]:
|
||||
def _get_model_device_file(self) -> dict:
|
||||
"""
|
||||
Get the used models and devices for this loop
|
||||
Also extract the model name and the music file
|
||||
@ -406,8 +407,6 @@ class VocalRemover:
|
||||
'model_name': None,
|
||||
}
|
||||
|
||||
music_file = self.loop_data['file_path']
|
||||
|
||||
if not self.loop_data['loop_num']:
|
||||
# First Iteration
|
||||
if self.seperation_data['stackOnly']:
|
||||
@ -427,24 +426,14 @@ class VocalRemover:
|
||||
model_device['model'] = self.general_data['models']['stack']
|
||||
model_device['device'] = self.general_data['devices']['stack']
|
||||
model_device['model_name'] = os.path.basename(self.seperation_data['stackModel'])
|
||||
# Reference new music file
|
||||
music_file = 'temp.wav'
|
||||
|
||||
return model_device, music_file
|
||||
return model_device
|
||||
|
||||
def _get_path_data(self, file_path: str) -> Dict[str, str]:
|
||||
def _get_file_base_name(self, file_path: str) -> str:
|
||||
"""
|
||||
Get the path infos for the given music file
|
||||
"""
|
||||
file_data = {
|
||||
'file_path': None,
|
||||
'file_base_name': None,
|
||||
}
|
||||
# -Get Data-
|
||||
file_data['file_path'] = file_path
|
||||
file_data['file_base_name'] = f"{self.loop_data['file_num']}_{os.path.splitext(os.path.basename(file_path))[0]}"
|
||||
|
||||
return file_data
|
||||
return f"{self.loop_data['file_num']}_{os.path.splitext(os.path.basename(file_path))[0]}"
|
||||
|
||||
# -Seperation Methods-
|
||||
def _load_wave_source(self):
|
||||
@ -572,9 +561,13 @@ class VocalRemover:
|
||||
self.write_to_gui(text='Stft of wave source...',
|
||||
progress_step=0.1)
|
||||
|
||||
X = spec_utils.wave_to_spectrogram(wave=self.loop_data['X'],
|
||||
hop_length=self.seperation_data['hop_length'],
|
||||
n_fft=self.seperation_data['n_fft'])
|
||||
if not self.loop_data['loop_num']:
|
||||
X = spec_utils.wave_to_spectrogram(wave=self.loop_data['X'],
|
||||
hop_length=self.seperation_data['hop_length'],
|
||||
n_fft=self.seperation_data['n_fft'])
|
||||
else:
|
||||
X = self.loop_data['temp_spectogramm']
|
||||
|
||||
if self.seperation_data['tta']:
|
||||
prediction, X_mag, X_phase = inference_tta(X_spec=X,
|
||||
device=self.loop_data['model_device']['device'],
|
||||
@ -627,6 +620,7 @@ class VocalRemover:
|
||||
self.loop_data['y_spec'] = y_spec
|
||||
self.loop_data['v_spec'] = v_spec
|
||||
|
||||
self.loop_data['temp_spectogramm'] = y_spec
|
||||
self.write_to_gui(text='Done!',
|
||||
progress_step=0.9)
|
||||
|
||||
@ -702,13 +696,6 @@ class VocalRemover:
|
||||
|
||||
vocal_name, instrumental_name, folder_path = get_vocal_instrumental_name()
|
||||
|
||||
# Save Temp File
|
||||
# For instrumental the instrumental is the temp file
|
||||
# and for vocal the instrumental is the temp file due
|
||||
# to reversement
|
||||
sf.write(f'temp.wav',
|
||||
self.loop_data['wav_instrument'].T, self.loop_data['sampling_rate'])
|
||||
|
||||
# -Save files-
|
||||
# Instrumental
|
||||
if instrumental_name is not None:
|
||||
|
@ -80,6 +80,7 @@ class VocalRemover:
|
||||
# Updated on every conversion or loop
|
||||
self.loop_data = {
|
||||
# File specific
|
||||
'file_path': None,
|
||||
'file_base_name': None,
|
||||
'file_num': 0,
|
||||
# Loop specific
|
||||
@ -107,8 +108,6 @@ class VocalRemover:
|
||||
'wav_instrument': None,
|
||||
'y_spec': None,
|
||||
'v_spec': None,
|
||||
# Spectogram from last seperation
|
||||
'temp_spectogramm': None,
|
||||
}
|
||||
|
||||
def seperate_files(self):
|
||||
@ -167,27 +166,26 @@ class VocalRemover:
|
||||
file_num is used to determine progress
|
||||
"""
|
||||
|
||||
# -Update file specific variables-
|
||||
self.loop_data['file_num'] = file_num
|
||||
self.loop_data['music_file'] = file_path
|
||||
self.loop_data['file_base_name'] = self._get_file_base_name(file_path)
|
||||
file_data = self._get_path_data(file_path)
|
||||
# -Update file specific variables-
|
||||
self.loop_data['file_path'] = file_data['file_path']
|
||||
self.loop_data['file_base_name'] = file_data['file_base_name']
|
||||
|
||||
for loop_num in range(self.general_data['total_loops']):
|
||||
self.loop_data['loop_num'] = loop_num
|
||||
# -Get loop specific variables-
|
||||
command_base_text = self._get_base_text()
|
||||
model_device = self._get_model_device_file()
|
||||
model_device, music_file = self._get_model_device_file()
|
||||
constants = self._get_constants(model_device['model_name'])
|
||||
# -Update loop specific variables
|
||||
self.loop_data['constants'] = constants
|
||||
self.loop_data['command_base_text'] = command_base_text
|
||||
self.loop_data['model_device'] = model_device
|
||||
self.loop_data['music_file'] = music_file
|
||||
|
||||
# -Seperation-
|
||||
if not self.loop_data['loop_num']:
|
||||
print('A')
|
||||
# First loop
|
||||
self._load_wave_source()
|
||||
self._load_wave_source()
|
||||
self._wave_to_spectogram()
|
||||
if self.seperation_data['postProcess']:
|
||||
# Postprocess
|
||||
@ -198,6 +196,7 @@ class VocalRemover:
|
||||
# End of seperation
|
||||
if self.seperation_data['outputImage']:
|
||||
self._save_mask()
|
||||
os.remove('temp.wav')
|
||||
|
||||
self.write_to_gui(text='Completed Seperation!\n',
|
||||
progress_step=1)
|
||||
@ -395,7 +394,7 @@ class VocalRemover:
|
||||
|
||||
return seperation_params
|
||||
|
||||
def _get_model_device_file(self) -> dict:
|
||||
def _get_model_device_file(self) -> Tuple[dict, str]:
|
||||
"""
|
||||
Get the used models and devices for this loop
|
||||
Also extract the model name and the music file
|
||||
@ -407,6 +406,8 @@ class VocalRemover:
|
||||
'model_name': None,
|
||||
}
|
||||
|
||||
music_file = self.loop_data['file_path']
|
||||
|
||||
if not self.loop_data['loop_num']:
|
||||
# First Iteration
|
||||
if self.seperation_data['stackOnly']:
|
||||
@ -426,14 +427,24 @@ class VocalRemover:
|
||||
model_device['model'] = self.general_data['models']['stack']
|
||||
model_device['device'] = self.general_data['devices']['stack']
|
||||
model_device['model_name'] = os.path.basename(self.seperation_data['stackModel'])
|
||||
# Reference new music file
|
||||
music_file = 'temp.wav'
|
||||
|
||||
return model_device
|
||||
return model_device, music_file
|
||||
|
||||
def _get_file_base_name(self, file_path: str) -> str:
|
||||
def _get_path_data(self, file_path: str) -> Dict[str, str]:
|
||||
"""
|
||||
Get the path infos for the given music file
|
||||
"""
|
||||
return f"{self.loop_data['file_num']}_{os.path.splitext(os.path.basename(file_path))[0]}"
|
||||
file_data = {
|
||||
'file_path': None,
|
||||
'file_base_name': None,
|
||||
}
|
||||
# -Get Data-
|
||||
file_data['file_path'] = file_path
|
||||
file_data['file_base_name'] = f"{self.loop_data['file_num']}_{os.path.splitext(os.path.basename(file_path))[0]}"
|
||||
|
||||
return file_data
|
||||
|
||||
# -Seperation Methods-
|
||||
def _load_wave_source(self):
|
||||
@ -561,13 +572,9 @@ class VocalRemover:
|
||||
self.write_to_gui(text='Stft of wave source...',
|
||||
progress_step=0.1)
|
||||
|
||||
if not self.loop_data['loop_num']:
|
||||
X = spec_utils.wave_to_spectrogram(wave=self.loop_data['X'],
|
||||
hop_length=self.seperation_data['hop_length'],
|
||||
n_fft=self.seperation_data['n_fft'])
|
||||
else:
|
||||
X = self.loop_data['temp_spectogramm']
|
||||
|
||||
X = spec_utils.wave_to_spectrogram(wave=self.loop_data['X'],
|
||||
hop_length=self.seperation_data['hop_length'],
|
||||
n_fft=self.seperation_data['n_fft'])
|
||||
if self.seperation_data['tta']:
|
||||
prediction, X_mag, X_phase = inference_tta(X_spec=X,
|
||||
device=self.loop_data['model_device']['device'],
|
||||
@ -620,7 +627,6 @@ class VocalRemover:
|
||||
self.loop_data['y_spec'] = y_spec
|
||||
self.loop_data['v_spec'] = v_spec
|
||||
|
||||
self.loop_data['temp_spectogramm'] = y_spec
|
||||
self.write_to_gui(text='Done!',
|
||||
progress_step=0.9)
|
||||
|
||||
@ -696,6 +702,13 @@ class VocalRemover:
|
||||
|
||||
vocal_name, instrumental_name, folder_path = get_vocal_instrumental_name()
|
||||
|
||||
# Save Temp File
|
||||
# For instrumental the instrumental is the temp file
|
||||
# and for vocal the instrumental is the temp file due
|
||||
# to reversement
|
||||
sf.write(f'temp.wav',
|
||||
self.loop_data['wav_instrument'].T, self.loop_data['sampling_rate'])
|
||||
|
||||
# -Save files-
|
||||
# Instrumental
|
||||
if instrumental_name is not None:
|
37
uvrcli.py
37
uvrcli.py
@ -1,37 +0,0 @@
|
||||
"""
|
||||
Argumentparser version of UVR
|
||||
"""
|
||||
import argparse
|
||||
import sys
|
||||
from src.inference.converter_v4 import (VocalRemover, default_data)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='This is the terminal version of UVR.')
|
||||
# -IO-
|
||||
parser.add_argument('-i', '--inputs', metavar='InputPath/s', type=str, nargs='+',
|
||||
required=True, dest='input_paths',
|
||||
help='Path to music file/s')
|
||||
parser.add_argument('-o', '--output', metavar='ExportPath', type=str, nargs=1,
|
||||
required=True, dest='export_path',
|
||||
help='Path to output directory')
|
||||
# -Models-
|
||||
parser.add_argument('-inst', '--instrumentalModel', metavar='InstrumentalPath', type=str, nargs=1,
|
||||
required=True, dest='instrumentalModel',
|
||||
help='Path to instrumental model')
|
||||
parser.add_argument('-stacked', '--stackedModel', metavar='StackedPath', type=str, nargs=1,
|
||||
required=False, dest='stackModel',
|
||||
help='Path to stacked model')
|
||||
# -Settings-
|
||||
# parser.add_argument('--sum', dest='accumulate', action='store_const',
|
||||
# const=sum, default=max,
|
||||
# help='sum the integers (default: find the max)')
|
||||
args = parser.parse_args()
|
||||
# seperation_data = default_data.copy()
|
||||
# seperation_data['input_paths'] = [r'']
|
||||
# seperation_data['export_path'] = r''
|
||||
# seperation_data['instrumentalModel'] = r''
|
||||
# seperation_data['stackPasses'] = 0
|
||||
# seperation_data['stackModel'] = r''
|
||||
|
||||
# vocal_remover = VocalRemover(data=seperation_data)
|
||||
# vocal_remover.seperate_files()
|
Loading…
x
Reference in New Issue
Block a user