模型:
padmalcom/tts-tacotron2-german
使用使用speechbrain在custom german dataset上训练的Tacotron2进行文本到语音 (TTS),使用了12天的音频。
训练了39个epoch(英语的speechbrain模型需要750个epoch训练),因此还有改进的空间,很可能很快会更新模型。幸运的是,hifigan vocoder可以在不同语言上使用。
安装speechbrain。
pip install speechbrain
生成频谱图(第17行),并使用hifigan生成wav文件(第18行)。
import torchaudio
from speechbrain.pretrained import Tacotron2
from speechbrain.pretrained import HIFIGAN
# Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
tacotron2 = Tacotron2.from_hparams(source="padmalcom/tts-tacotron2-german", 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("Die Sonne schien den ganzen Tag.")
# Running Vocoder (spectrogram-to-waveform)
waveforms = hifi_gan.decode_batch(mel_output)
# Save the waverform
torchaudio.save('example_TTS.wav',waveforms.squeeze(1), 22050)