kokorosay
kokorosay is a fast, lightweight command-line text-to-speech (TTS) tool built on top of Kokoro.
Pass text as an argument or pipe it via standard input; kokorosay will immediately stream speech through your speakers or export it to high-quality WAV or MP3 audio files.
Features
- ⚡ Fast & Lightweight: Built on the open-weights 82M parameter Kokoro model (
hexgrad/Kokoro-82M). - 🔊 Direct Low-Latency Playback: Streams audio chunks to your default audio device in real time as they are generated.
- 💾 WAV & MP3 Export: Concatenates synthesized chunks into a seamless 24 kHz audio file; parent directories are created automatically.
- 🌐 9 Languages & 50+ Voices: Supports English, Japanese, Mandarin Chinese, Spanish, French, Hindi, Italian, and Brazilian Portuguese.
- 🔀 Automatic Language Detection: The target language is derived directly from the voice name prefix (e.g.
jf_nezumi→ Japanese,zf_xiaobei→ Mandarin,af_heart→ American English). - 📥 Pipeline & Stdin Friendly: Supports
-as input with explicit UTF-8 and BOM decoding, ideal for shell pipes and automation scripts. - 🎛️ Synthesis Controls: Easily adjust speech rate multiplier (
--speed) or provide custom segment-splitting regexes (--split-pattern). - 🛡️ Clean CLI & Standard Exit Codes: Suppresses third-party noise, outputs errors to
stderr, and adheres to standard exit codes (0,1,2,130).
Installation
kokorosay requires Python 3.14+.
Recommended: Using uv
Install kokorosay as a globally isolated command-line tool:
uv tool install kokorosay
Alternative: Using pipx or pip
# Using pipx
pipx install kokorosay
# Using standard pip (inside an active virtual environment)
pip install kokorosay
System Prerequisites (Linux only)
On Windows and macOS, audio dependencies are bundled automatically. On Linux systems, portaudio might be needed for direct speaker playback:
# Debian / Ubuntu
sudo apt-get install libportaudio2
Setup
Before first use, run the one-time dictionary setup:
kokorosay --setup
- Japanese UniDic:
kokorosay --setupdownloads the full UniDic dictionary required for Japanese G2P (grapheme-to-phoneme) processing. - Model weights: The Kokoro-82M model and voice weights (~330 MB) are automatically fetched from Hugging Face on your first speech synthesis and cached locally for future offline use.
Quick Start & Examples
1. Direct Playback
Provide text in quotes to play speech instantly through the default audio device:
# Play using default voice (af_heart - American English female)
kokorosay "Hello! Kokorosay brings text to life right from your terminal."
# British English voice, slightly faster
kokorosay "Mind the gap between the train and the platform." --voice bm_george --speed 1.15
2. Exporting to Audio Files (.wav / .mp3)
Specify an output file path as the second positional argument. Only .mp3 and .wav formats are supported (case-insensitive). Missing directories will be created automatically:
# Save as MP3
kokorosay "Speech saved to an MP3 file." output.mp3
# Japanese voice saved to a nested directory
kokorosay "こんにちは、世界。" audio/japanese/hello.wav --voice jf_nezumi
# Mandarin Chinese voice
kokorosay "你好,欢迎使用文本转语音工具。" out/welcome.mp3 --voice zf_xiaobei
3. Piping from Stdin (-)
Pass - as INPUT to read text from standard input. kokorosay decodes standard input as UTF-8 (and strips PowerShell's UTF-8 BOM if present):
# Pipe the output of any command
fortune | kokorosay -
# Read from a file via stdin
cat story.txt | kokorosay - story.mp3 --voice bf_emma
# In PowerShell:
Get-Content notes.txt -Raw | kokorosay - notes.wav
4. Text Starting with Hyphens (--)
If your input text begins with a dash or minus sign, use -- so the argument parser does not interpret it as a flag:
kokorosay -- "-5 degrees Celsius outside today."
CLI Reference
Synopsis
kokorosay INPUT [OUTPUT] [OPTIONS]
kokorosay --list-voices
kokorosay --setup
Arguments and Options
| Argument / Option | Default | Description |
|---|---|---|
INPUT |
– | Text to synthesize. Use - to read UTF-8 text from stdin. |
OUTPUT |
– | Output audio path (.wav or .mp3). If omitted, audio plays directly. |
--voice NAME |
af_heart |
Voice identifier (e.g. jf_nezumi, bf_emma). First letter sets language. |
--speed FLOAT |
1.0 |
Speech rate multiplier (must be a positive number). |
--split-pattern REGEX |
Kokoro default | Regular expression to split input text into segments. |
--list-voices |
– | Print all supported voices grouped by language and exit. |
--setup |
– | Download the UniDic dictionary for Japanese support and exit. |
--version |
– | Show version number and exit. |
-h, --help |
– | Show command help and exit. |
Note:
--setupand--list-voicesare standalone modes. They cannot be combined with positional arguments (INPUT/OUTPUT) or with each other.
Supported Languages & Voices
Kokoro determines the language from the first letter of the voice name. The second letter indicates voice gender (f for female, m for male).
| Prefix | Language | Example Voices |
|---|---|---|
a |
American English | af_heart (default), af_alloy, af_bella, am_adam, am_michael |
b |
British English | bf_alice, bf_emma, bm_daniel, bm_george |
e |
Spanish | ef_dora, em_alex, em_santa |
f |
French | ff_siwis |
h |
Hindi | hf_alpha, hf_beta, hm_omega, hm_psi |
i |
Italian | if_sara, im_nicola |
j |
Japanese | jf_alpha, jf_gongitsune, jf_nezumi, jf_tebukuro, jm_kumo |
p |
Brazilian Portuguese | pf_dora, pm_alex, pm_santa |
z |
Mandarin Chinese | zf_xiaobei, zf_xiaoni, zf_xiaoxiao, zm_yunjian, zm_yunyang |
To view the complete list of available voices grouped by language, run:
kokorosay --list-voices
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success: Audio played or written successfully, or --help / --list-voices completed. |
1 |
Runtime Failure: Network error downloading weights, synthesis failure, missing audio device, or invalid UTF-8 bytes on stdin. |
2 |
Usage Error: Missing INPUT, invalid argument, unknown voice name, unsupported output extension, or empty text. |
130 |
Interrupted: Execution aborted by SIGINT (Ctrl+C). |
Development
If you wish to contribute or modify kokorosay:
# Clone repository
git clone https://github.com/ecator/kokorosay.git
cd kokorosay
# Install runtime and dev dependencies
uv sync
# Lint and check formatting
uv run ruff check .
uv run ruff format --check .
# Run unit tests (offline, mocked Kokoro/sounddevice)
uv run pytest
# Run integration tests (requires real model weights & audio device)
uv run pytest -m integration
See AGENTS.md for full architecture specifications and coding conventions.
Acknowledgments
Metadata
Release files for kokorosay 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| kokorosay-0.1.0.tar.gz | 126.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kokorosay-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 138.7 kB
Release files / kokorosay-0.1.0.tar.gz
| Download URL | kokorosay-0.1.0.tar.gz |
|---|---|
| Size | 126.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b546665de8bb384b7e5f0e1c125b93299e68d54f527ac3325159e329bbf8c6f
|
|
BLAKE2b-256 checksum How to use checksums |
37c13179269e89c2357727c0d931de1c5b6d6776a00f4176d6b5b2ce7df700f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / kokorosay-0.1.0-py3-none-any.whl
| Download URL | kokorosay-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1cb007041b1bab24cb2a7c621ca509880f14bfa1b2ea1321253e3874e410a189
|
|
BLAKE2b-256 checksum How to use checksums |
2d9e52d2a496ef9e95b19f418123f8a37c1bc8a88a72ba901ab26d5191e564e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for kokorosay 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.