Kokoro-TTS Voice

Resources

Kokoro-TTS Voice

To install

create python virtual environment

python3.11 -m venv kokoro-env
source kokoro-env/bin/activate

install pytorch and Apple silicon mps support

pip install torch torchvision torchaudio

verify

python -c "import torch; print(torch.backends.mps.is_available())"

install Hugging Face and audio dependencies

pip install transformers accelerate soundfile scipy librosa

may also need

brew install ffmpeg

Download Kokoro-82M

A) Let Transformers auto-download

from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("hexgrad/Kokoro-82M")

B) Manually download via CLI

install Hugging Face cli

pip install huggingface_hub

login

huggingface-cli login

download

huggingface-cli download hexgrad/Kokoro-82M

Minimal TTS Code

import torch
from transformers import AutoProcessor, AutoModel
import soundfile as sf

device = "mps" if torch.backends.mps.is_available() else "cpu"

processor = AutoProcessor.from_pretrained("hexgrad/Kokoro-82M")
model = AutoModel.from_pretrained("hexgrad/Kokoro-82M").to(device)

text = "The quick brown fox jumped confidently over the lazy log."

inputs = processor(text=text, return_tensors="pt").to(device)

with torch.no_grad():
    audio = model.generate(**inputs)

sf.write("output.wav", audio.cpu().numpy(), 22050)

run

python test_kokoro.py