模型:

Sunbird/sunbird-lug-tts

英文

Sunbird AI基于卢干达文本训练的文本转语音(TTS)模型

使用专业工作室录音训练的Tacotron2进行文本转语音(TTS)

此存储库提供了使用SpeechBrain进行文本转语音(TTS)所需的所有工具。

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

安装SpeechBrain

pip install 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="/Sunbird/sunbird-lug-tts", 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("Mbagaliza Christmass Enungi Nomwaka Omugya Gubaberere Gwamirembe")

# 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 = [
       "Nsanyuse okukulaba",
       "Erinnya lyo ggwe ani?",
       "Mbagaliza Christmass Enungi Nomwaka Omugya Gubaberere Gwamirembe"
     ]
mel_outputs, mel_lengths, alignments = tacotron2.encode_batch(items)

在GPU上推断

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