#!/usr/bin/env python3 # coding=utf-8 # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """CLI launcher for Audex Enhancement VAE""" from __future__ import annotations import argparse from pathlib import Path import torch from enhancement_vae import DEFAULT_CHECKPOINT, DEFAULT_CONFIG, enhance_file, iter_input_files, load_model def parse_args() -> argparse.Namespace: script_dir = Path(__file__).resolve().parent parser = argparse.ArgumentParser(description="Enhance XCodec1-decoded 16 kHz WAVs to 48 kHz.") parser.add_argument("--input", type=Path, required=True, help="Input audio file or directory.") parser.add_argument("--output-dir", type=Path, required=True, help="Directory for enhanced 48 kHz WAVs.") parser.add_argument("--device", type=str, default="cuda" if torch.cuda.is_available() else "cpu") parser.add_argument("--seed", type=int, default=0, help="Torch seed for stochastic VAE sampling.") parser.add_argument("--deterministic", action="store_true", help="Use posterior mean instead of VAE sampling.") parser.set_defaults( checkpoint=script_dir / DEFAULT_CHECKPOINT, config=script_dir / DEFAULT_CONFIG, ) return parser.parse_args() def main() -> None: args = parse_args() torch.manual_seed(args.seed) device = torch.device(args.device) model = load_model(checkpoint_path=args.checkpoint, config_path=args.config, device=device) input_files = iter_input_files(args.input) if not input_files: raise ValueError(f"No audio files found in {args.input}") for input_path in input_files: output_path = args.output_dir / f"{input_path.stem}_enhanced_48k.wav" enhance_file(model, input_path, output_path, deterministic=args.deterministic) print(f"{input_path} -> {output_path}") if __name__ == "__main__": main()