File size: 762 Bytes
7b88c07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# removes files with loudness below 24db

from pathlib import Path 
import shutil
import audiotools as at
import argbind

@argbind.bind(without_prefix=True)
def remove_quiet_files(
    src_dir: Path = None,
    dest_dir: Path = None,
    min_loudness: float = -30,
):
    # copy src to dest
    dest_dir.mkdir(parents=True, exist_ok=True)
    shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True)
    
    audio_files = at.util.find_audio(dest_dir)
    for audio_file in audio_files:
        sig = at.AudioSignal(audio_file)
        if sig.loudness() < min_loudness:
            audio_file.unlink()
            print(f"removed {audio_file}")

if __name__ == "__main__":
    args = argbind.parse_args()

    with argbind.scope(args):
        remove_quiet_files()