A simple, focused command-line tool for converting text to speech using ElevenLabs.
- Pipe text from stdin or provide as argument
- Voice selection via flags
- Output to file or pipe to audio players
- TypeScript with full type safety
- Configurable voice settings (stability, similarity)
Automatically sets up the environment when you cd into the directory:
# First time setup
cd elevenlabs/cli
direnv allow
# Environment loads automatically!
# Copy the example env file and add your API key
cp .envrc.local.example .envrc.local
# Edit .envrc.local and add your ELEVENLABS_API_KEYOr without direnv:
# Enter development shell with all dependencies
nix develop
# Or run directly
nix run . -- "Hello world" -o test.mp3Requires Bun or Node.js to be installed manually.
bun install # or npm install
bun run build # or npm run build
bun link # or npm link - Makes 'tts' command available globally# Pipe text and play with mpv
echo "Hello world" | tts | mpv -
# Save to file
echo "Hello world" | tts -o hello.mp3
# Provide text as argument
tts "Hello world" -o hello.mp3
# Use different voice
echo "Hello world" | tts -v "21m00Tcm4TlvDq8ikWAM" | mpv --v, --voice <id> Voice ID (default: ErXwobaYiN019PkySvjV - Antoni)
-o, --output <file> Output file (default: stdout for piping)
-m, --model <id> Model ID (default: eleven_multilingual_v2)
-s, --stability <value> Voice stability 0-1 (default: 0.5)
-S, --similarity <value> Similarity boost 0-1 (default: 0.75)
ErXwobaYiN019PkySvjV- Antoni (default, male)21m00Tcm4TlvDq8ikWAM- Rachel (female)AZnzlk1XvdvUeBnXmlld- Domi (female)EXAVITQu4vr4xnSDxMaL- Bella (female)MF3mGyEYCl7XYWbV9V6O- Elli (female)TxGEqnHWrfWFTfGW9XjX- Josh (male)
Set your ElevenLabs API key:
export ELEVENLABS_API_KEY="your-api-key-here"# Read from file and convert
cat document.txt | tts -o document.mp3
# Generate and play immediately
tts "This is a test" | mpv -
# Use different voice settings
echo "Dramatic reading" | tts -s 0.8 -S 0.9 -o dramatic.mp3
# Pipe from other commands
fortune | tts | mpv -# Build
npm run build
# Watch mode
npm run dev
# Run directly
npm start -- "Hello world" -o test.mp3