diff --git a/log_error.log b/log_error.log new file mode 100644 index 0000000..876e829 --- /dev/null +++ b/log_error.log @@ -0,0 +1,85 @@ +(venv) PS D:\AI\Ultimate Vocal Remover> python -m uvr_cli run -a "D:\AI\UVR\Experiments\exp_1\edited_remixed_audio-2.wav" -m UVR-MDX-NET-Inst_HQ_4.onnx -p fp32 -d cpu --segment-size 4000 --overlap 0.25 -o D:\AI\UVR\Experiments\exp_1\out +Resolving model: UVR-MDX-NET-Inst_HQ_4.onnx (MDX-Net) +Separating : edited_remixed_audio-2.wav +Precision : Ultra Quality (FP32) +Output folder : D:\AI\UVR\Experiments\exp_1\out + +[!] Output file(s) already exist: + -> edited_remixed_audio-2_(Instrumental).wav + -> edited_remixed_audio-2_(Vocals).wav + +Overwrite? [Y/N]: y +[DIAGNOSTIC] === SeperateMDX.seperate Start === +[DIAGNOSTIC] Initial GPU Alloc: 0.00 MB, Reserved: 0.00 MB +[DIAGNOSTIC] Cache keys currently stored: [] +[DIAGNOSTIC] get_model lookup: D:\AI\Ultimate Vocal Remover\models\MDX_Net_Models\UVR-MDX-NET-Inst_HQ_4.onnx -> normalized: D:\AI\Ultimate Vocal Remover\models\MDX_Net_Models\UVR-MDX-NET-Inst_HQ_4.onnx +[DIAGNOSTIC] get_model Cache Miss for: D:\AI\Ultimate Vocal Remover\models\MDX_Net_Models\UVR-MDX-NET-Inst_HQ_4.onnx +Model Cache Store: Resident model cached UVR-MDX-NET-Inst_HQ_4.onnx (precision: Ultra Quality (FP32)) +[PRECISION] === Runtime Precision Report === +[PRECISION] requested_mode: FP32 +[PRECISION] effective_mode: FP32 +[PRECISION] model_type: ONNX +[PRECISION] execution_provider: ['CPUExecutionProvider'] +[PRECISION] onnx_input_type: tensor(float) +[PRECISION] onnx_output_type: tensor(float) +[PRECISION] active_providers: ['CPUExecutionProvider'] +[PRECISION] [OK] Precision applied correctly: FP32 +[PRECISION] ============================== +[UVR Core] Done! + +[UVR Core] Running inference... +Traceback (most recent call last): + File "", line 198, in _run_module_as_main + File "", line 88, in _run_code + File "D:\AI\Ultimate Vocal Remover\uvr_cli\__main__.py", line 6, in + main() + File "D:\AI\Ultimate Vocal Remover\uvr_cli\cli.py", line 330, in main + sys.exit(handle_run(args)) + ^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\uvr_cli\cli.py", line 142, in handle_run + stems, is_valid = execute_inference( + ^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\uvr_cli\runner.py", line 165, in execute_inference + separator.seperate() + File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + ^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\separate.py", line 1068, in demix + stream_transfer = torch.cuda.Stream(device=self.device) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\venv\Lib\site-packages\torch\cuda\streams.py", line 45, in __new__ + with torch.cuda.device(device): + File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + ^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\separate.py", line 1068, in demix + stream_transfer = torch.cuda.Stream(device=self.device) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\venv\Lib\site-packages\torch\cuda\streams.py", line 45 File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + ^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\separate.py", line 1068, in demix + stream_transfer = torch.cuda.Stream(device=self.device) + File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + ^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\separate.py", line 1068, in demix + stream_transfer = torch.cuda.Stream(device=self.device) + File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + File "D:\AI\Ultimate Vocal Remover\separate.py", line 940, in seperate + source = self.demix(mix) + ^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\separate.py", line 1068, in demix + stream_transfer = torch.cuda.Stream(device=self.device) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\venv\Lib\site-packages\torch\cuda\streams.py", line 45, in __new__ + with torch.cuda.device(device): + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\venv\Lib\site-packages\torch\cuda\__init__.py", line 600, in __init__ + self.idx = _get_device_index(device, optional=True) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\AI\Ultimate Vocal Remover\venv\Lib\site-packages\torch\cuda\_utils.py", line 542, in _get_device_index + raise ValueError(f"Expected a cuda device, but got: {device}") +ValueError: Expected a cuda device, but got: cpu +[DIAGNOSTIC] === SeperateAttributes Destructor Called for: UVR-MDX-NET-Inst_HQ_4 === \ No newline at end of file diff --git a/tests/test_uvr_cli.py b/tests/test_uvr_cli.py index 405c909..3d24d33 100644 --- a/tests/test_uvr_cli.py +++ b/tests/test_uvr_cli.py @@ -16,6 +16,7 @@ from uvr_cli.model_resolver import ( list_available_models, resolve_model_file, ) +from uvr_cli.runner import get_existing_outputs, get_expected_stem_paths from uvr_cli.telemetry import TelemetrySampler, collect_system_info @@ -104,7 +105,6 @@ class BenchmarkCLITests(unittest.TestCase): "audio_file": "sample.wav", "audio_duration_sec": 10.0, "round": "1", - "cache_state": "cold", "total_time_sec": 2.5, "inference_time_sec": 2.5, "speed_factor_rt": 4.0, @@ -154,6 +154,51 @@ class BenchmarkCLITests(unittest.TestCase): self.assertEqual(args_bench.rounds, 3) self.assertEqual(args_bench.warmup, 1) + # Test 'run' with --overwrite and -y + args_run_ow = parser.parse_args([ + "run", + "--audio", "test.wav", + "--model", "UVR-MDX-NET-Inst_HQ_4.onnx", + "--overwrite", + ]) + self.assertTrue(args_run_ow.overwrite) + + args_run_y = parser.parse_args([ + "run", + "-a", "test.wav", + "-m", "UVR-MDX-NET-Inst_HQ_4.onnx", + "-y", + ]) + self.assertTrue(args_run_y.overwrite) + + def test_expected_stem_paths_and_existing_outputs(self): + with tempfile.TemporaryDirectory() as temp_dir: + temp_path = Path(temp_dir) + dummy_audio = temp_path / "song.wav" + dummy_audio.touch() + + model_data = HeadlessModelData( + primary_stem="Instrumental", + secondary_stem="Vocals", + ) + + expected = get_expected_stem_paths(model_data, dummy_audio, temp_path) + expected_names = [p.name for p in expected] + self.assertIn("song_(Instrumental).wav", expected_names) + self.assertIn("song_(Vocals).wav", expected_names) + + # Initially no files exist + existing = get_existing_outputs(model_data, dummy_audio, temp_path) + self.assertEqual(len(existing), 0) + + # Create one stem + stem1 = temp_path / "song_(Instrumental).wav" + stem1.touch() + + existing = get_existing_outputs(model_data, dummy_audio, temp_path) + self.assertEqual(len(existing), 1) + self.assertEqual(existing[0].name, "song_(Instrumental).wav") + def test_synthetic_audio_creation(self): audio_path = create_synthetic_audio(duration_sec=1.0, samplerate=44100) try: diff --git a/uvr_cli/README.md b/uvr_cli/README.md index c8078c2..b14d5f0 100644 --- a/uvr_cli/README.md +++ b/uvr_cli/README.md @@ -52,7 +52,17 @@ venv\Scripts\python.exe -m uvr_cli run ` --device cuda:0 ` --output-dir "separated_outputs" ``` -Supported precisions: `fp32`, `fp16`, `fp8_e4m3`, `nvfp4`. +Supported precisions: `fp32`, `fp16`, `bf16`. + +If destination stem files already exist in `--output-dir`, the CLI will prompt: +`Overwrite? [Y/N]: ` +To automatically overwrite without interactive confirmation, pass `--overwrite` or `-y`: +```powershell +venv\Scripts\python.exe -m uvr_cli run ` + --audio "path/to/song.wav" ` + --model "UVR-MDX-NET-Inst_HQ_4.onnx" ` + --overwrite +``` ### 3. Real Performance Benchmark Benchmark one or more models across multiple rounds with warmup: diff --git a/uvr_cli/__init__.py b/uvr_cli/__init__.py index 49fa234..7a32f9f 100644 --- a/uvr_cli/__init__.py +++ b/uvr_cli/__init__.py @@ -11,7 +11,12 @@ from .model_resolver import ( list_available_models, resolve_model_file, ) -from .runner import execute_inference, get_audio_metadata +from .runner import ( + execute_inference, + get_audio_metadata, + get_existing_outputs, + get_expected_stem_paths, +) from .telemetry import TelemetrySampler, collect_system_info, sync_cuda __version__ = "2.0.0" @@ -27,6 +32,8 @@ __all__ = [ "export_benchmark_csv", "export_benchmark_json", "get_audio_metadata", + "get_existing_outputs", + "get_expected_stem_paths", "list_available_models", "resolve_model_file", "sanitize_path", diff --git a/uvr_cli/cli.py b/uvr_cli/cli.py index 38cbd75..c23d886 100644 --- a/uvr_cli/cli.py +++ b/uvr_cli/cli.py @@ -24,16 +24,13 @@ from uvr_cli.model_resolver import ( list_available_models, resolve_model_file, ) -from uvr_cli.runner import execute_inference +from uvr_cli.runner import execute_inference, get_existing_outputs # Map shorthand precision arguments to UVR canonical precision strings PRECISION_MAP = { "fp32": MODEL_PRECISION_FP32, "fp16": MODEL_PRECISION_FP16, "bf16": MODEL_PRECISION_BF16, - "fp8": "Performance (FP8-E4M3)", - "fp8_e4m3": "Performance (FP8-E4M3)", - "nvfp4": "Performance (NVFP4)", } @@ -109,15 +106,45 @@ def handle_run(args: argparse.Namespace) -> int: audio_path = Path(args.audio).resolve() output_dir = Path(args.output_dir).resolve() + if not audio_path.is_file(): + print(f"[ERROR] Input audio file not found: {audio_path}") + return 1 + print(f"Separating : {audio_path.name}") print(f"Precision : {precision}") print(f"Output folder : {output_dir}") + # Check for existing conflicting output stems + existing_outputs = get_existing_outputs(model_data, audio_path, output_dir) + overwrite = getattr(args, "overwrite", False) + + if existing_outputs and not overwrite: + print(f"\n[!] Output file(s) already exist:") + for f in existing_outputs: + print(f" -> {f.name}") + + if not sys.stdin.isatty(): + print(f"\n[ERROR] Output files already exist. Use '--overwrite' or '-y' to overwrite.") + return 1 + + try: + choice = input("\nOverwrite? [Y/N]: ").strip().lower() + except (EOFError, KeyboardInterrupt): + print("\n[INFO] Operation cancelled.") + return 0 + + if choice in ("y", "yes"): + overwrite = True + else: + print("[INFO] Separation cancelled. Existing files were preserved.") + return 0 + stems, is_valid = execute_inference( model_data=model_data, audio_path=audio_path, export_dir=output_dir, console_callback=lambda text, base="": print(f"[UVR Core] {text}"), + overwrite=overwrite, ) if is_valid and stems: @@ -237,13 +264,19 @@ def build_parser() -> argparse.ArgumentParser: "--precision", "-p", default="fp16", - help="Inference precision: fp32, fp16, fp8, nvfp4 (default: fp16)", + help="Inference precision: fp32, fp16, bf16 (default: fp16)", ) run_parser.add_argument("--device", "-d", default="cuda:0", help="Target device: cuda:0, cpu (default: cuda:0)") run_parser.add_argument("--output-dir", "-o", default="separated_outputs", help="Output directory for stems") run_parser.add_argument("--segment-size", type=int, default=None, help="Segment size (MDX chunk size)") run_parser.add_argument("--overlap", type=float, default=None, help="Overlap ratio (e.g. 0.25)") run_parser.add_argument("--batch-size", type=int, default=1, help="Inference batch size (default: 1)") + run_parser.add_argument( + "--overwrite", + "-y", + action="store_true", + help="Overwrite existing output stems without prompting", + ) # Command: bench bench_parser = subparsers.add_parser("bench", help="Run real benchmark with hardware telemetry & metric export") @@ -253,7 +286,7 @@ def build_parser() -> argparse.ArgumentParser: "--precision", "-p", default="fp16", - help="Inference precision: fp32, fp16, fp8, nvfp4 (default: fp16)", + help="Inference precision: fp32, fp16, bf16 (default: fp16)", ) bench_parser.add_argument("--device", "-d", default="cuda:0", help="Target device: cuda:0, cpu (default: cuda:0)") bench_parser.add_argument("--rounds", "-r", type=int, default=3, help="Number of measurement rounds (default: 3)") diff --git a/uvr_cli/engine.py b/uvr_cli/engine.py index 148c9d0..f6b79b8 100644 --- a/uvr_cli/engine.py +++ b/uvr_cli/engine.py @@ -69,11 +69,10 @@ class BenchmarkEngine: current_iter += 1 is_warmup_run = current_iter <= self.warmup round_number = current_iter if is_warmup_run else (current_iter - self.warmup) - cache_state = "cold" if current_iter == 1 else "warm" run_label = f"Warmup {round_number}" if is_warmup_run else f"Measurement Round {round_number}/{self.rounds}" if verbose: - print(f"--> Starting {run_label} (Cache: {cache_state})...") + print(f"--> Starting {run_label}...") round_export_dir = temp_stems_dir / f"round_{current_iter}" round_export_dir.mkdir(parents=True, exist_ok=True) @@ -102,7 +101,6 @@ class BenchmarkEngine: "iteration": current_iter, "is_warmup": is_warmup_run, "round": round_number, - "cache_state": cache_state, "total_time_sec": total_time, "speed_factor_rt": speed_factor, "is_valid": is_valid, @@ -123,7 +121,6 @@ class BenchmarkEngine: "audio_file": self.audio_path.name, "audio_duration_sec": duration_sec, "round": f"warmup_{round_number}" if is_warmup_run else str(round_number), - "cache_state": cache_state, "total_time_sec": total_time, "inference_time_sec": total_time, # Pure separator execution "speed_factor_rt": speed_factor, diff --git a/uvr_cli/exporter.py b/uvr_cli/exporter.py index 4b9cb90..7065516 100644 --- a/uvr_cli/exporter.py +++ b/uvr_cli/exporter.py @@ -48,7 +48,6 @@ CSV_FIELDS = [ "audio_file", "audio_duration_sec", "round", - "cache_state", "total_time_sec", "inference_time_sec", "speed_factor_rt", diff --git a/uvr_cli/model_resolver.py b/uvr_cli/model_resolver.py index 57d6594..5e33a4d 100644 --- a/uvr_cli/model_resolver.py +++ b/uvr_cli/model_resolver.py @@ -218,13 +218,16 @@ def _load_json(path: Path) -> Dict[str, Any]: def list_available_models() -> List[Dict[str, Any]]: - """Scan and list all installed models across MDX, VR, and Demucs architectures.""" + """Scan and list all installed ONNX models in MDX_Net_Models (non-recursive). + + Per MVP spec §3.1, only `.onnx` files in `models/MDX_Net_Models` are + discovered. Non-ONNX model formats are out of scope for this MVP. + """ results: List[Dict[str, Any]] = [] - # MDX Models if MDX_MODELS_DIR.is_dir(): for file in MDX_MODELS_DIR.iterdir(): - if file.is_file() and file.suffix.lower() in [ONNX, CKPT]: + if file.is_file() and file.suffix.lower() == ONNX: results.append({ "name": file.name, "basename": file.stem, @@ -234,81 +237,43 @@ def list_available_models() -> List[Dict[str, Any]]: "format": file.suffix.lower(), }) - # VR Models - if VR_MODELS_DIR.is_dir(): - for file in VR_MODELS_DIR.iterdir(): - if file.is_file() and file.suffix.lower() in [PTH]: - results.append({ - "name": file.name, - "basename": file.stem, - "path": str(file), - "architecture": VR_ARCH_TYPE, - "size_mb": round(file.stat().st_size / (1024 * 1024), 2), - "format": file.suffix.lower(), - }) - - # Demucs Models - if DEMUCS_MODELS_DIR.is_dir(): - for file in DEMUCS_MODELS_DIR.iterdir(): - if file.is_file() and file.suffix.lower() in [".th", YAML]: - results.append({ - "name": file.name, - "basename": file.stem, - "path": str(file), - "architecture": DEMUCS_ARCH_TYPE, - "size_mb": round(file.stat().st_size / (1024 * 1024), 2), - "format": file.suffix.lower(), - }) - if DEMUCS_NEWER_REPO_DIR.is_dir(): - for file in DEMUCS_NEWER_REPO_DIR.iterdir(): - if file.is_file() and file.suffix.lower() in [YAML, ".th"]: - results.append({ - "name": file.name, - "basename": file.stem, - "path": str(file), - "architecture": DEMUCS_ARCH_TYPE, - "size_mb": round(file.stat().st_size / (1024 * 1024), 2), - "format": file.suffix.lower(), - }) - return results def resolve_model_file(model_identifier: str) -> Tuple[Path, str]: - """Resolve a model name or file path to an existing file and its architecture.""" + """Resolve an ONNX model name or file path to an existing file and its architecture. + + Per MVP spec §3.1, only `.onnx` files are accepted. Non-ONNX model + extensions are rejected with a clear error. + """ # 1. Direct path check direct_path = Path(model_identifier).resolve() if direct_path.is_file(): ext = direct_path.suffix.lower() - if ext in [ONNX, CKPT]: - return direct_path, MDX_ARCH_TYPE - if ext in [PTH]: - return direct_path, VR_ARCH_TYPE - if ext in [YAML, ".th"]: - return direct_path, DEMUCS_ARCH_TYPE + if ext != ONNX: + raise ValueError( + f"Non-ONNX model format '{ext}' is not supported in this MVP. " + f"Only .onnx models are accepted. Got: {direct_path.name}" + ) return direct_path, MDX_ARCH_TYPE - # 2. Search by filename or stem in MDX_Net_Models - for candidate in [MDX_MODELS_DIR / model_identifier, MDX_MODELS_DIR / f"{model_identifier}.onnx", MDX_MODELS_DIR / f"{model_identifier}.ckpt"]: - if candidate.is_file(): + # 2. Search by filename or stem in MDX_Net_Models (.onnx only) + for candidate in [ + MDX_MODELS_DIR / model_identifier, + MDX_MODELS_DIR / f"{model_identifier}.onnx", + ]: + if candidate.is_file() and candidate.suffix.lower() == ONNX: return candidate, MDX_ARCH_TYPE - # 3. Search in VR_Models - for candidate in [VR_MODELS_DIR / model_identifier, VR_MODELS_DIR / f"{model_identifier}.pth"]: - if candidate.is_file(): - return candidate, VR_ARCH_TYPE - - # 4. Search in Demucs_Models - for candidate in [DEMUCS_MODELS_DIR / model_identifier, DEMUCS_NEWER_REPO_DIR / model_identifier, DEMUCS_NEWER_REPO_DIR / f"{model_identifier}.yaml"]: - if candidate.is_file(): - return candidate, DEMUCS_ARCH_TYPE - - # 5. Fallback search through all available models + # 3. Fallback search through discovered ONNX models for m in list_available_models(): if model_identifier.lower() in [m["name"].lower(), m["basename"].lower()]: return Path(m["path"]), m["architecture"] - raise FileNotFoundError(f"Model '{model_identifier}' could not be located in models directories.") + raise FileNotFoundError( + f"ONNX model '{model_identifier}' could not be located in " + f"models/MDX_Net_Models/. Ensure the .onnx file is present." + ) def build_headless_model_data( diff --git a/uvr_cli/runner.py b/uvr_cli/runner.py index 9ae51c5..90b154f 100644 --- a/uvr_cli/runner.py +++ b/uvr_cli/runner.py @@ -40,12 +40,65 @@ def get_audio_metadata(audio_path: str | Path) -> Dict[str, Any]: } +def get_expected_stem_paths( + model_data: HeadlessModelData, + audio_path: str | Path, + export_dir: str | Path, +) -> List[Path]: + """Calculate expected output stem file paths based on model settings and audio name.""" + audio_stem = Path(audio_path).stem + export_path = Path(export_dir).resolve() + + stems = [] + # Demucs 4-stem or standard 2-stem + if getattr(model_data, "process_method", "") == DEMUCS_ARCH_TYPE and getattr(model_data, "is_4_stem_ensemble", False): + sources = getattr(model_data, "demucs_source_list", ["drums", "bass", "other", "vocals"]) + for src in sources: + stems.append(src.capitalize()) + else: + # Standard primary & secondary stems + if not getattr(model_data, "is_secondary_stem_only", False) and getattr(model_data, "primary_stem", None): + stems.append(model_data.primary_stem) + if not getattr(model_data, "is_primary_stem_only", False) and getattr(model_data, "secondary_stem", None): + stems.append(model_data.secondary_stem) + + ext = ".wav" + save_format = getattr(model_data, "save_format", "WAV").lower() + if save_format in ("mp3", "flac", "m4a"): + ext = f".{save_format}" + + return [export_path / f"{audio_stem}_({stem}){ext}" for stem in stems] + + +def get_existing_outputs( + model_data: HeadlessModelData, + audio_path: str | Path, + export_dir: str | Path, +) -> List[Path]: + """Find any existing output files in export_dir matching this separation job.""" + export_path = Path(export_dir).resolve() + if not export_path.is_dir(): + return [] + + audio_stem = Path(audio_path).stem + expected = set(get_expected_stem_paths(model_data, audio_path, export_dir)) + existing = [p for p in expected if p.is_file()] + + # Also detect existing files matching "{audio_stem}_(*).*" + for p in export_path.glob(f"{audio_stem}_*.*"): + if p.is_file() and p not in existing and "(" in p.name and ")" in p.name: + existing.append(p) + + return sorted(existing) + + def execute_inference( model_data: HeadlessModelData, audio_path: str | Path, export_dir: str | Path, progress_callback: Optional[Callable[[float, float], None]] = None, console_callback: Optional[Callable[[str, str], None]] = None, + overwrite: bool = False, ) -> Tuple[List[Path], bool]: """Execute UVR separation directly using core separate.py classes. @@ -59,8 +112,18 @@ def execute_inference( if not audio_path.is_file(): raise FileNotFoundError(f"Input audio file not found: {audio_path}") - # Snapshot existing files in export directory to detect new outputs + # Remove conflicting existing outputs if overwrite is enabled + if overwrite: + colliding = get_existing_outputs(model_data, audio_path, export_path) + for f in colliding: + try: + f.unlink() + except Exception: + pass + + # Snapshot existing files and mtimes in export directory existing_files = set(export_path.glob("*")) + existing_mtimes = {f: f.stat().st_mtime for f in existing_files if f.is_file()} def default_progress(step: float, inference_iterations: float = 0.0) -> None: if progress_callback: @@ -101,18 +164,30 @@ def execute_inference( # Run inference directly separator.seperate() - # Detect generated stems + # Detect generated stems: all_current_files = set(export_path.glob("*")) - new_files = [f for f in (all_current_files - existing_files) if f.is_file()] + generated_set = set( + f for f in (all_current_files - existing_files) + if f.is_file() and f.name.startswith(f"{audio_path.stem}_") + ) + + # Expected output stems that were written or updated + expected_stems = get_expected_stem_paths(model_data, audio_path, export_path) + for p in expected_stems: + if p.is_file(): + if p not in existing_mtimes or p.stat().st_mtime >= existing_mtimes.get(p, 0): + generated_set.add(p) + + output_files = sorted([f for f in generated_set if f.name.startswith(f"{audio_path.stem}_")]) # Validate output files is_valid = True - if not new_files: + if not output_files: is_valid = False else: - for stem_file in new_files: + for stem_file in output_files: if stem_file.stat().st_size == 0: is_valid = False break - return sorted(new_files), is_valid + return output_files, is_valid