Kokoro-TTS Voice
Resources
Kokoro-TTS Voice
To install
create python virtual environment
python3.11 -m venv kokoro-env
source kokoro-env/bin/activateinstall pytorch and Apple silicon mps support
pip install torch torchvision torchaudioverify
python -c "import torch; print(torch.backends.mps.is_available())"install Hugging Face and audio dependencies
pip install transformers accelerate soundfile scipy librosamay also need
brew install ffmpegDownload 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_hublogin
huggingface-cli logindownload
huggingface-cli download hexgrad/Kokoro-82MMinimal 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