模型:

speechbrain/tts-tacotron2-ljspeech

英文

Text-to-Speech (TTS) 使用在LJSpeech上训练的Tacotron2

此存储库提供了使用SpeechBrain进行文本到语音(TTS)所需的所有工具,使用了在 LJSpeech 上预训练的 Tacotron2 的模型。

预训练模型接受输入的短文本,并产生输出的频谱图。通过在生成的频谱图之上应用声码器(例如HiFIGAN),可以得到最终的波形。

安装SpeechBrain

pip install speechbrain

请注意,我们建议您阅读我们的教程并了解更多有关 SpeechBrain 的信息。

执行文本到语音(TTS)

import torchaudio
from speechbrain.pretrained import Tacotron2
from speechbrain.pretrained import HIFIGAN

# Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")

# Running the TTS
mel_output, mel_length, alignment = tacotron2.encode_text("Mary had a little lamb")

# Running Vocoder (spectrogram-to-waveform)
waveforms = hifi_gan.decode_batch(mel_output)

# Save the waverform
torchaudio.save('example_TTS.wav',waveforms.squeeze(1), 22050)

如果您想一次生成多个句子,可以按照以下方式执行:

from speechbrain.pretrained import Tacotron2
tacotron2 = Tacotron2.from_hparams(source="speechbrain/TTS_Tacotron2", savedir="tmpdir")
items = [
       "A quick brown fox jumped over the lazy dog",
       "How much wood would a woodchuck chuck?",
       "Never odd or even"
     ]
mel_outputs, mel_lengths, alignments = tacotron2.encode_batch(items)

在GPU上进行推理

要在GPU上执行推理,在调用from_hparams方法时添加run_opts={"device":"cuda"}。

训练

该模型是使用SpeechBrain进行训练的。要从头开始训练,请按照以下步骤进行:

  • 克隆SpeechBrain:
  • git clone https://github.com/speechbrain/speechbrain/
    
  • 安装:
  • cd speechbrain
    pip install -r requirements.txt
    pip install -e .
    
  • 运行训练:
  • cd recipes/LJSpeech/TTS/tacotron2/
    python train.py --device=cuda:0 --max_grad_norm=1.0 --data_folder=/your_folder/LJSpeech-1.1 hparams/train.yaml
    

    您可以在这里找到我们的训练结果(模型、日志等) here

    限制

    SpeechBrain团队不对在其他数据集上使用此模型时获得的性能提供任何保证。

    关于SpeechBrain

    引用SpeechBrain

    如果您在研究或商业中使用SpeechBrain,请引用它。

    @misc{speechbrain,
      title={{SpeechBrain}: A General-Purpose Speech Toolkit},
      author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
      year={2021},
      eprint={2106.04624},
      archivePrefix={arXiv},
      primaryClass={eess.AS},
      note={arXiv:2106.04624}
    }