SpeakEasy 🎤
A unified speech library for all your projects with support for multiple TTS providers and clean configuration structure.
Features
- Multiple TTS Providers: System (macOS), OpenAI, ElevenLabs, Groq
- Smart Caching: Caches generated audio for faster subsequent requests
- Smart Fallbacks: Automatically falls back to available providers
- Queue Management: Handles multiple speech requests with priority
- Text Cleaning: Removes emojis and normalizes text for better speech
- TypeScript: Full type safety
- Clean Config: Nested provider configuration
Installation
npm install speakeasy
Quick Start
import { say } from 'speakeasy';
await say('Hello world!');
await say('Hello!', 'openai');
await say('Hello!', 'elevenlabs');
await say('Hello!', 'groq');
Configuration
SpeakEasy uses a clean nested configuration structure in ~/.config/speakeasy/settings.json
:
{
"providers": {
"openai": {
"enabled": true,
"voice": "nova",
"model": "tts-1",
"apiKey": "sk-..."
},
"elevenlabs": {
"enabled": true,
"voiceId": "EXAVITQu4vr4xnSDxMaL",
"apiKey": "sk-..."
},
"system": {
"enabled": true,
"voice": "Samantha"
},
"groq": {
"enabled": true,
"voice": "onyx",
"model": "tts-1-hd",
"apiKey": "gsk-..."
}
},
"defaults": {
"provider": "groq",
"fallbackOrder": ["groq", "openai", "elevenlabs", "system"],
"rate": 180
},
"global": {
"tempDir": "/tmp",
"cleanup": true
}
}
Environment Variables
export OPENAI_API_KEY=your_openai_key
export ELEVENLABS_API_KEY=your_elevenlabs_key
export GROQ_API_KEY=your_groq_key
Usage
Basic Usage
import { say, speak } from 'speakeasy';
await say('Hello world!');
await say('Hello!', 'openai');
await say('Hello!', 'elevenlabs');
await say('Hello!', 'groq');
await speak('Hello world!', { priority: 'high' });
await speak('Hello!', { provider: 'openai', priority: 'high' });
import { SpeakEasy } from 'speakeasy';
const speech = new SpeakEasy({
provider: 'openai',
openaiVoice: 'nova',
rate: 180,
});
await speech.speak('Hello world!');
In Your Projects
import { say } from 'speakeasy';
export async function speakNotification(message: string, project: string) {
await say(`In ${project}, ${message}`, { priority: 'high' });
}
Caching
- Enabled by default for OpenAI, ElevenLabs, and Groq providers
- Declarative TTL: Configure with simple strings like
"7d"
, "1h"
, "30m"
- Declarative max size: Configure with strings like
"100mb"
, "1gb"
- Storage location:
/tmp/speakeasy-cache/
by default
Convenience
say('text')
- One-liner with system voice and caching
say('text', 'openai' | 'elevenlabs' | 'groq')
- One-liner with provider and caching
say('text', provider, false)
- Disable caching for specific call
speak('text', options, false)
- Full featured with caching control
Examples
npm run example
Declarative Caching Configuration
import { SpeakEasy } from 'speakeasy';
const speaker = new SpeakEasy({
provider: 'openai',
cache: {
enabled: true,
ttl: '7d',
maxSize: '100mb',
dir: '/tmp/my-cache'
}
});
{
"cache": {
"enabled": true,
"ttl": "1d",
"maxSize": "500mb"
}
}
CLI Usage
Install globally for command-line access:
npm install -g speakeasy
speakeasy "Hello world"
speakeasy --text "Hello from CLI" --provider openai --voice nova
speakeasy --cache --text "Hello cached world"
speakeasy --cache --list
speakeasy --cache --find "hello"
speakeasy --cache --provider openai
speakeasy --clear-cache
speakeasy --config
speakeasy --help
Cache Inspection
Programmatic
const speaker = new SpeakEasy({ cache: { enabled: true } });
const metadata = await speaker.getCacheMetadata();
console.log(metadata);
const found = await speaker.findByText('hello world');
const openaiEntries = await speaker.findByProvider('openai');
CLI
speakeasy --cache --list
speakeasy --cache --find "hello"
speakeasy --cache --provider openai
speakeasy --cache --stats
Testing
npm run build
npm test
npm test cache
npm run cli -- --help