重要提示

您正在查看 NeMo 2.0 文档。此版本引入了 API 的重大更改和一个新的库,NeMo Run。我们目前正在将 NeMo 1.0 的所有功能移植到 2.0。有关先前版本或 2.0 中尚不可用的功能的文档,请参阅NeMo 24.07 文档

NeMo TTS 配置文件#

本节介绍 NeMo 配置文件设置,该设置特定于 TTS 集合中的模型。有关如何设置和运行所有 NeMo 模型通用的实验(例如,实验管理器和 PyTorch Lightning 训练器参数)的常规信息,请参阅NeMo 模型部分。

NeMo TTS 配置文件的模型部分通常需要有关正在使用的数据集、音频文件的预处理器、正在执行的任何增强的参数以及模型架构规范的信息。此页面上的部分更详细地介绍了这些内容。

所有 NeMo TTS 脚本的示例配置文件都可以在examples 的 config 目录中找到。

数据集配置#

训练、验证和测试参数分别使用配置文件中的 model.train_dsmodel.validation_dsmodel.test_ds 部分指定。根据任务的不同,可能有参数指定音频文件的采样率、补充数据(如语音/文本对齐先验和说话人 ID)等、从音频信号中修剪前导和尾随静音的阈值、音高归一化参数等等。您还可以决定将诸如 manifest_filepath 之类的字段留空,以便在运行时通过命令行指定。

nemo.collections.tts.data.dataset.TTSDataset 接受的任何初始化参数都可以在配置文件中设置。有关数据集类及其各自参数的列表,请参阅 API 的数据集处理类部分。一个示例 TTS 训练和验证配置应如下所示

model:
  train_ds:
    dataset:
      _target_: nemo.collections.tts.data.dataset.TTSDataset
      manifest_filepath: ???
      sample_rate: 44100
      sup_data_path: ???
      sup_data_types: ["align_prior_matrix", "pitch"]
      n_fft: 2048
      win_length: 2048
      hop_length: 512
      window: hann
      n_mels: 80
      lowfreq: 0
      highfreq: null
      max_duration: null
      min_duration: 0.1
      ignore_file: null
      trim: false
      pitch_fmin: 65.40639132514966
      pitch_fmax: 2093.004522404789
      pitch_norm: true
      pitch_mean: 212.35873413085938
      pitch_std: 68.52806091308594
      use_beta_binomial_interpolator: true

    dataloader_params:
      drop_last: false
      shuffle: true
      batch_size: 32
      num_workers: 12
      pin_memory: true

音频预处理器配置#

如果您正在为实验加载音频文件,您可能需要使用预处理器将原始音频信号转换为特征(例如,梅尔频谱图或 MFCC)。配置的 preprocessor 部分通过 _target_ 字段指定要使用的音频预处理器,以及该预处理器的任何初始化参数。以下是指定预处理器的示例。有关预处理器选项、预期参数和默认值,请参阅音频预处理器 API 部分。

model:
  preprocessor:
    _target_: nemo.collections.asr.modules.AudioToMelSpectrogramPreprocessor
    features: 80
    lowfreq: 0
    highfreq: null
    n_fft: 2048
    n_window_size: 2048
    window_size: false
    n_window_stride: 512
    window_stride: false
    pad_to: 1
    pad_value: 0
    sample_rate: 44100
    window: hann
    normalize: null
    preemph: null
    dither: 0.0
    frame_splicing: 1
    log: true
    log_zero_guard_type: add
    log_zero_guard_value: 1e-05
    mag_power: 1.0

文本规范化器配置#

文本规范化 (TN) 将书面形式的文本转换为口语形式,它是文本到语音合成之前必不可少的预处理步骤。TN 确保 TTS 可以处理所有输入文本,而不会跳过未知符号。例如,“$123”转换为“一百二十三美元”。目前,NeMo 支持英语、德语、西班牙语和汉语的文本规范化器。有关更多详细信息,请参阅上一节(逆)文本规范化。下面显示了指定英语文本规范化器的示例。

model:
  text_normalizer:
    _target_: nemo_text_processing.text_normalization.normalize.Normalizer
    lang: en
    input_case: cased

  text_normalizer_call_kwargs:
    verbose: false
    punct_pre_process: true
    punct_post_process: true

分词器配置#

分词将输入文本字符串转换为整数标记列表。它可能会在字符串中填充前导和/或尾随空格。NeMo 分词器支持仅字素输入、仅音素输入或字素和音素输入的混合,以消除英语、德语和西班牙语异形同音异义词的发音歧义。它还利用字素到音素 (G2P) 工具来音译词汇表外 (OOV) 单词。有关更多详细信息,请参阅G2P 部分TTS 分词器集合。请注意,G2P 集成到 NeMo TTS 分词器管道即将推出。以下示例设置了一个 EnglishPhonemesTokenizer,其中混合了字素和音素输入,其中异形同音异义词列表中显示的每个单词有 50% 的机会被音译为字素或音素。

model:
  text_tokenizer:
    _target_: nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers.EnglishPhonemesTokenizer
    punct: true
    stresses: true
    chars: true
    apostrophe: true
    pad_with_space: true
    g2p:
      _target_: nemo.collections.tts.g2p.models.en_us_arpabet.EnglishG2p
      phoneme_dict: ${phoneme_dict_path}
      heteronyms: ${heteronyms_path}
    phoneme_probability: 0.5

模型架构配置#

每个配置文件都应描述用于实验的模型架构。NeMo TTS 集合中的模型需要几个模块部分,其中 _target_ 字段指定使用哪个模型架构或组件。有关详细信息,请参阅TTS 模块集合。下面显示了一个 FastPitch 模型架构的示例,

model:
  input_fft: #n_embed and padding_idx are added by the model
    _target_: nemo.collections.tts.modules.transformer.FFTransformerEncoder
    n_layer: 6
    n_head: 1
    d_model: 384
    d_head: 64
    d_inner: 1536
    kernel_size: 3
    dropout: 0.1
    dropatt: 0.1
    dropemb: 0.0
    d_embed: 384

  output_fft:
    _target_: nemo.collections.tts.modules.transformer.FFTransformerDecoder
    n_layer: 6
    n_head: 1
    d_model: 384
    d_head: 64
    d_inner: 1536
    kernel_size: 3
    dropout: 0.1
    dropatt: 0.1
    dropemb: 0.0

  alignment_module:
    _target_: nemo.collections.tts.modules.aligner.AlignmentEncoder
    n_text_channels: 384

  duration_predictor:
    _target_: nemo.collections.tts.modules.fastpitch.TemporalPredictor
    input_size: 384
    kernel_size: 3
    filter_size: 256
    dropout: 0.1
    n_layers: 2

  pitch_predictor:
    _target_: nemo.collections.tts.modules.fastpitch.TemporalPredictor
    input_size: 384
    kernel_size: 3
    filter_size: 256
    dropout: 0.1
    n_layers: 2

  optim:
    name: adamw
    lr: 1e-3
    betas: [0.9, 0.999]
    weight_decay: 1e-6

    sched:
      name: NoamAnnealing
      warmup_steps: 1000
      last_epoch: -1
      d_model: 1  # Disable scaling based on model dim

微调配置#

所有 TTS 脚本都支持通过将预训练权重从检查点部分/完全加载到当前实例化的模型中来轻松进行微调。请注意,当前实例化的模型应具有与预训练检查点匹配的参数(以便权重可以正确加载)。为了直接微调预先存在的检查点,请按照为新说话人微调 FastPitch的教程进行操作。

可以通过多种方式提供预训练权重

  1. 提供 NeMo 模型的路径(通过 init_from_nemo_model

  2. 提供预训练 NeMo 模型的名称(将通过云下载)(通过 init_from_pretrained_model

  3. 提供 Pytorch Lightning 检查点文件的路径(通过 init_from_ptl_ckpt

examples/tts/<model>_finetune.py中有多个 TTS 模型微调脚本。您可以通过替换 <model> 标签来微调任何模型。下面显示了微调 HiFiGAN 模型的示例。

通过 NeMo 模型进行微调#

python examples/tts/hifigan_finetune.py \
    --config-path=<path to dir of configs> \
    --config-name=<name of config without .yaml>) \
    model/train_ds=train_ds_finetune \
    model/validation_ds=val_ds_finetune \
    train_dataset="<path to manifest file>" \
    validation_dataset="<path to manifest file>" \
    model.optim.lr=0.00001 \
    ~model.optim.sched \
    trainer.devices=-1 \
    trainer.accelerator='gpu' \
    trainer.max_epochs=50 \
    +init_from_nemo_model="<path to .nemo model file>"

通过 NeMo 预训练模型名称进行微调#

python examples/tts/hifigan_finetune.py \
    --config-path=<path to dir of configs> \
    --config-name=<name of config without .yaml>) \
    model/train_ds=train_ds_finetune \
    model/validation_ds=val_ds_finetune \
    train_dataset="<path to manifest file>" \
    validation_dataset="<path to manifest file>" \
    model.optim.lr=0.00001 \
    ~model.optim.sched \
    trainer.devices=-1 \
    trainer.accelerator='gpu' \
    trainer.max_epochs=50 \
    +init_from_pretrained_model="<name of pretrained checkpoint>"

通过 Pytorch Lightning 检查点进行微调#

python examples/tts/hifigan_finetune.py \
    --config-path=<path to dir of configs> \
    --config-name=<name of config without .yaml>) \
    model/train_ds=train_ds_finetune \
    model/validation_ds=val_ds_finetune \
    train_dataset="<path to manifest file>" \
    validation_dataset="<path to manifest file>" \
    model.optim.lr=0.00001 \
    ~model.optim.sched \
    trainer.devices=-1 \
    trainer.accelerator='gpu' \
    trainer.max_epochs=50 \
    +init_from_ptl_ckpt="<name of pytorch lightning checkpoint>"