chatterbox icon indicating copy to clipboard operation
chatterbox copied to clipboard

SOLUTION: a dependency installation script for Apple Silicon (only requires brew's python 3.11 installed)

Open pardeike opened this issue 2 months ago • 2 comments

Running the following will install all dependencies in the correct order on macOS 14 or newer (tested with Tahoe) and will also test run a simple generation and play it. I tested it on my MacBook Air M2 with a clean python installation:

install_chatterbox.sh

#!/usr/bin/env bash

# Chatterbox TTS on macOS 14+/Apple Silicon with Python 3.11
# Installs deps in the right order, satisfies s3tokenizer extras, and runs a smoke test.

set -euo pipefail

# Quieter installs and logs
export HF_HUB_DISABLE_TELEMETRY=1
export HF_HUB_DISABLE_PROGRESS_BARS=1
export TOKENIZERS_PARALLELISM=false
export TQDM_DISABLE=1
export PYTHONWARNINGS="ignore::FutureWarning"

PY_BIN="${PY_BIN:-python3.11}"   # override: PY_BIN=/opt/homebrew/bin/python3.11 bash install_chatterbox.sh

[[ "$(uname -s)" == "Darwin" ]] || { echo "macOS only"; exit 1; }
[[ "$(uname -m)" == "arm64"   ]] || { echo "Apple Silicon only"; exit 1; }
command -v "$PY_BIN" >/dev/null || { echo "Python 3.11 not found at: $PY_BIN. Try installing with 'brew install [email protected]'"; exit 1; }

echo "Installing using $("$PY_BIN" -V)"
PIP=( "$PY_BIN" -m pip )

# Quieter, faster, deterministic
export PIP_NO_INPUT=1
export PIP_DEFAULT_TIMEOUT=120

# 0) Tools
"${PIP[@]}" -qq install --upgrade pip setuptools wheel

# 1) Core ML stack (Apple Silicon)
"${PIP[@]}" -qq install torch==2.6.0 torchaudio==2.6.0

# 2) Preinstall numpy so pkuseg’s setup.py can import it
"${PIP[@]}" -qq install numpy==1.25.2

# 3) Chatterbox pinned runtime deps (without the tokenizers yet)
"${PIP[@]}" -qqq install \
  transformers==4.46.3 \
  diffusers==0.29.0 \
  conformer==0.3.2 \
  resemble-perth==1.0.1 \
  safetensors==0.5.3 \
  librosa==0.11.0 \
  gradio==5.44.1 \
  pykakasi==2.3.0

# 4) s3tokenizer + its declared requirements
#    We pin onnx and pre-commit to satisfy 'pip check' and avoid exits.
"${PIP[@]}" -qq install onnx==1.16.2 pre-commit==3.7.1
"${PIP[@]}" -qq install --no-deps s3tokenizer==0.2.0

# 5) pkuseg (needs numpy visible; disable build isolation)
PIP_NO_BUILD_ISOLATION=1 "${PIP[@]}" -qq install pkuseg==0.0.25

# 6) Chatterbox itself, last, without pulling deps again
"${PIP[@]}" -qq install --no-deps chatterbox-tts==0.1.4

# 7) Dependency sanity. Do not abort on minor resolver gripes.
"${PIP[@]}" -qq check || true
echo "Installation done"

# 8) Smoke test: synthesize to out.wav using MPS if available
"$PY_BIN" - <<'PY'
import os, sys, io, contextlib, warnings, torch, subprocess, torchaudio as ta
os.environ["TQDM_DISABLE"]="1"
from transformers.utils import logging as hf_logging
from diffusers.utils import logging as df_logging
hf_logging.set_verbosity_error(); df_logging.set_verbosity_error()
warnings.filterwarnings("ignore", category=FutureWarning)

print("Processing...")
buf = io.StringIO()
with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf), warnings.catch_warnings():
    warnings.filterwarnings(
        "ignore", r"pkg_resources is deprecated.*", category=UserWarning, module=r"perth\.perth_net"
    )
    from chatterbox.tts import ChatterboxTTS  # moved inside
    device = "mps" if torch.backends.mps.is_available() else "cpu"
    tts = ChatterboxTTS.from_pretrained(device=device)
    wav = tts.generate("Hello world. Chatterbox on Apple Silicon!")

ta.save("out.wav", wav, tts.sr)
print("Torch", torch.__version__, "MPS:", torch.backends.mps.is_available())
print("Wrote out.wav")
subprocess.run(["/usr/bin/afplay", "out.wav"], check=True)
PY

pardeike avatar Oct 24 '25 19:10 pardeike

Thank you, @pardeike. Your solution helped me a lot because I was stuck with several python issues while trying to run this on my MacBook.

andreiRS avatar Oct 25 '25 22:10 andreiRS

Thanks @pardeike, this is helpful.

AndrewJaquez avatar Oct 29 '25 02:10 AndrewJaquez