🚀 Parler-TTS Mini 多語言版
Parler-TTS Mini 多語言版 是 Parler-TTS Mini 的多語言擴展版本。它能夠將文本轉換為語音,支持英語、法語、西班牙語、葡萄牙語、波蘭語、德語、意大利語和荷蘭語等 8 種歐洲語言。該模型經過精心微調,在多種數據集上進行訓練,具有出色的性能和廣泛的應用潛力。
🚀 快速開始
安裝
使用 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-mini-multilingual").to(device)
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-mini-multilingual")
description_tokenizer = AutoTokenizer.from_pretrained(model.config.text_encoder._name_or_path)
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 = description_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)
⚠️ 重要提示
與之前版本的 Parler-TTS 不同,這裡我們使用兩個分詞器 - 一個用於提示,一個用於描述。
💡 使用建議
- 我們已經設置了一個 推理指南 來加快生成速度。可以考慮使用 SDPA、torch.compile、批處理和流式傳輸等技術!
- 在提示中包含 “very clear audio” 以生成最高質量的音頻,包含 “very noisy audio” 以生成具有高背景噪音的音頻。
- 可以使用標點符號來控制生成語音的韻律,例如使用逗號在語音中添加小停頓。
- 其餘的語音特徵(性別、語速、音高和混響)可以直接通過提示進行控制。
✨ 主要特性
- 多語言支持:支持 8 種歐洲語言,包括英語、法語、西班牙語、葡萄牙語、波蘭語、德語、意大利語和荷蘭語。
- 特徵可控:可以通過簡單的文本提示控制語音的各種特徵,如性別、語速、音高、背景噪音等。
- 開源開放:完全開源發佈,所有數據集、預處理代碼、訓練代碼和模型權重都在寬鬆許可下公開,方便社區在此基礎上進行開發。
📦 安裝指南
使用以下命令安裝 Parler-TTS 庫:
pip install git+https://github.com/huggingface/parler-tts.git
💻 使用示例
基礎用法
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-multilingual").to(device)
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-mini-multilingual")
description_tokenizer = AutoTokenizer.from_pretrained(model.config.text_encoder._name_or_path)
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 = description_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)
📚 詳細文檔
動機
Parler-TTS 是對 Dan Lyth 和 Simon King(分別來自 Stability AI 和愛丁堡大學)的論文 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 許可下發布。