code: def _collect_data(directory, input_ext, target_ext):
    
    # Directory from string to tuple pair of strings
    # key: the filepath to a datafile including the datafile's basename. Example,
    #   if the datafile was "/path/to/datafile.wav" then the key would be
    #   "/path/to/datafile"
    # value: a pair of strings (input_filepath, target_filepath)
    data_files = {}
    for root, _, filenames in os.walk(directory):
      input_files = [filename for filename in filenames if input_ext in filename]
      for input_filename in input_files:
        basename = input_filename.strip(input_ext)
        input_file = os.path.join(root, input_filename)
        target_file = os.path.join(root, basename + target_ext)
        key = os.path.join(root, basename)
        assert os.path.exists(target_file)
        assert key not in data_files
        data_files[key] = (input_file, target_file)
    return data_files
docs: Traverses directory collecting input and target files.