File size: 2,430 Bytes
2caea7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import glob
import subprocess

def de_echo(input_sound, output_dir):
    """MP3 256kps"""
    command = [
        "audio-separator", input_sound,
        "--model_filename", "UVR-De-Echo-Aggressive.pth",
        "--vr_window_size", "512",
        "--vr_batch_size", "16",
        "--vr_aggression", "5",        
        "--output_format", "MP3",
        "--output_dir", output_dir
    ]

    try:
        subprocess.run(command, check=True, stderr=subprocess.DEVNULL)
        #print(f"Conversion successful: {output_sound}")
    except subprocess.CalledProcessError as error:
        print(f"Conversion failed: {error}")


def de_echo_normal(input_sound, output_dir):
    """MP3 256kps"""
    command = [
        "audio-separator", input_sound,
        "--model_filename", "UVR-De-Echo-Normal.pth",
        "--vr_window_size", "512",
        "--vr_batch_size", "16",
        "--vr_aggression", "5",        
        "--output_format", "MP3",
        "--output_dir", output_dir
    ]

    try:
        subprocess.run(command, check=True, stderr=subprocess.DEVNULL)
        #print(f"Conversion successful: {output_sound}")
    except subprocess.CalledProcessError as error:
        print(f"Conversion failed: {error}")


def main():
    import argparse
    parser = argparse.ArgumentParser(description='')

    parser.add_argument('--in_dir', type=str, help='')
    parser.add_argument('--out_dir', type=str, help='')
    args = parser.parse_args()
    #print(args)
	#########################
    os.makedirs(args.out_dir, exist_ok=True)
  
    files = glob.glob(f'{args.in_dir}/*.mp3')
    files.sort()
    print(f'num_files: {len(files)}')

    for i,file in enumerate(files):
      print(f'{i}/{len(files)}: {file}')
      #de_echo(file, f'{args.out_dir}')
      de_echo_normal(file, f'{args.out_dir}')
      os.system(f'rm -f {args.out_dir}/*Instrumental*')

      file_name = os.path.basename(file)
      name = os.path.splitext(file_name)[0]

      #src_file = os.path.join(args.out_dir, f'{name}_(No Echo)_UVR-De-Echo-Aggressive.mp3')
      src_file = os.path.join(args.out_dir, f'{name}_(No Echo)_UVR-De-Echo-Normal.mp3')
      dst_file = os.path.join(args.out_dir, f'{name}.mp3')
      try:
        os.rename(src_file, dst_file)
      except:
        pass
	
	#########################

if __name__ == '__main__':
    main()