speechbrain.inference.vocoders 模块
指定文本到语音(TTS)模块的推理接口。
- Authors:
阿库·罗赫 2021
彼得·普兰廷加 2021
洛伦·卢戈斯奇 2020
Mirco Ravanelli 2020
Titouan Parcollet 2021
阿卜杜勒·赫巴 2021
安德烈亚斯·诺茨 2022, 2023
Pooneh Mousavi 2023
Sylvain de Langen 2023
阿德尔·穆门 2023
普拉迪亚·坎达尔卡 2023
摘要
类:
一个即用型的DiffWave推理封装器,作为声码器使用。该封装器允许执行生成任务:局部条件生成:mel_spec -> 波形。 |
|
一个即用型的HiFiGAN封装器(mel_spec -> 波形)。 |
|
一个即用型的Unit HiFiGAN封装器(离散单元 -> 波形)。 |
参考
- class speechbrain.inference.vocoders.HIFIGAN(*args, **kwargs)[source]
基础类:
Pretrained一个即用型的HiFiGAN封装器(mel_spec -> 波形)。
Example
>>> tmpdir_vocoder = getfixture('tmpdir') / "vocoder" >>> hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir=tmpdir_vocoder) >>> mel_specs = torch.rand(2, 80,298) >>> waveforms = hifi_gan.decode_batch(mel_specs) >>> # You can use the vocoder coupled with a TTS system >>> # Initialize TTS (tacotron2) >>> tmpdir_tts = getfixture('tmpdir') / "tts" >>> from speechbrain.inference.TTS import Tacotron2 >>> tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir=tmpdir_tts) >>> # 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)
- HPARAMS_NEEDED = ['generator']
- decode_batch(spectrogram, mel_lens=None, hop_len=None)[source]
从一批梅尔频谱图中计算波形
- Parameters:
spectrogram (torch.Tensor) – 梅尔频谱图的批次 [批次, 梅尔, 时间]
mel_lens (torch.tensor) – 批次中mel频谱图长度的列表 可以从Tacotron/FastSpeech的输出中获得
hop_len (int) – 用于提取梅尔频谱图的跳跃长度 应与.yaml文件中的值相同
- Returns:
waveforms – 一批梅尔波形 [批次, 1, 时间]
- Return type:
torch.Tensor
- mask_noise(waveform, mel_lens, hop_len)[source]
在批量推理过程中掩盖由填充引起的噪声
- Parameters:
波形 (torch.tensor) – 生成的波形批次 [批次, 1, 时间]
mel_lens (torch.tensor) – 批次中mel频谱图长度的列表 可以从Tacotron/FastSpeech的输出中获得
hop_len (int) – 用于提取梅尔频谱图的跳跃长度 与.yaml文件中的值相同
- Returns:
waveform – 没有填充噪声的波形批次 [batch, 1, time]
- Return type:
torch.tensor
- decode_spectrogram(spectrogram)[source]
从单个梅尔频谱图计算波形
- Parameters:
spectrogram (torch.Tensor) – 梅尔频谱图 [mels, time]
- Returns:
waveform (torch.Tensor) – 波形 [1, 时间]
音频可以通过以下方式保存
>>> import torchaudio
>>> waveform = torch.rand(1, 666666)
>>> sample_rate = 22050
>>> torchaudio.save(str(getfixture(‘tmpdir’) / “test.wav”), waveform, sample_rate)
- class speechbrain.inference.vocoders.DiffWaveVocoder(*args, **kwargs)[source]
基础类:
Pretrained一个即用型的DiffWave作为声码器的推理封装器。 该封装器允许执行生成任务:
局部条件生成:mel_spec -> waveform
- HPARAMS_NEEDED = ['diffusion']
- decode_batch(mel, hop_len, mel_lens=None, fast_sampling=False, fast_sampling_noise_schedule=None)[source]
从频谱图生成波形
- Parameters:
- Returns:
waveforms – 一批梅尔波形 [批次, 1, 时间]
- Return type:
torch.tensor
- mask_noise(waveform, mel_lens, hop_len)[source]
在批量推理过程中掩盖由填充引起的噪声
- Parameters:
波形 (torch.tensor) – 生成的波形批次 [批次, 1, 时间]
mel_lens (torch.tensor) – 批次中mel频谱图长度的列表 可以从Tacotron/FastSpeech的输出中获得
hop_len (int) – 用于提取梅尔频谱图的跳跃长度 与.yaml文件中的值相同
- Returns:
waveform – 没有填充噪声的波形批次 [batch, 1, time]
- Return type:
torch.tensor
- decode_spectrogram(spectrogram, hop_len, fast_sampling=False, fast_sampling_noise_schedule=None)[source]
从单个梅尔频谱图计算波形
- Parameters:
- Returns:
waveform (torch.tensor) – 波形 [1, 时间]
音频可以通过以下方式保存
>>> import torchaudio
>>> waveform = torch.rand(1, 666666)
>>> sample_rate = 22050
>>> torchaudio.save(str(getfixture(‘tmpdir’) / “test.wav”), waveform, sample_rate)
- class speechbrain.inference.vocoders.UnitHIFIGAN(*args, **kwargs)[source]
基础类:
Pretrained一个即用型的Unit HiFiGAN封装器(离散单元 -> 波形)。
Example
>>> tmpdir_vocoder = getfixture('tmpdir') / "vocoder" >>> hifi_gan = UnitHIFIGAN.from_hparams(source="speechbrain/hifigan-hubert-l1-3-7-12-18-23-k1000-LibriTTS", savedir=tmpdir_vocoder) >>> codes = torch.randint(0, 99, (100, 1)) >>> waveform = hifi_gan.decode_unit(codes)
- HPARAMS_NEEDED = ['generator']
- decode_batch(units, spk=None)[source]
从一批离散单元计算波形
- Parameters:
units (torch.tensor) – 离散单元的批次 [batch, codes]
spk (torch.tensor) – 说话人嵌入的批次 [batch, spk_dim]
- Returns:
waveforms – 一批梅尔波形 [批次, 1, 时间]
- Return type:
torch.tensor