tts-in-1-line
v1.0.0
Published
The fastest way to convert text to speech in JavaScript. 1 line = instant audio. No setup, no API key.
Maintainers
Readme
tts-in-1-line
The Easiest Text-to-Speech Library for JavaScript (1 Line)
🔥 No API key. No config. No setup. Just one line of JavaScript — instant audio.
⚡ Install & speak in 10 seconds
npm install tts-in-1-lineimport { speak } from 'tts-in-1-line'
await speak('Hello world')That's it. Your speakers will play the audio immediately.
🎧 Features
- ✅ Zero setup — no API key, no account, works out of the box
- ✅ Cross-platform — macOS, Windows, Linux
- ✅ ESM + CommonJS — works with
importandrequire - ✅ Save to file — export as
.mp3for any use case - ✅ Multiple voices — female, male, US, UK, Australian accents
- ✅ Long text — auto-chunks long text for smooth playback
- ✅ Node.js 18+ — no native addons, no binary installs
🧠 API
speak(text, options?)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| voice | string | 'female' | Voice preset (see below) |
| save | string \| null | null | File path to save MP3. If set, skips playback. |
Returns: Promise<string> — path to the audio file
Voice presets
| Preset | Accent |
|--------|--------|
| 'female' | British English female (default) |
| 'male' | British English male |
| 'female-us' | US English female |
| 'male-us' | US English male |
| 'female-uk' | UK English female |
| 'female-au' | Australian English female |
| 'male-au' | Australian English male |
You can also pass any StreamElements voice name directly (e.g. 'Joanna', 'Matthew', 'Brian').
📖 Examples
Play immediately
import { speak } from 'tts-in-1-line'
await speak('Hello world')Choose a voice
await speak('Hello from the US!', { voice: 'female-us' })
await speak('G\'day mate!', { voice: 'female-au' })
await speak('Good morning.', { voice: 'male' })Save to MP3
const filePath = await speak('This will be saved, not played.', {
save: './output.mp3'
})
console.log('Saved to:', filePath)CommonJS (require)
const { speak } = require('tts-in-1-line')
await speak('Works with require too!')Long text (auto-chunked)
await speak(`
Text to speech has never been this simple in JavaScript.
No configuration files. No API keys to manage.
Just install the package and speak.
`)🖥️ Platform requirements
| Platform | Requirement |
|----------|------------|
| macOS | Nothing — afplay is built-in |
| Windows | Nothing — Windows Media Player COM is built-in |
| Linux | mpg123 (auto-detected), or mplayer, ffmpeg, or vlc |
Install on Linux if needed:
sudo apt install mpg123 # Ubuntu/Debian
sudo dnf install mpg123 # Fedora
sudo pacman -S mpg123 # Arch🧩 Why tts-in-1-line?
Every other TTS library for JavaScript requires you to:
- Sign up for an API key
- Read through pages of documentation
- Configure auth credentials
- Handle audio playback yourself
tts-in-1-line does all of that for you. Install it, call speak(), done.
🚀 Want higher quality voices?
This package uses free voices by default. For ultra-realistic, studio-quality speech synthesis — including voice cloning, emotions, and custom voices — check out Vocallab.ai.
📦 Related keywords
text to speech npm · javascript text to speech · tts nodejs simple · node tts · speak npm · audio synthesis javascript · nodejs speak text · tts without api key
License
MIT
