timit.py
def main():
  """ Convert raw TIMIT to the standard train, val, test sets. """

  description = main.__doc__
  formatter_class = argparse.ArgumentDefaultsHelpFormatter
  parser = argparse.ArgumentParser(description=description, formatter_class=formatter_class)
  parser.add_argument('--raw_data_dir', type=str, default=DEFAULT_RAW_DATA_DIR,
                      help='''The raw TIMIT data directory. This should contain the file readme.doc
                              and the directories doc, test, and train. It's okay if they're uppercase,
                              lowercase, etc. In the standardized version, everything will be lowercase.''')
  parser.add_argument('--data_dir', type=str, default=DEFAULT_DATA_DIR,
                      help='''The directory in which we'll save the standardized version.''')
  args = parser.parse_args()

  top_level_contents = [name.lower() for name in os.listdir(args.raw_data_dir)]
  if not all(name in top_level_contents for name in ['readme.doc', 'doc', 'test', 'train']):
    raise ValueError('%s is not the expected raw TIMIT directory. Run timit.py --help.' % args.raw_data_dir)

  if os.path.exists(args.data_dir):
    raise ValueError('%s already exists. ' % args.data_dir + 'If you intend to overwrite it, delete it first.')

  raw_train_dir = os.path.join(args.data_dir, 'raw_train')
  raw_test_dir = os.path.join(args.data_dir, 'raw_test')

  train_dir = os.path.join(args.data_dir, 'train')
  val_dir = os.path.join(args.data_dir, 'val')
  test_dir = os.path.join(args.data_dir, 'test')

  print('Copying %s to %s ..' % (args.raw_data_dir, args.data_dir))
  shutil.copytree(args.raw_data_dir, args.data_dir)

  print('Renaming all files to lowercase..')
  recursive_lowercase_rename(args.data_dir)

  print('Moving train to raw_train and test to raw_test..')
  shutil.move(train_dir, raw_train_dir)
  shutil.move(test_dir, raw_test_dir)

  print('Populating the train directory..')
  for path in glob.glob(os.path.join(raw_train_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in TRAIN_SPEAKERS:
      shutil.copytree(path, os.path.join(train_dir, speaker))

  print('Populating the val directory..')
  for path in glob.glob(os.path.join(raw_test_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in VAL_SPEAKERS:
      shutil.copytree(path, os.path.join(val_dir, speaker))

  print('Populating the test directory..')
  for path in glob.glob(os.path.join(raw_test_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in TEST_SPEAKERS:
      shutil.copytree(path, os.path.join(test_dir, speaker))

  for parent_dir in [train_dir, val_dir, test_dir]:
    print('Recursively removing dialect files from %s ..' % parent_dir)
    for dirpath, dirnames, filenames in os.walk(parent_dir):
      for filename in filenames:
        if filename.startswith('sa'):
          os.remove(os.path.join(dirpath, filename))

  for parent_dir in [train_dir, val_dir, test_dir]:
    print('Recursively repairing wav files (by adding headers) in %s ..' % parent_dir)
    for dirpath, dirnames, filenames in os.walk(parent_dir):
      for filename in filenames:
        if filename.endswith('wav'):
          path = os.path.join(dirpath, filename)
          raw_path = os.path.join(dirpath, 'raw_' + filename)
          os.rename(path, raw_path)
          os.system('sox %s %s' % (raw_path, path))
          os.remove(raw_path)
 Convert raw TIMIT to the standard train, val, test sets. 
Convert raw TIMIT to the standard train, val, test sets.
Convert raw TIMIT to the standard train val test sets .
def main():
  description = main.__doc__
  formatter_class = argparse.ArgumentDefaultsHelpFormatter
  parser = argparse.ArgumentParser(description=description, formatter_class=formatter_class)
  parser.add_argument('--raw_data_dir', type=str, default=DEFAULT_RAW_DATA_DIR,
                      help='''The raw TIMIT data directory. This should contain the file readme.doc
                              and the directories doc, test, and train. It's okay if they're uppercase,
                              lowercase, etc. In the standardized version, everything will be lowercase.''')
  parser.add_argument('--data_dir', type=str, default=DEFAULT_DATA_DIR,
                      help='''The directory in which we'll save the standardized version.''')
  args = parser.parse_args()
  top_level_contents = [name.lower() for name in os.listdir(args.raw_data_dir)]
  if not all(name in top_level_contents for name in ['readme.doc', 'doc', 'test', 'train']):
    raise ValueError('%s is not the expected raw TIMIT directory. Run timit.py --help.' % args.raw_data_dir)
  if os.path.exists(args.data_dir):
    raise ValueError('%s already exists. ' % args.data_dir + 'If you intend to overwrite it, delete it first.')
  raw_train_dir = os.path.join(args.data_dir, 'raw_train')
  raw_test_dir = os.path.join(args.data_dir, 'raw_test')
  train_dir = os.path.join(args.data_dir, 'train')
  val_dir = os.path.join(args.data_dir, 'val')
  test_dir = os.path.join(args.data_dir, 'test')
  print('Copying %s to %s ..' % (args.raw_data_dir, args.data_dir))
  shutil.copytree(args.raw_data_dir, args.data_dir)
  print('Renaming all files to lowercase..')
  recursive_lowercase_rename(args.data_dir)
  print('Moving train to raw_train and test to raw_test..')
  shutil.move(train_dir, raw_train_dir)
  shutil.move(test_dir, raw_test_dir)
  print('Populating the train directory..')
  for path in glob.glob(os.path.join(raw_train_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in TRAIN_SPEAKERS:
      shutil.copytree(path, os.path.join(train_dir, speaker))
  print('Populating the val directory..')
  for path in glob.glob(os.path.join(raw_test_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in VAL_SPEAKERS:
      shutil.copytree(path, os.path.join(val_dir, speaker))
  print('Populating the test directory..')
  for path in glob.glob(os.path.join(raw_test_dir, '*', '*')):
    _, speaker = os.path.split(path)
    if speaker in TEST_SPEAKERS:
      shutil.copytree(path, os.path.join(test_dir, speaker))
  for parent_dir in [train_dir, val_dir, test_dir]:
    print('Recursively removing dialect files from %s ..' % parent_dir)
    for dirpath, dirnames, filenames in os.walk(parent_dir):
      for filename in filenames:
        if filename.startswith('sa'):
          os.remove(os.path.join(dirpath, filename))
  for parent_dir in [train_dir, val_dir, test_dir]:
    print('Recursively repairing wav files (by adding headers) in %s ..' % parent_dir)
    for dirpath, dirnames, filenames in os.walk(parent_dir):
      for filename in filenames:
        if filename.endswith('wav'):
          path = os.path.join(dirpath, filename)
          raw_path = os.path.join(dirpath, 'raw_' + filename)
          os.rename(path, raw_path)
          os.system('sox %s %s' % (raw_path, path))
          os.remove(raw_path)
def main ( ) : description = main . __doc__ formatter_class = argparse . ArgumentDefaultsHelpFormatter parser = argparse . ArgumentParser ( description = description , formatter_class = formatter_class ) parser . add_argument ( '--raw_data_dir' , type = str , default = DEFAULT_RAW_DATA_DIR , help = '''The raw TIMIT data directory. This should contain the file readme.doc
                              and the directories doc, test, and train. It's okay if they're uppercase,
                              lowercase, etc. In the standardized version, everything will be lowercase.''' ) parser . add_argument ( '--data_dir' , type = str , default = DEFAULT_DATA_DIR , help = '''The directory in which we'll save the standardized version.''' ) args = parser . parse_args ( ) top_level_contents = [ name . lower ( ) for name in os . listdir ( args . raw_data_dir ) ] if not all ( name in top_level_contents for name in [ 'readme.doc' , 'doc' , 'test' , 'train' ] ) : raise ValueError ( '%s is not the expected raw TIMIT directory. Run timit.py --help.' % args . raw_data_dir ) if os . path . exists ( args . data_dir ) : raise ValueError ( '%s already exists. ' % args . data_dir + 'If you intend to overwrite it, delete it first.' ) raw_train_dir = os . path . join ( args . data_dir , 'raw_train' ) raw_test_dir = os . path . join ( args . data_dir , 'raw_test' ) train_dir = os . path . join ( args . data_dir , 'train' ) val_dir = os . path . join ( args . data_dir , 'val' ) test_dir = os . path . join ( args . data_dir , 'test' ) print ( 'Copying %s to %s ..' % ( args . raw_data_dir , args . data_dir ) ) shutil . copytree ( args . raw_data_dir , args . data_dir ) print ( 'Renaming all files to lowercase..' ) recursive_lowercase_rename ( args . data_dir ) print ( 'Moving train to raw_train and test to raw_test..' ) shutil . move ( train_dir , raw_train_dir ) shutil . move ( test_dir , raw_test_dir ) print ( 'Populating the train directory..' ) for path in glob . glob ( os . path . join ( raw_train_dir , '*' , '*' ) ) : _ , speaker = os . path . split ( path ) if speaker in TRAIN_SPEAKERS : shutil . copytree ( path , os . path . join ( train_dir , speaker ) ) print ( 'Populating the val directory..' ) for path in glob . glob ( os . path . join ( raw_test_dir , '*' , '*' ) ) : _ , speaker = os . path . split ( path ) if speaker in VAL_SPEAKERS : shutil . copytree ( path , os . path . join ( val_dir , speaker ) ) print ( 'Populating the test directory..' ) for path in glob . glob ( os . path . join ( raw_test_dir , '*' , '*' ) ) : _ , speaker = os . path . split ( path ) if speaker in TEST_SPEAKERS : shutil . copytree ( path , os . path . join ( test_dir , speaker ) ) for parent_dir in [ train_dir , val_dir , test_dir ] : print ( 'Recursively removing dialect files from %s ..' % parent_dir ) for dirpath , dirnames , filenames in os . walk ( parent_dir ) : for filename in filenames : if filename . startswith ( 'sa' ) : os . remove ( os . path . join ( dirpath , filename ) ) for parent_dir in [ train_dir , val_dir , test_dir ] : print ( 'Recursively repairing wav files (by adding headers) in %s ..' % parent_dir ) for dirpath , dirnames , filenames in os . walk ( parent_dir ) : for filename in filenames : if filename . endswith ( 'wav' ) : path = os . path . join ( dirpath , filename ) raw_path = os . path . join ( dirpath , 'raw_' + filename ) os . rename ( path , raw_path ) os . system ( 'sox %s %s' % ( raw_path , path ) ) os . remove ( raw_path )
Convert raw TIMIT to the standard train, val, test sets.
Convert raw TIMIT to the standard train val test sets .
""" Convert raw TIMIT to the standard train, val, test sets. """