Chatterbox 声音克隆
在 Clore.ai 的 GPU 上运行 Resemble AI 的 Chatterbox TTS,用于零样本声音克隆和多语言语音合成。
最后更新于
这有帮助吗?
这有帮助吗?
# 从 PyPI 安装
pip install chatterbox-tts
# 或从源码安装
git clone https://github.com/resemble-ai/chatterbox.git
cd chatterbox
pip install -e .
# 验证
python -c "from chatterbox.tts import ChatterboxTTS; print('Chatterbox ready')"import torchaudio as ta
from chatterbox.tts_turbo import ChatterboxTurboTTS
model = ChatterboxTurboTTS.from_pretrained(device="cuda")
# 带副语言标签的基础 TTS
text = "Hey, welcome back! [chuckle] I've got some great news for you today."
# 语音克隆 — 提供 10 秒以上的参考音频片段
wav = model.generate(text, audio_prompt_path="reference_voice.wav")
ta.save("output_turbo.wav", wav, model.sr)
print(f"Saved at {model.sr} Hz")import torchaudio as ta
from chatterbox.tts import ChatterboxTTS
model = ChatterboxTTS.from_pretrained(device="cuda")
text = "The quick brown fox jumps over the lazy dog. It was a beautiful morning."
# 不使用语音克隆生成(使用默认语音)
wav = model.generate(text)
ta.save("output_default.wav", wav, model.sr)
# 使用语音克隆生成
wav = model.generate(text, audio_prompt_path="my_voice_sample.wav")
ta.save("output_cloned.wav", wav, model.sr)import torchaudio as ta
from chatterbox.mtl_tts import ChatterboxMultilingualTTS
model = ChatterboxMultilingualTTS.from_pretrained(device="cuda")
# 法语
french_text = "Bonjour, comment allez-vous? Bienvenue dans notre démonstration."
wav_fr = model.generate(french_text, language_id="fr")
ta.save("output_french.wav", wav_fr, model.sr)
# Japanese
japanese_text = "こんにちは、テキスト読み上げのデモンストレーションです。"
wav_ja = model.generate(japanese_text, language_id="ja")
ta.save("output_japanese.wav", wav_ja, model.sr)
# 俄语与语音克隆
russian_text = "Привет! Это демонстрация синтеза речи на русском языке."
wav_ru = model.generate(
russian_text,
language_id="ru",
audio_prompt_path="russian_speaker.wav"
)
ta.save("output_russian.wav", wav_ru, model.sr)
print("Multilingual generation complete")import torchaudio as ta
from chatterbox.tts_turbo import ChatterboxTurboTTS
model = ChatterboxTurboTTS.from_pretrained(device="cuda")
samples = [
("greeting", "Hi there! [laugh] It's so good to see you again."),
("nervous", "Um, well [cough] I'm not really sure about that."),
("excited", "Oh my gosh! [chuckle] That's absolutely incredible news!"),
]
for name, text in samples:
wav = model.generate(text, audio_prompt_path="speaker_ref.wav")
ta.save(f"para_{name}.wav", wav, model.sr)
prompt=prompt,import torchaudio as ta
from chatterbox.tts import ChatterboxTTS
批处理处理
model = ChatterboxTTS.from_pretrained(device="cuda")
# 处理一系列行(例如有声书章节)
lines = [
"Chapter one. The adventure begins.",
"It was a dark and stormy night.",
"The hero stood at the crossroads, uncertain of the path ahead.",
]
os.makedirs("output_batch", exist_ok=True)
for i, line in enumerate(lines):
wav = model.generate(line, audio_prompt_path="narrator_voice.wav")
ta.save(f"output_batch/line_{i:03d}.wav", wav, model.sr)
print(f"[{i+1}/{len(lines)}] {line[:40]}...")
print("Batch processing complete")