def one_vs_one(source, target): # Print log logging.debug('Converting audio %s to target %s', source, target) # Create output path source_file_name = source.split('/') source_file_name = source_file_name[len(source_file_name) - 1] source_file_name = source_file_name.split(".")[0] str_path = source_file_name + "_to_t" + target + ".wav" #f'{source_file_name}_to_t{target}.wav' output_path = os.path.join(conversions_dir, str_path) # Get features and variables to perform the conversion _, spec = get_spectrograms(source) spec_expand = np.expand_dims(spec, axis=0) spec_tensor = torch.from_numpy(spec_expand).type(torch.FloatTensor) c = Variable(torch.from_numpy(np.array([int(target)]))).cuda() # Convert audio to target speaker result = solver.test_step(spec_tensor, c, gen=args.use_gen) result = result.squeeze(axis=0).transpose((1, 0)) # Generate and save converted audio wav_data = spectrogram2wav(result) write(output_path, rate=args.sample_rate, data=wav_data)
parser.add_argument('-hps', help='The path of hyper-parameter set', default='vctk.json') parser.add_argument('-model', '-m', help='The path of model checkpoint') parser.add_argument('-source', '-s', help='The path of source .wav file') parser.add_argument( '-target', '-t', help= 'Target speaker id (integer). Same order as the speaker list when preprocessing (en_speaker_used.txt)' ) parser.add_argument('-output', '-o', help='output .wav path') parser.add_argument('-sample_rate', '-sr', default=16000, type=int) parser.add_argument('--use_gen', default=True, action='store_true') args = parser.parse_args() hps = Hps() hps.load(args.hps) hps_tuple = hps.get_tuple() solver = Solver(hps_tuple, None) solver.load_model(args.model) _, spec = get_spectrograms(args.source) spec_expand = np.expand_dims(spec, axis=0) spec_tensor = torch.from_numpy(spec_expand).type(torch.FloatTensor) c = Variable(torch.from_numpy(np.array([int(args.target)]))).cuda() result = solver.test_step(spec_tensor, c, gen=args.use_gen) result = result.squeeze(axis=0).transpose((1, 0)) wav_data = spectrogram2wav(result) write(args.output, rate=args.sample_rate, data=wav_data)
def sp2wav(sp): #exp_sp = np.exp(sp) exp_sp = sp wav_data = spectrogram2wav(exp_sp) return wav_data
def sp2wav(sp): exp_sp = sp wav_data = spectrogram2wav(exp_sp) return wav_data