Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/chatterbox/mtl_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ def from_local(cls, ckpt_dir, device) -> 'ChatterboxMultilingualTTS':
return cls(t3, s3gen, ve, tokenizer, device, conds=conds)

@classmethod
def from_pretrained(cls, device: torch.device) -> 'ChatterboxMultilingualTTS':
def from_pretrained(cls, device: torch.device, **kwargs) -> 'ChatterboxMultilingualTTS':

# Check if model_snapshot_path is provided in kwargs
if 'model_snapshot_path' in kwargs:
model_snapshot_path = Path(kwargs['model_snapshot_path'])
if model_snapshot_path.exists():
return cls.from_local(ckpt_dir=model_snapshot_path, device=device)
ckpt_dir = Path(
snapshot_download(
repo_id=REPO_ID,
Expand Down
7 changes: 6 additions & 1 deletion src/chatterbox/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ def from_local(cls, ckpt_dir, device) -> 'ChatterboxTTS':
return cls(t3, s3gen, ve, tokenizer, device, conds=conds)

@classmethod
def from_pretrained(cls, device) -> 'ChatterboxTTS':
def from_pretrained(cls, device, **kwargs) -> 'ChatterboxTTS':
# Check if MPS is available on macOS
if device == "mps" and not torch.backends.mps.is_available():
if not torch.backends.mps.is_built():
print("MPS not available because the current PyTorch install was not built with MPS enabled.")
else:
print("MPS not available because the current MacOS version is not 12.3+ and/or you do not have an MPS-enabled device on this machine.")
device = "cpu"
# Check if model_snapshot_path is provided in kwargs
if 'model_snapshot_path' in kwargs:
model_snapshot_path = Path(kwargs['model_snapshot_path'])
if model_snapshot_path.exists():
return cls.from_local(ckpt_dir=model_snapshot_path, device=device)

for fpath in ["ve.safetensors", "t3_cfg.safetensors", "s3gen.safetensors", "tokenizer.json", "conds.pt"]:
local_path = hf_hub_download(repo_id=REPO_ID, filename=fpath)
Expand Down
8 changes: 7 additions & 1 deletion src/chatterbox/tts_turbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def from_local(cls, ckpt_dir, device) -> 'ChatterboxTurboTTS':
return cls(t3, s3gen, ve, tokenizer, device, conds=conds)

@classmethod
def from_pretrained(cls, device) -> 'ChatterboxTurboTTS':
def from_pretrained(cls, device, **kwargs) -> 'ChatterboxTurboTTS':
# Check if MPS is available on macOS
if device == "mps" and not torch.backends.mps.is_available():
if not torch.backends.mps.is_built():
Expand All @@ -192,6 +192,12 @@ def from_pretrained(cls, device) -> 'ChatterboxTurboTTS':
print("MPS not available because the current MacOS version is not 12.3+ and/or you do not have an MPS-enabled device on this machine.")
device = "cpu"

# Check if model_snapshot_path is provided in kwargs
if 'model_snapshot_path' in kwargs:
model_snapshot_path = Path(kwargs['model_snapshot_path'])
if model_snapshot_path.exists():
return cls.from_local(ckpt_dir=model_snapshot_path, device=device)

local_path = snapshot_download(
repo_id=REPO_ID,
token=os.getenv("HF_TOKEN") or True,
Expand Down
10 changes: 8 additions & 2 deletions src/chatterbox/vc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ def from_local(cls, ckpt_dir, device) -> 'ChatterboxVC':
return cls(s3gen, device, ref_dict=ref_dict)

@classmethod
def from_pretrained(cls, device) -> 'ChatterboxVC':
def from_pretrained(cls, device, **kwargs) -> 'ChatterboxVC':
# Check if MPS is available on macOS
if device == "mps" and not torch.backends.mps.is_available():
if not torch.backends.mps.is_built():
print("MPS not available because the current PyTorch install was not built with MPS enabled.")
else:
print("MPS not available because the current MacOS version is not 12.3+ and/or you do not have an MPS-enabled device on this machine.")
device = "cpu"


# Check if model_snapshot_path is provided in kwargs
if 'model_snapshot_path' in kwargs:
model_snapshot_path = Path(kwargs['model_snapshot_path'])
if model_snapshot_path.exists():
return cls.from_local(ckpt_dir=model_snapshot_path, device=device)

for fpath in ["s3gen.safetensors", "conds.pt"]:
local_path = hf_hub_download(repo_id=REPO_ID, filename=fpath)

Expand Down