text: # preprocess the VCTK database
  #  - normalize the audio
  #
  # Zhenhao Ge, 2021-10-14
  
  import os
  import argparse
  import glob
  
  # change working dir if needed
  import sys
  sys.path.append('utils')
  
  from audio import audioread, normalize_wav
  
  def parse_args():
  
    usage = 'usage: preprocess the VCTK database'
    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument('-di', 'in-dir', type=str, help='input dir')
    parser.add_argument('-do', 'out-dir', type=str, help='output dir')
    return parser.parse_args()
  
  def main():
  
    # # runtime mode
    # args = parse_args()
  
    # interactive mode (comment out before running the script)
    args = argparse.ArgumentParser()
    args.in_dir = '/data/evs/VCTK/VCTK-wgan/wav22_silence_trimmed'
    args.out_dir = '/data/evs/VCTK/VCTK-wgan/wav22_silence_trimmed'
  
    print('input dir: {}'.format(args.in_dir))
    print('output dir: {}'.format(args.out_dir))
  
    wavfiles = sorted(glob.glob(os.path.join(args.in_dir, '**', '*.wav')))
    wavfiles = [f for f in wavfiles if 'norm' not in f]
    nwavs = len(wavfiles)
    print('# of wav files in {}: {}'.format(args.in_dir, nwavs))
  
    tuples = [[] for _ in range(nwavs)]
  
    blksize = 100
    for i in range(nwavs):
  
      if i % blksize == 0:
        print('processing {}/{} - {}/{} ...'.format(
          i, nwavs, min(i+blksize, nwavs), nwavs))
  
      wavfile = wavfiles[i]
      wavfile_norm = os.path.splitext(wavfile)[0] + '.norm.wav'
  
      # normalize wav file
      if not os.path.isfile(wavfile_norm):
        normalize_wav(wavfile, wavfile_norm, eps=0.1, verbose=False)
  
      # # collect info for the amplitude change
      # data0, params0 = audioread(wavfile)
      # max0 = max(abs(data0))
      # data1, params1 = audioread(wavfile_norm)
      # max1 = max(abs(data1))
      # r = max1/max0
      # tuples[i] = (wavfile, max0, max1, r)
  