Instructions to use openbmb/VoxCPM2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- VoxCPM
How to use openbmb/VoxCPM2 with VoxCPM:
import soundfile as sf from voxcpm import VoxCPM model = VoxCPM.from_pretrained("openbmb/VoxCPM2") wav = model.generate( text="VoxCPM is an innovative end-to-end TTS model from ModelBest, designed to generate highly expressive speech.", prompt_wav_path=None, # optional: path to a prompt speech for voice cloning prompt_text=None, # optional: reference text cfg_value=2.0, # LM guidance on LocDiT, higher for better adherence to the prompt, but maybe worse inference_timesteps=10, # LocDiT inference timesteps, higher for better result, lower for fast speed normalize=True, # enable external TN tool denoise=True, # enable external Denoise tool retry_badcase=True, # enable retrying mode for some bad cases (unstoppable) retry_badcase_max_times=3, # maximum retrying times retry_badcase_ratio_threshold=6.0, # maximum length restriction for bad case detection (simple but effective), it could be adjusted for slow pace speech ) sf.write("output.wav", wav, 16000) print("saved: output.wav") - Notebooks
- Google Colab
- Kaggle
fix: use hasattr for BatchEncoding compatibility
Browse files- tokenization_voxcpm2.py +2 -2
tokenization_voxcpm2.py
CHANGED
|
@@ -57,7 +57,7 @@ class VoxCPM2Tokenizer(LlamaTokenizerFast):
|
|
| 57 |
|
| 58 |
def __call__(self, text, *args, **kwargs):
|
| 59 |
result = super().__call__(text, *args, **kwargs)
|
| 60 |
-
if
|
| 61 |
ids = result["input_ids"]
|
| 62 |
if isinstance(ids, list) and ids and isinstance(ids[0], list):
|
| 63 |
result["input_ids"] = [self._expand_ids(x) for x in ids]
|
|
@@ -65,7 +65,7 @@ class VoxCPM2Tokenizer(LlamaTokenizerFast):
|
|
| 65 |
result["attention_mask"] = [
|
| 66 |
[1] * len(x) for x in result["input_ids"]
|
| 67 |
]
|
| 68 |
-
|
| 69 |
result["input_ids"] = self._expand_ids(ids)
|
| 70 |
if "attention_mask" in result:
|
| 71 |
result["attention_mask"] = [1] * len(result["input_ids"])
|
|
|
|
| 57 |
|
| 58 |
def __call__(self, text, *args, **kwargs):
|
| 59 |
result = super().__call__(text, *args, **kwargs)
|
| 60 |
+
if hasattr(result, "input_ids"):
|
| 61 |
ids = result["input_ids"]
|
| 62 |
if isinstance(ids, list) and ids and isinstance(ids[0], list):
|
| 63 |
result["input_ids"] = [self._expand_ids(x) for x in ids]
|
|
|
|
| 65 |
result["attention_mask"] = [
|
| 66 |
[1] * len(x) for x in result["input_ids"]
|
| 67 |
]
|
| 68 |
+
elif isinstance(ids, list):
|
| 69 |
result["input_ids"] = self._expand_ids(ids)
|
| 70 |
if "attention_mask" in result:
|
| 71 |
result["attention_mask"] = [1] * len(result["input_ids"])
|