Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koko-tts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ค Koko TTS - Kokoro Text-to-Speech CLI
A simple, powerful command-line tool for text-to-speech generation using the Kokoro TTS engine. Convert text to natural-sounding speech with 28+ professional voices.
โจ Features
- ๐ฏ 28 Professional Voices with quality grades (American & British English)
- ๐ Interactive Mode - Just run
kokofor a clean, guided experience - ๐ File Input - Process text files via CLI or interactive mode
- ๐๏ธ Voice Control - Choose speed, temperature, and voice
- ๐ฆ Zero Config - Works out of the box
- ๐ Streaming - Real-time generation for long texts
- ๐พ Multiple Formats - WAV and PCM output
- ๐ Auto-Chunking - Bypass 25-second limit with automatic text splitting
- ๐งฉ Audio Stitching - Chunks automatically combined into single files
- ๐งน Auto-Cleanup - Temp files cleaned automatically
๐ Quick Start
Interactive Mode (Easiest)
# Using npx (no installation needed)
npx koko-tts@latest
# Or install globally first
npm install -g koko-tts
koko
# Clean, guided interface:
# ๐ค Koko TTS
# Simple text-to-speech generation
#
# What would you like to do?
# โฏ โจ Generate speech
# ๐ญ Browse voices
# ๐ช ExitCommand Line (For Scripts & Automation)
# Generate speech instantly
npx koko-tts@latest generate "Hello, this is Koko TTS!"
# With specific voice
npx koko-tts@latest generate "Welcome to Koko!" --voice af_heart
# From a text file
npx koko-tts@latest generate --file story.txt --voice bf_emmaUsing Nix (Recommended for Development)
# Clone and enter development environment
git clone https://github.com/piotutic/koko-tts
cd kokoro-tts-typescript
nix develop
# Build and use
npm run build
koko generate "Hello from Nix!"๐ Usage
Basic Commands
# Simple generation (uses default voice af_sarah)
koko generate "Your text here"
# Choose a specific voice
koko generate "Hello world" --voice af_heart
# Read from file
koko generate --file input.txt --output audiobook.wav
# Adjust speaking speed and expressiveness
koko generate "Custom speech" --speed 0.8 --temperature 0.9
# Quiet mode (minimal output)
koko generate "Silent generation" --quietList Available Voices
# Show all voices
koko voices
# Filter by category
koko voices --category recommended
koko voices --category american
koko voices --category british
# JSON output for scripting
koko voices --jsonInteractive Mode
# Launch interactive interface (default when no arguments)
koko
# Or explicitly
koko interactive
# Interactive features:
# - Choose between typing text or loading from file
# - Smart voice selection with defaults
# - File browser with validation
# - Custom filename or smart auto-naming
# - Clean, professional interface๐ญ Voice Options
Recommended Voices (Highest Quality)
| Voice ID | Description | Language | Gender |
|---|---|---|---|
af_heart |
Warm, expressive โญ | US English | Female |
af_bella |
Clear, professional โญ | US English | Female |
bf_emma |
Elegant, refined โญ | UK English | Female |
am_michael |
Smooth, versatile | US English | Male |
bm_george |
Distinguished, clear | UK English | Male |
โญ = Top quality voices
Voice Categories
- American Female:
af_heart,af_bella,af_sarah(default),af_nicole,af_kore - American Male:
am_michael,am_fenrir,am_puck,am_echo,am_eric - British Female:
bf_emma,bf_isabella,bf_alice,bf_lily - British Male:
bm_george,bm_fable,bm_lewis,bm_daniel
โ๏ธ Options
| Option | Description | Default | Range |
|---|---|---|---|
--voice |
Voice to use | af_sarah |
See voice list |
--speed |
Speaking speed | 1.0 |
0.5 - 2.0 |
--temperature |
Expressiveness | 0.7 |
0.1 - 1.0 |
--output |
Output filename | output.wav |
Any path |
--file |
Input text file | - | Any .txt file |
--quiet |
Minimal output | false |
Boolean |
--streaming |
Stream long texts | false |
Boolean |
๐ Examples
Basic Text Generation
# Simple generation
koko generate "Welcome to Koko TTS!"
# Professional presentation voice
koko generate "Good morning everyone" --voice af_bella --speed 0.9
# Storytelling with British accent
koko generate "Once upon a time..." --voice bf_emma --temperature 0.8File Processing
# Command line file processing
koko generate --file chapter1.txt --voice am_michael --output chapter1.wav
# Interactive file processing
koko
# Choose "โจ Generate speech"
# Choose "๐ Load from file"
# Enter file path with validation
# Batch process with streaming (for long files)
koko generate --file novel.txt --streaming --output audiobook.wavInteractive Mode Workflow
# Start interactive mode
koko
# 1. Main Menu
# What would you like to do?
# โฏ โจ Generate speech
# ๐ญ Browse voices
# ๐ช Exit
# 2. Input Method (when generating speech)
# How would you like to provide text?
# โฏ โจ๏ธ Type text manually
# ๐ Load from file
# 3. File Input (if file selected)
# Enter file path: story.txt
# โ
Loaded 1,240 characters from file
# Preview: "Once upon a time in a distant galaxy..."
# 4. Voice Selection
# Use default voice (Sarah)? (Y/n)
# Select voice: Heart (Female) / Michael (Male) / etc.
# 5. Filename Customization
# Output filename: (koko_20250917T143022.wav)
# Press Enter for default or type custom name: my-presentation
# โ Uses: my-presentation.wav
# 6. Generation
# Generating: my-presentation.wav
# โ
Success! Generated: my-presentation.wavVoice Comparison
# Test the same text with different voices
koko generate "Voice test" --voice af_heart --output heart.wav
koko generate "Voice test" --voice bf_emma --output emma.wav
koko generate "Voice test" --voice am_michael --output michael.wavFilename Examples
# Interactive mode filename options:
# Press Enter โ koko_20250917T143022.wav (auto-timestamp)
# Type "presentation" โ presentation.wav (auto .wav)
# Type "chapter1.wav" โ chapter1.wav (keeps extension)
# Type "audio-notes" โ audio-notes.wav (auto .wav)
# Command line (unchanged)
koko generate "text" --output my-custom-name.wav๐ง Advanced Usage
Configuration
# Initialize configuration file
koko config --init
# Use custom configuration
koko generate "Text" --config my-settings.yml
# Save current settings as preset
koko generate "Test" --voice af_heart --save-config my-preset.ymlAudio Stitching & Chunks
# Default: Chunks are automatically stitched into single file
koko generate --file long-text.txt
# โ Creates: combined-audio.wav
# Keep individual chunks AND combined file
koko generate --file long-text.txt --keep-chunks
# โ Creates: combined-audio.wav + individual chunk files
# Disable stitching (legacy behavior)
koko generate --file long-text.txt --no-stitch
# โ Creates: audio_001.wav, audio_002.wav, audio_003.wav...Cleanup
# Clean temp files older than 24 hours (default)
koko cleanup
# Custom cleanup age
koko cleanup --max-age 48
# Verbose cleanup output
koko cleanup --verbosePerformance & Quality
# High quality (slower)
koko generate "Text" --dtype fp32
# Balanced quality/speed (default)
koko generate "Text" --dtype q8
# Fast generation (lower quality)
koko generate "Text" --dtype q4๐ Performance Tips
- First Run: Downloads the model (~100MB), subsequent runs are much faster
- Voice Selection:
af_heartandaf_bellaprovide the best quality - Speed Settings: 0.8-0.9 for presentations, 1.0-1.2 for casual content
- Long Texts: Use
--streamingfor files over 500 characters - File Format: WAV provides best compatibility
๐ Organized Directory Structure
Koko TTS automatically organizes all files in a .koko-tts/ directory:
.koko-tts/
โโโ config/ # Configuration files
โโโ cache/ # Audio cache for faster re-generation
โโโ outputs/ # Generated audio files
โ โโโ YYYY-MM-DD/ # CLI outputs by date
โ โโโ interactive/ # Interactive mode outputs
โ โโโ YYYY-MM-DD/
โโโ temp/ # Temporary files (auto-cleaned)Benefits:
- Clean workspace (no scattered output files)
- Easy cleanup (delete entire
.koko-tts/folder) - Organized by date and generation mode
- Add to
.gitignore:echo ".koko-tts/" >> .gitignore
๐ Troubleshooting
Common Issues
Model Download Fails
# Check internet connection and retry
koko generate "test" --verboseAudio File Issues
# Verify output file was created
ls -la output.wav
# Test audio playback (Linux)
ffplay output.wav
# or
aplay output.wavPermission Denied
# Ensure CLI has execute permissions
npm run build # This sets permissions automatically๐ฆ Development
Project Structure
src/
โโโ cli.ts # Main CLI application
โโโ tts-engine.ts # TTS engine wrapper
โโโ voices.ts # Voice configurations
โโโ types.ts # TypeScript definitions
โโโ utils.ts # Utility functionsBuild Commands
# Build TypeScript
npm run build
# Type checking
npm run type-check
# Clean build files
npm run clean
# Development mode
npm run cli -- generate "dev test"Adding New Voices
Edit src/voices.ts to add new voice configurations with metadata.
๐ License
Apache License 2.0 - see LICENSE file for details.
๐ Acknowledgments
- Kokoro TTS - Original model by hexgrad
- kokoro-js - JavaScript implementation by Xenova
- Transformers.js - Machine learning in JavaScript
๐ Links
Simple, powerful text-to-speech: Just run koko for interactive mode or koko generate "your text" for command line ๐ค