def test_create_analyzer(args, frame_period, mcep_order): conf = kwiiyatta.Config() conf.parse_args(args) analyzer = conf.create_analyzer(kwiiyatta.Wavdata(0, None)) assert analyzer.frame_period == frame_period assert analyzer.mel_cepstrum_order == mcep_order
def main(): conf = kwiiyatta.Config() conf.add_argument('--result-dir', type=str, help='Path to write result wav files') conf.add_argument('files', type=str, nargs='+', help='Wav files to convert voice') conf.add_converter_arguments() conf.parse_args() converter = conf.train_converter(use_delta=True) for conv_file in conf.files: conv_path = pathlib.Path(conv_file) diff_MLPG = convert(conf, converter, conv_path) synth_MLPG = convert(conf, converter, conv_path, diffvc=False) result_path = conv_path if conf.result_dir is not None: result_path = pathlib.Path(conf.result_dir) / conv_path.name result_path.parent.mkdir(parents=True, exist_ok=True) result = result_path.with_suffix('.diff.wav') print(f'diff MLPG: {result!s}') diff_MLPG.save(result) result = result_path.with_suffix('.synth.wav') print(f'synth MLPG: {result!s}') synth_MLPG.save(result)
def test_pass_parser(): parser = argparse.ArgumentParser() parser.add_argument('--test-arg', type=str) conf = kwiiyatta.Config(parser) conf.parse_args(['--frame-period', '20', '--test-arg', 'hogehoge']) assert conf.frame_period == 20 assert conf.test_arg == 'hogehoge'
def test_sys_argv_and_parse(): sys.argv += ['--frame-period', '40'] conf = kwiiyatta.Config() conf.parse_args(['--frame-period', '50']) assert conf.frame_period == 40
def test_sys_argv(): sys.argv += ['--frame-period', '30'] conf = kwiiyatta.Config() conf.parse_args() assert conf.frame_period == 30
def test_argument(): conf = kwiiyatta.Config() conf.parse_args(['--frame-period', '10', '--mcep-order', '32']) assert conf.frame_period == 10 assert conf.mcep_order == 32
def test_empty_argument(): conf = kwiiyatta.Config() conf.parse_args() assert conf.frame_period == 5 assert conf.mcep_order == 24
def main(): conf = kwiiyatta.Config() conf.add_argument('source', type=str, help='Source wav file of voice resynthesis') conf.add_argument('--result-dir', type=str, help='Path to write result wav files') conf.add_argument('--mcep', action='store_true', help='Use mel-cepstrum to resynthesize') conf.add_argument('--play', action='store_true', help='Play result wavform') conf.add_argument('--no-save', action='store_true', help='Not to write result wav file, and play wavform') conf.add_argument('--carrier', type=str, help='Wav file to use for carrier') conf.add_argument('--diffvc', action='store_true', help='Use difference MelCepstrum synthesis') conf.add_argument('--result-fs', type=int, help='Result waveform sampling rate') conf.parse_args() conf.play |= conf.no_save source_path = pathlib.Path(conf.source).resolve() source = conf.create_analyzer(source_path, Analyzer=kwiiyatta.analyze_wav) if conf.result_dir is None: result_path = source_path.with_suffix('.resynth.wav') else: result_path = pathlib.Path(conf.result_dir) / source_path.name feature = kwiiyatta.feature(source) wav = None if conf.carrier is not None: carrier = conf.create_analyzer(conf.carrier, Analyzer=kwiiyatta.analyze_wav) feature = kwiiyatta.align(source, carrier) if conf.diffvc: mcep_diff = copy.copy(feature.mel_cepstrum) mcep_diff.data -= carrier.mel_cepstrum.data wav = kwiiyatta.apply_mlsa_filter(carrier.wavdata, mcep_diff) else: feature.f0 = carrier.f0 if wav is None: if conf.mcep: feature.extract_mel_cepstrum() feature.spectrum_envelope = None if conf.result_fs is not None: feature.resample(conf.result_fs) wav = feature.synthesize() if not conf.no_save: result_path.parent.mkdir(parents=True, exist_ok=True) wav.save(result_path) if conf.play: wav.play()