def testLoadBatchEncodings(self, n_files, start_length, end_length, channels=16): test_encoding = np.random.randn(start_length, channels) # Make temp dir test_dir = tf.test.get_temp_dir() tf.gfile.MakeDirs(test_dir) # Make wav files files = [] for i in range(n_files): fname = os.path.join(test_dir, 'test_embedding_{}.npy'.format(i)) files.append(fname) np.save(fname, test_encoding) # Load the files batch_data = fastgen.load_batch_encodings(files, sample_length=end_length) self.assertEqual(batch_data.shape, (n_files, end_length, channels))
def main(unused_argv=None): os.environ["CUDA_VISIBLE_DEVICES"] = str(FLAGS.gpu_number) source_path = utils.shell_path(FLAGS.source_path) checkpoint_path = utils.shell_path(FLAGS.checkpoint_path) save_path = utils.shell_path(FLAGS.save_path) if not save_path: raise ValueError("Must specify a save_path.") tf.logging.set_verbosity(FLAGS.log) # Use directory of files if tf.gfile.IsDirectory(source_path): files = tf.gfile.ListDirectory(source_path) file_extensions = [os.path.splitext(f)[1] for f in files] if ".wav" in file_extensions: file_extension = ".wav" elif ".npy" in file_extensions: file_extension = ".npy" else: raise RuntimeError("Folder must contain .wav or .npy files.") file_extension = ".npy" if FLAGS.npy_only else file_extension files = sorted([ os.path.join(source_path, fname) for fname in files if fname.lower().endswith(file_extension) ]) # Use a single file elif source_path.lower().endswith((".wav", ".npy")): file_extension = os.path.splitext(source_path.lower())[1] files = [source_path] else: raise ValueError( "source_path {} must be a folder or file.".format(source_path)) # Now synthesize from files one batch at a time batch_size = FLAGS.batch_size sample_length = FLAGS.sample_length n = len(files) for start in range(0, n, batch_size): end = start + batch_size batch_files = files[start:end] save_names = [ os.path.join( save_path, "gen_" + os.path.splitext(os.path.basename(f))[0] + ".wav") for f in batch_files ] # Encode waveforms if file_extension == ".wav": batch_data = fastgen.load_batch_audio(batch_files, sample_length=sample_length) encodings = fastgen.encode(batch_data, checkpoint_path, sample_length=sample_length) # Or load encodings else: encodings = fastgen.load_batch_encodings( batch_files, sample_length=sample_length) # Synthesize multi-gpu if FLAGS.gpu_number != 0: with tf.device("/device:GPU:%d" % FLAGS.gpu_number): fastgen.synthesize(encodings, save_names, checkpoint_path=checkpoint_path) # Single gpu else: fastgen.synthesize(encodings, save_names, checkpoint_path=checkpoint_path)
def main(unused_argv=None): os.environ["CUDA_VISIBLE_DEVICES"] = str(FLAGS.gpu_number) source_path = utils.shell_path(FLAGS.source_path) checkpoint_path = utils.shell_path(FLAGS.checkpoint_path) save_path = utils.shell_path(FLAGS.save_path) if not save_path: raise ValueError("Must specify a save_path.") tf.logging.set_verbosity(FLAGS.log) # Use directory of files if tf.gfile.IsDirectory(source_path): files = tf.gfile.ListDirectory(source_path) file_extensions = [os.path.splitext(f)[1] for f in files] if ".wav" in file_extensions: file_extension = ".wav" elif ".npy" in file_extensions: file_extension = ".npy" else: raise RuntimeError("Folder must contain .wav or .npy files.") file_extension = ".npy" if FLAGS.npy_only else file_extension files = sorted([ os.path.join(source_path, fname) for fname in files if fname.lower().endswith(file_extension) ]) # Use a single file elif source_path.lower().endswith((".wav", ".npy")): file_extension = os.path.splitext(source_path.lower())[1] files = [source_path] else: raise ValueError( "source_path {} must be a folder or file.".format(source_path)) # Now synthesize from files one batch at a time batch_size = FLAGS.batch_size sample_length = FLAGS.sample_length n = len(files) for start in range(0, n, batch_size): end = start + batch_size batch_files = files[start:end] save_names = [ os.path.join(save_path, "gen_" + os.path.splitext(os.path.basename(f))[0] + ".wav") for f in batch_files ] # Encode waveforms if file_extension == ".wav": batch_data = fastgen.load_batch_audio( batch_files, sample_length=sample_length) encodings = fastgen.encode( batch_data, checkpoint_path, sample_length=sample_length) # Or load encodings else: encodings = fastgen.load_batch_encodings( batch_files, sample_length=sample_length) # Synthesize multi-gpu if FLAGS.gpu_number != 0: with tf.device("/device:GPU:%d" % FLAGS.gpu_number): fastgen.synthesize( encodings, save_names, checkpoint_path=checkpoint_path) # Single gpu else: fastgen.synthesize( encodings, save_names, checkpoint_path=checkpoint_path)