Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Last active June 4, 2024 02:31
Show Gist options
  • Save iqiancheng/3d02ad4bf54216bcba0546222a2491c5 to your computer and use it in GitHub Desktop.
Save iqiancheng/3d02ad4bf54216bcba0546222a2491c5 to your computer and use it in GitHub Desktop.
ChatTTS 保存并基本固定音色的方法 how to keep ChattTTS voice tone properly

保存并基本固定音色的方法

采用core里的sample_random_speaker方法随机生成音色:

text = "简短的测试文字,可以节省生成测试语音的时间"

rand_spk = chat.sample_random_speaker()
params_infer_code = {
    'prompt':'[speed_5]',
    'temperature':.3,
    'spk_emb': rand_spk,
}

wavs = chat.infer(text, use_decoder=True, params_infer_code=params_infer_code)

觉得音色不错的话,可以采用如下方式保存:

torch.save(rand_spk, 'speaker/girl4.pth')

下次再使用这个音色的话可以采用torch.load进行加载:

rand_spk = torch.load('speaker/girl4.pth')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment