🚀 Parler-TTS Large v1
Parler-TTS Large v1 是一個擁有 22 億參數的文本轉語音(TTS)模型,在 45000 小時的音頻數據上進行訓練。它能夠生成高質量、自然流暢的語音,並且可以通過簡單的文本提示(如性別、背景噪音、語速、音高和混響)來控制語音特徵。
本模型是 Parler-TTS 項目發佈的第二批模型之一,該項目旨在為社區提供 TTS 訓練資源和數據集預處理代碼。此前還發布過 Parler-TTS Mini v1。
🚀 快速開始
📦 安裝指南
使用 Parler-TTS 就像說 “bonjour” 一樣簡單。只需安裝一次庫即可:
pip install git+https://github.com/huggingface/parler-tts.git
💻 使用示例
基礎用法
🎲 使用隨機語音
Parler-TTS 經過訓練,可以通過簡單的文本提示來控制生成語音的特徵,例如:
import torch
from parler_tts import ParlerTTSForConditionalGeneration
from transformers import AutoTokenizer
import soundfile as sf
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model = ParlerTTSForConditionalGeneration.from_pretrained("parler-tts/parler-tts-large-v1").to(device)
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-large-v1")
prompt = "Hey, how are you doing today?"
description = "A female speaker delivers a slightly expressive and animated speech with a moderate speed and pitch. The recording is of very high quality, with the speaker's voice sounding clear and very close up."
input_ids = tokenizer(description, return_tensors="pt").input_ids.to(device)
prompt_input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids)
audio_arr = generation.cpu().numpy().squeeze()
sf.write("parler_tts_out.wav", audio_arr, model.config.sampling_rate)
🎯 使用特定說話人
為了確保生成語音時說話人的一致性,該模型還在 34 位說話人數據上進行了訓練,這些說話人可以通過姓名(如 Jon、Lea、Gary、Jenna、Mike、Laura)來識別。
要使用特定說話人,只需在文本描述中指定即可,例如:Jon's voice is monotone yet slightly fast in delivery, with a very close recording that almost has no background noise.
import torch
from parler_tts import ParlerTTSForConditionalGeneration
from transformers import AutoTokenizer
import soundfile as sf
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model = ParlerTTSForConditionalGeneration.from_pretrained("parler-tts/parler-tts-large-v1").to(device)
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-large-v1")
prompt = "Hey, how are you doing today?"
description = "Jon's voice is monotone yet slightly fast in delivery, with a very close recording that almost has no background noise."
input_ids = tokenizer(description, return_tensors="pt").input_ids.to(device)
prompt_input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids)
audio_arr = generation.cpu().numpy().squeeze()
sf.write("parler_tts_out.wav", audio_arr, model.config.sampling_rate)
💡 使用建議
- 我們已經設置了一個推理指南,可以使生成速度更快,其中涉及 SDPA、torch.compile、批處理和流式傳輸等技術。
- 在提示中包含 “very clear audio” 可以生成最高質量的音頻,包含 “very noisy audio” 則可以生成具有高背景噪音的音頻。
- 可以使用標點符號來控制生成語音的韻律,例如使用逗號在語音中添加小停頓。
- 其餘語音特徵(性別、語速、音高和混響)可以直接通過提示進行控制。
📚 詳細文檔
項目動機
Parler-TTS 是對 Dan Lyth(來自 Stability AI)和 Simon King(來自愛丁堡大學)發表的論文 Natural language guidance of high-fidelity text-to-speech with synthetic annotations 研究工作的復現。
與其他 TTS 模型不同,Parler-TTS 是一個完全開源的版本。所有數據集、預處理代碼、訓練代碼和模型權重都在寬鬆許可下公開發布,這使得社區可以在我們的工作基礎上構建自己強大的 TTS 模型。
Parler-TTS 發佈時還附帶了以下資源:
引用
如果你發現這個倉庫很有用,請考慮引用這項工作以及原始的 Stability AI 論文:
@misc{lacombe-etal-2024-parler-tts,
author = {Yoach Lacombe and Vaibhav Srivastav and Sanchit Gandhi},
title = {Parler-TTS},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/huggingface/parler-tts}}
}
@misc{lyth2024natural,
title={Natural language guidance of high-fidelity text-to-speech with synthetic annotations},
author={Dan Lyth and Simon King},
year={2024},
eprint={2402.01912},
archivePrefix={arXiv},
primaryClass={cs.SD}
}
📄 許可證
該模型遵循 Apache 2.0 許可協議。