Parler-TTS 是一個輕量級文本轉語音 (TTS) 模型,能夠生成高品質、自然的語音,並且可以控制說話者的風格(性別、音調、說話方式等)。該項目是對 Stability AI 和愛丁堡大學研究論文《Natural language guidance of high-fidelity text-to-speech with synthetic annotations》的開源實現。
pip install git+https://github.com/huggingface/parler-tts.git
pip3 install --pre torch torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
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-mini-v1").to(device)
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-mini-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 個預定義說話者,包括:Laura, Gary, Jon, Lea, Karen, Rick, Brenda, David, Eileen, Jordan, Mike, Yann, Joy, James, Eric, Lauren, Rose, Will, Jason, Aaron, Naomie, Alisa, Patrick, Jerry, Tina, Jenna, Bill, Tom, Carol, Barbara, Rebecca, Anna, Bruce, Emily。
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)
accelerate launch ./training/run_parler_tts_training.py ./helpers/training_configs/starting_point_v1.json
項目提供了完整的訓練和微調指南,包括:
項目包含多種性能優化:
項目採用寬鬆的開源許可證,鼓勵社區貢獻和商業使用。如果使用該項目,建議引用:
@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}}
}
項目歡迎社區貢獻,特別是在以下方面:
Parler TTS 代表了開源 TTS 技術的重要進展,為研究者和開發者提供了強大而靈活的文本轉語音解決方案。