promptttsppで合成音声を試す(Winodows)

初めに

新しくttsのライブラリが出たので触ってみます

論文の中では日本語の音声合成にも触れられていましたが、デモ版では日本語はできないみたいです

環境

  • WIndows 11
  • anaconda
  • RTX 4070 Ti Super

準備

公式のReadMeの通りに進めていきます

conda create -n py38_prompt python=3.8 numpy scipy scikit-learn numba cython pandas tqdm
conda activate py38_prompt
pip install "torch==1.11.0+cu113" "torchvision==0.12.0+cu113" "torchaudio==0.11.0" --extra-index-url https://download.pytorch.org/whl/cu113
pip install -e .

また 以下のhfから事前学習モデルをダウンロードして以下のように配置します

huggingface.co

egs\proposed\bin\conf\demo.yaml の 設定を書き換えます

model_ckpt_path: ./pretrained_model/checkpoint/proposed/last.ckpt
vocoder_ckpt_path: ./pretrained_model/checkpoint/bigvgan_f0_full/last.ckpt
mel_stats_file: ./pretrained_model/checkpoint/pretrained_model_checkpoint_stats.yaml

実行

以下で動かすことできます

python app.py

推論時間は1.7s程度でした

以下の箇所で計測しています

    @torch.no_grad()
    def onclick_synthesis(content_prompt, style_prompt=None, reference_mel=None):
        start_time = time.perf_counter()
        assert style_prompt is not None or reference_mel is not None
        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        phonemes = g2p(content_prompt)
        phonemes = [p if p not in [",", "."] else "sil" for p in phonemes]
        phonemes = [p for p in phonemes if p in symbols]
        phoneme_ids = text_to_sequence(" ".join(phonemes))
        phoneme_ids = torch.LongTensor(phoneme_ids)[None, :].to(device)
        if style_prompt is not None:
            dec, log_cf0, vuv = model.infer(
                phoneme_ids,
                style_prompt=style_prompt,
                use_max=True,
                noise_scale=0.5,
                return_f0=True,
            )
        else:
            reference_mel = (reference_mel - mel_stats["mean"]) / mel_stats["std"]
            reference_mel = reference_mel.to(device)
            dec, log_cf0, vuv = model.infer(
                phoneme_ids,
                reference_mel=reference_mel,
                use_max=True,
                noise_scale=0.5,
                return_f0=True,
            )
        modfs = int(1.0 / (10 * 0.001))
        log_cf0 = lowpass_filter(log_cf0, modfs, cutoff=20)
        f0 = log_cf0.exp()
        f0[vuv < 0.5] = 0
        dec = dec * mel_stats["std"] + mel_stats["mean"]
        wav = vocoder(dec, f0).squeeze(1).cpu()
        
        # 終了時間を記録
        end_time = time.perf_counter()
        inference_time = end_time - start_time
        print(f"推論時間: {inference_time:.4f} 秒")
        return wav