Arsh9210 commited on
Commit
6748056
·
verified ·
1 Parent(s): 47a7df4

Added enhancement_VAE/enhance_audio_48k.py

Browse files
enhancement_VAE/enhance_audio_48k.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # coding=utf-8
3
+ # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """CLI launcher for Audex Enhancement VAE"""
17
+
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ from pathlib import Path
22
+
23
+ import torch
24
+
25
+ from enhancement_vae import DEFAULT_CHECKPOINT, DEFAULT_CONFIG, enhance_file, iter_input_files, load_model
26
+
27
+
28
+ def parse_args() -> argparse.Namespace:
29
+ script_dir = Path(__file__).resolve().parent
30
+ parser = argparse.ArgumentParser(description="Enhance XCodec1-decoded 16 kHz WAVs to 48 kHz.")
31
+ parser.add_argument("--input", type=Path, required=True, help="Input audio file or directory.")
32
+ parser.add_argument("--output-dir", type=Path, required=True, help="Directory for enhanced 48 kHz WAVs.")
33
+ parser.add_argument("--device", type=str, default="cuda" if torch.cuda.is_available() else "cpu")
34
+ parser.add_argument("--seed", type=int, default=0, help="Torch seed for stochastic VAE sampling.")
35
+ parser.add_argument("--deterministic", action="store_true", help="Use posterior mean instead of VAE sampling.")
36
+ parser.set_defaults(
37
+ checkpoint=script_dir / DEFAULT_CHECKPOINT,
38
+ config=script_dir / DEFAULT_CONFIG,
39
+ )
40
+ return parser.parse_args()
41
+
42
+
43
+ def main() -> None:
44
+ args = parse_args()
45
+ torch.manual_seed(args.seed)
46
+ device = torch.device(args.device)
47
+ model = load_model(checkpoint_path=args.checkpoint, config_path=args.config, device=device)
48
+ input_files = iter_input_files(args.input)
49
+ if not input_files:
50
+ raise ValueError(f"No audio files found in {args.input}")
51
+ for input_path in input_files:
52
+ output_path = args.output_dir / f"{input_path.stem}_enhanced_48k.wav"
53
+ enhance_file(model, input_path, output_path, deterministic=args.deterministic)
54
+ print(f"{input_path} -> {output_path}")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main()