当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python PyTorch Tacotron2TTSBundle用法及代码示例


本文简要介绍python语言中 torchaudio.pipelines.Tacotron2TTSBundle 的用法。

用法:

class torchaudio.pipelines.Tacotron2TTSBundle

捆绑相关信息以使用预训练 Tacotron2 和声码器的数据类。

该类提供了用于实例化预训练模型的接口以及检索预训练权重所需的信息以及与模型一起使用的附加数据。

Torchaudio 库实例化了这个类的对象,每个对象代表一个不同的预训练模型。客户端代码应通过这些实例访问预训练模型。

请参阅下面的用法和可用值。

示例 - 使用 Tacotron2 和 WaveRNN 的基于字符的 TTS 管道
>>> import torchaudio
>>>
>>> text = "Hello, T T S !"
>>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_CHAR_LJSPEECH
>>>
>>> # Build processor, Tacotron2 and WaveRNN model
>>> processor = bundle.get_text_processor()
>>> tacotron2 = bundle.get_tacotron2()
Downloading:
100%|███████████████████████████████| 107M/107M [00:01<00:00, 87.9MB/s]
>>> vocoder = bundle.get_vocoder()
Downloading:
100%|███████████████████████████████| 16.7M/16.7M [00:00<00:00, 78.1MB/s]
>>>
>>> # Encode text
>>> input, lengths = processor(text)
>>>
>>> # Generate (mel-scale) spectrogram
>>> specgram, lengths, _ = tacotron2.infer(input, lengths)
>>>
>>> # Convert spectrogram to waveform
>>> waveforms, lengths = vocoder(specgram, lengths)
>>>
>>> torchaudio.save('hello-tts.wav', waveforms[0], vocoder.sample_rate)
示例 - 使用 Tacotron2 和 WaveRNN 的基于音素的 TTS 管道
>>>
>>> # Note:
>>> #     This bundle uses pre-trained DeepPhonemizer as
>>> #     the text pre-processor.
>>> #     Please install deep-phonemizer.
>>> #     See https://github.com/as-ideas/DeepPhonemizer
>>> #     The pretrained weight is automatically downloaded.
>>>
>>> import torchaudio
>>>
>>> text = "Hello, TTS!"
>>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_PHONEME_LJSPEECH
>>>
>>> # Build processor, Tacotron2 and WaveRNN model
>>> processor = bundle.get_text_processor()
Downloading:
100%|███████████████████████████████| 63.6M/63.6M [00:04<00:00, 15.3MB/s]
>>> tacotron2 = bundle.get_tacotron2()
Downloading:
100%|███████████████████████████████| 107M/107M [00:01<00:00, 87.9MB/s]
>>> vocoder = bundle.get_vocoder()
Downloading:
100%|███████████████████████████████| 16.7M/16.7M [00:00<00:00, 78.1MB/s]
>>>
>>> # Encode text
>>> input, lengths = processor(text)
>>>
>>> # Generate (mel-scale) spectrogram
>>> specgram, lengths, _ = tacotron2.infer(input, lengths)
>>>
>>> # Convert spectrogram to waveform
>>> waveforms, lengths = vocoder(specgram, lengths)
>>>
>>> torchaudio.save('hello-tts.wav', waveforms[0], vocoder.sample_rate)

相关用法


注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torchaudio.pipelines.Tacotron2TTSBundle。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。