Loading other/lp16k.py 0 → 100755 +76 −0 Original line number Diff line number Diff line #!/usr/bin/python3 import argparse import multiprocessing as mp import sys from pathlib import Path from time import sleep sys.path.append(str(Path(__file__).parent.parent)) from ivas_processing_scripts.audiotools.audio import fromfile from ivas_processing_scripts.audiotools.audiofile import write from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu from ivas_processing_scripts.utils import progressbar_update, spinner def lp16k(in_file, out_file): x = fromfile("STEREO", in_file) if x.fs != 48000: raise ValueError( f"Unsupported sampling rate {x.fs//1000} kHz for input file {in_file} - only 48 kHz is supported!" ) # resample ITU only returns the audio array # but uses the sampling rate stored in the audio object # so we need to correctly set it after each call x.audio = resample_itu(x, 96000) x.fs = 96000 x.audio = resample_itu(x, 32000) x.fs = 32000 x.audio = resample_itu(x, 96000) x.fs = 96000 x.audio = resample_itu(x, 48000) x.fs = 48000 write(out_file, x.audio, x.fs) def main(args): # list input files and create function arguments in_files = list(args.in_dir.glob("*.wav")) func_args = [(f, args.out_dir.joinpath(f.name)) for f in in_files] if not args.out_dir.exists(): args.out_dir.mkdir() # progressbar and multiprocessing setup count = len(func_args) width = 80 p = mp.Pool() results = p.starmap_async(lp16k, func_args) # apply function in parallel progressbar_update(0, count, width) while not results.ready(): progressbar_update(count - int(results._number_left), count, width) spinner() sleep(0.1) progressbar_update(count, count, width) print("\n", flush=True, file=sys.stdout) results.get() p.close() p.join() if __name__ == "__main__": parser = argparse.ArgumentParser(description="Script to lowpass audio to 16 kHz") parser.add_argument("in_dir", help="Input directory", type=Path) parser.add_argument("out_dir", help="Output directory", type=Path) args = parser.parse_args() main(args) Loading
other/lp16k.py 0 → 100755 +76 −0 Original line number Diff line number Diff line #!/usr/bin/python3 import argparse import multiprocessing as mp import sys from pathlib import Path from time import sleep sys.path.append(str(Path(__file__).parent.parent)) from ivas_processing_scripts.audiotools.audio import fromfile from ivas_processing_scripts.audiotools.audiofile import write from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu from ivas_processing_scripts.utils import progressbar_update, spinner def lp16k(in_file, out_file): x = fromfile("STEREO", in_file) if x.fs != 48000: raise ValueError( f"Unsupported sampling rate {x.fs//1000} kHz for input file {in_file} - only 48 kHz is supported!" ) # resample ITU only returns the audio array # but uses the sampling rate stored in the audio object # so we need to correctly set it after each call x.audio = resample_itu(x, 96000) x.fs = 96000 x.audio = resample_itu(x, 32000) x.fs = 32000 x.audio = resample_itu(x, 96000) x.fs = 96000 x.audio = resample_itu(x, 48000) x.fs = 48000 write(out_file, x.audio, x.fs) def main(args): # list input files and create function arguments in_files = list(args.in_dir.glob("*.wav")) func_args = [(f, args.out_dir.joinpath(f.name)) for f in in_files] if not args.out_dir.exists(): args.out_dir.mkdir() # progressbar and multiprocessing setup count = len(func_args) width = 80 p = mp.Pool() results = p.starmap_async(lp16k, func_args) # apply function in parallel progressbar_update(0, count, width) while not results.ready(): progressbar_update(count - int(results._number_left), count, width) spinner() sleep(0.1) progressbar_update(count, count, width) print("\n", flush=True, file=sys.stdout) results.get() p.close() p.join() if __name__ == "__main__": parser = argparse.ArgumentParser(description="Script to lowpass audio to 16 kHz") parser.add_argument("in_dir", help="Input directory", type=Path) parser.add_argument("out_dir", help="Output directory", type=Path) args = parser.parse_args() main(args)