Skip to main content

Logo
nkl-kokoro-tts-cli 🗣️🤖 Gap

License Contributors Stars Last Commit

 

👉 Table of Contents

📍 Overview

Minimal, pipeline-first CLI for Kokoro TTS (hexgrad/Kokoro-82M). Unix-philosophy: text in → wav/mp3 out, logs to stderr, stdout stays binary-clean.

✨ Features

  • Pipeline-firststdin/stdout everywhere. echo "hi" | kokoro-tts -o - | mpv --no-video - works, no temp file. Logs ([INFO]/[WARN]/[ERROR]) go to stderr only.
  • Always local model — default ~/.cache/huggingface/hub (or $HF_HUB_CACHE/$KOKORO_MODEL_DIR). First run auto-downloads hexgrad/Kokoro-82M (~340M) via huggingface_hub, then fully offline. kokoro-tts download --model-dir ./kokoro-model for a plain dir.
  • Unix verbosity — default WARN (only warnings/errors). -vINFO, -vvDEBUG, -qERROR only, --log-level overrides. Quiet by default for | mpv.
  • Perf — in-process pipeline + voice tensor cache (cold 5.3s → warm 0.42s 12.5×), lazy torch/kokoro import so --help is instant, CUDA ~10× for long texts.
  • Audiowav default (no deps) via soundfile 24kHz, mp3 via ffmpeg (-f mp3), mpv pipe friendly.
  • Voices & langsam_echo default, 50+ known (af_, bf_, ef_, jf_, zf_…), auto lang from voice prefix (a US, b GB, e es, f fr, h hi, i it, p pt-br, j ja, z zh), custom .pt voice.
  • Linux standardsuv + hatchling src/ layout, pyproject.toml, requires-python >=3.10, kokoro-tts entry point, 88 mocked tests, SIGPIPE safe.

📦 Installation

System deps (recommended):

# Debian/Ubuntu
sudo apt install espeak-ng ffmpeg mpv

# Arch
sudo pacman -S espeak-ng ffmpeg mpv

espeak-ng improves G2P fallback, ffmpeg needed for mp3, mpv for pipe playback.

User install:

# uv tool (isolated, recommended)
uv tool install nkl-kokoro-tts-cli
kokoro-tts --help

# pip
pip install nkl-kokoro-tts-cli

# first run auto-downloads model to ~/.cache/huggingface/hub (~340M)
kokoro-tts "Hello world" -o hello.wav

Pre-download (optional, for offline):

kokoro-tts download                          # → ~/.cache/huggingface/hub
kokoro-tts download --model-dir ./kokoro-model  # → plain ./kokoro-model
KOKORO_MODEL_DIR=./kokoro-model kokoro-tts "Hi" -o out.wav

🔧 Development

git clone https://github.com/nkl/kokoro-tts-cli
cd kokoro-tts-cli

# env + deps (includes en_core_web_sm 3.8.0 via direct ref)
uv sync --extra dev
uv run kokoro-tts --help

# tests (70+ mocked, no GPU/HF needed)
uv run pytest -q          # 88 passed
uv run pytest -v
uv run pytest -k test_model_local

# lint / build / publish
uv run ruff check src tests
uv build
uv run twine check dist/*
uv tool install --force dist/nkl_kokoro_tts_cli-*.whl

Project layout: src/nkl_kokoro_tts_cli/{cli,tts,logger}.py (cli = pipe/arg parsing, tts = Kokoro wrapper + pipeline/voice cache, logger = leveled stderr), tests/{test_cli,test_tts,test_logger,test_model_local}.

🚀 Usage

kokoro-tts --help
kokoro-tts --list-voices
kokoro-tts --version

Basic

kokoro-tts "Hello world, this is Kokoro." -o hello.wav
kokoro-tts "Hello" --voice am_echo --speed 1.0 -o hello.wav
kokoro-tts "Hello" --voice af_bella --lang a -o out.wav  # lang auto from voice

Pipes (first-class)

echo "Hello from the pipeline" | kokoro-tts -o out.wav
cat book.txt | kokoro-tts --format mp3 -o book.mp3
kokoro-tts --input-file chapter.txt -o chapter.wav --speed 0.95
from_clipboard | kokoro-tts -o - | mpv --no-video -  # from_clipboard = xsel -ob

kokoro-tts writes wav to stdout when -o - or when stdout is piped and no -o given.

mpv pipeline

# wav (no ffmpeg)
echo "Hello, this is a test" | kokoro-tts --voice am_echo -o - | mpv --no-video -

# mp3 (needs ffmpeg)
echo "Hello" | kokoro-tts -o - --format mp3 | mpv -

# with speed / volume, silent logs
cat transcript.txt | kokoro-tts --voice af_bella --speed 0.95 -o - --log-level ERROR | mpv --no-video --volume=80 --really-quiet -

Tip: mpv --no-video - reads stdin. Our logs stay on stderr.

No -o defaults

  • stdout is a pipe → wav to stdout (| mpv - works without -o -)
  • stdout is a TTY → ./output.wav + [WARN]

Formats

kokoro-tts "Hello" -o out.wav               # wav (default)
kokoro-tts "Hello" -o out.mp3 --format mp3  # mp3 (ffmpeg)
echo "hi" | kokoro-tts -o - --format mp3 | mpv -

Voices & languages

kokoro-tts --list-voices                    # 50+ af_/am_/bf_/bm_/ef_/jf_/zf_...
kokoro-tts "Bonjour le monde" --voice ff_siwis -o fr.wav
kokoro-tts "Hola mundo" --voice ef_dora --lang e -o es.wav
kokoro-tts "Hello" --voice /path/to/custom.pt -o out.wav
kokoro-tts "Hi" --voice af_bella,af_nicole -o averaged.wav  # averaged

--lang auto-inferred from voice prefix; default am_echoa (US).

Verbosity (Unix standard)

kokoro-tts "Hello" -o out.wav               # default WARN (only WARN/ERROR)
kokoro-tts "Hello" -o out.wav -v            # INFO + WARN + ERROR
kokoro-tts "Hello" -o out.wav -vv           # DEBUG (adds chunk/ps debug)
kokoro-tts "Hello" -o out.wav -q            # ERROR only
kokoro-tts "Hello" -o out.wav --log-level DEBUG

Long texts & splitting

Kokoro chunks at 510 phonemes. Override:

kokoro-tts --input-file long.txt --split-pattern '\n+' -o out.wav

Model & device

# model (always local)
kokoro-tts download --model-dir ./kokoro-model  # plain dir
KOKORO_MODEL_DIR=./kokoro-model kokoro-tts "Hi" -o out.wav
# default HF cache: ~/.cache/huggingface/hub/models--hexgrad--Kokoro-82M

# device (auto picks CUDA if available)
kokoro-tts "Hello" -o out.wav --device auto -v  # [INFO] pipeline ready device='cuda:0' (hf-cache)
kokoro-tts "Hello" -o out.wav --device cpu
kokoro-tts "Hello" -o out.wav --device cuda

Long 2600 chars: CPU 40s vs CUDA 4s.

🐛 Troubleshooting

  • ffmpeg not found for mp3sudo apt install ffmpeg
  • EspeakFallback not Enabledsudo apt install espeak-ng
  • Can't find model 'en_core_web_sm' → fixed in 0.1.5+ via direct en_core_web_sm 3.8.0 dep; uv tool update nkl-kokoro-tts-cli
  • unauthenticated requests to HF Hub → suppressed in 0.1.5; set export HF_TOKEN=hf_xxx to raise rate limits
  • CUDA requested but not available--device cpu

📤 Publish

uv build
uv run twine check dist/*
uv publish

Or with just:

just build   # uv build (runs tests first)
just publish # uv build + twine check + uv publish

pyproject.toml uses hatchling, allow-direct-references for en_core_web_sm, entry kokoro-tts = nkl_kokoro_tts_cli.cli:main.

🫂 Acknowledgments

 

Footer

⭐ Hit the Star Button if You Found This Useful ⭐

X (Twitter) Icon LinkedIn Icon GitHub Icon Go to Top Icon

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nkl_kokoro_tts_cli-0.1.9.tar.gz (198.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nkl_kokoro_tts_cli-0.1.9-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file nkl_kokoro_tts_cli-0.1.9.tar.gz.

File metadata

  • Download URL: nkl_kokoro_tts_cli-0.1.9.tar.gz
  • Upload date:
  • Size: 198.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nkl_kokoro_tts_cli-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c4bd227ec317b7fb57c0a97bf77cfe3dda18718b3fab3d84fd5e2b1631a46b58
MD5 0e262bb74d7eddbf0c375cc54f6f9597
BLAKE2b-256 b53660e4e7b6c181c5037b2584aef6525de101d60dee7e1ec57badc32416dac7

See more details on using hashes here.

File details

Details for the file nkl_kokoro_tts_cli-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: nkl_kokoro_tts_cli-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nkl_kokoro_tts_cli-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7523f47360db835527036ef0021badc78ba095e9d24fa293ad7db216eeadbe8d
MD5 ba51e5d512326893abfbfb1e8dd6017c
BLAKE2b-256 497697c271ecd054f17190e0ea98daf95480d5246add2c07ee88aacc9b3d8550

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 files

0.1.8

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page