Views
No views yet
exaggeration=0.5, cfg=0.5) work well for most prompts.cfg to around 0.3 can improve pacing.cfg values (e.g. ~0.3) and increase exaggeration to around 0.7 or higher.exaggeration tends to speed up speech; reducing cfg helps compensate with slower, more deliberate pacing.pip install chatterbox-tts1import torchaudio as ta
2from chatterbox.tts import ChatterboxTTS
3
4model = ChatterboxTTS.from_pretrained(device="cuda")
5
6text = "Ezreal and Jinx teamed up with Ahri, Yasuo, and Teemo to take down the enemy's Nexus in an epic late-game pentakill."
7wav = model.generate(text)
8ta.save("test-1.wav", wav, model.sr)
9
10# If you want to synthesize with a different voice, specify the audio prompt
11AUDIO_PROMPT_PATH="YOUR_FILE.wav"
12wav = model.generate(text, audio_prompt_path=AUDIO_PROMPT_PATH)
13ta.save("test-2.wav", wav, model.sr)1import torchaudio as ta
2from chatterbox.mtl_tts import ChatterboxMultilingualTTS
3
4multilingual_model = ChatterboxMultilingualTTS.from_pretrained(device="cuda")
5
6french_text = "Bonjour, comment ça va? Ceci est le modèle de synthèse vocale multilingue Chatterbox, il prend en charge 23 langues."
7wav_french = multilingual_model.generate(french_text, language_id="fr")
8ta.save("test-french.wav", wav_french, model.sr)
9
10chinese_text = "你好,今天天气真不错,希望你有一个愉快的周末。"
11wav_chinese = multilingual_model.generate(chinese_text, language_id="zh")
12ta.save("test-chinese.wav", wav_chinese, model.sr)example_tts.py for more examples.1uv init --python 3.11
2uv sync
3source .venv/bin/activate
4git clone https://github.com/resemble-ai/chatterbox.git
5cd chatterbox
6# remove "gradio==5.44.1" and russian-text-stresser from pyproject.toml
7python -m pip install -e .
8
9# mac run:
10python example_for_mac.py1#example_fa.py
2from chatterbox.mtl_tts import ChatterboxMultilingualTTS
3import torch
4import torchaudio as ta
5from safetensors.torch import load_file as load_safetensors
6from huggingface_hub import hf_hub_download, login
7import os
8
9# Detect device (Mac with M1/M2/M3/M4)
10device = "mps" if torch.backends.mps.is_available() else "cpu"
11map_location = torch.device(device)
12
13torch_load_original = torch.load
14def patched_torch_load(*args, **kwargs):
15 if 'map_location' not in kwargs:
16 kwargs['map_location'] = map_location
17 return torch_load_original(*args, **kwargs)
18
19torch.load = patched_torch_load
20
21# Load the multilingual TTS model, making sure it uses the CPU
22multilingual_model = ChatterboxMultilingualTTS.from_pretrained(device)
23
24# read token
25token = "YOUR_TOKEN"
26login(token)
27
28# Define the model repo and file path
29model_repo = "Thomcles/Chatterbox-TTS-Persian-Farsi"
30file_name = "t3_fa.safetensors"
31
32# Define the cache directory (your custom local folder)
33cache_dir = "./cacheModel"
34
35# Create the cache directory if it doesn't exist
36os.makedirs(cache_dir, exist_ok=True)
37
38# Download the model weights to the specified cache directory
39file_path = hf_hub_download(repo_id=model_repo, filename=file_name, cache_dir=cache_dir)
40
41print(f"Model weights downloaded to: {file_path}")
42
43# Load the T3 model state dict for Persian, explicitly mapping to CPU
44# Use `torch.load` with map_location to ensure it loads on the CPU
45t3_state = load_safetensors(file_path, device='cpu')
46
47# Load the T3 model's state dict into the multilingual model and move it to the CPU
48multilingual_model.t3.load_state_dict(t3_state)
49multilingual_model.t3.to(device).eval() # Ensure it's on CPU
50
51# Define the Persian text you want to convert to speech
52persian_text = "سلام! به آزمایش تبدیل متن به گفتار خوش آمدید."
53
54
55# Generate the speech for the provided Persian text
56AUDIO_PROMPT_PATH = "target_voice.wav"
57wav_persian = multilingual_model.generate(
58 persian_text,
59 language_id=None,
60 audio_prompt_path=AUDIO_PROMPT_PATH,
61 exaggeration=0.5,
62 cfg_weight=0.5
63)
64
65# Save the generated speech to a WAV file
66ta.save("test-fa.wav", wav_persian, multilingual_model.sr)
67
68print("Speech synthesis complete, saved as 'test-fa.wav'")