Text-to-speech and speech-to-text for server and browser, with React hooks and audio components.
Documents Β· Changelog Β· Report Bug Β· Request Feature
Table of contents
Lobe TTS (@lobehub/tts) lets you add natural-sounding speech output and voice input to your app, on the server or in the browser, in a few lines of TypeScript. It powers the voice features of π€― LobeHub.
- Speak and listen β turn text into speech and speech into text with one library
- Pick your voice provider β Microsoft Edge, Microsoft Speech, OpenAI or the browser's built-in speech, behind the same simple API
- Server or browser β generate audio files in Node.js / Bun, or speak directly in the user's browser
- React-ready β drop-in hooks and an audio player with progress, pause and download, so you don't build playback yourself
- Smooth long-form playback β long text starts playing quickly instead of waiting for the whole audio
- AI-native β
skills.mdandllms.txtlet your coding agent use the real API instead of guessing
Important
This package is ESM only.
$ pnpm i @lobehub/ttsThe React entry @lobehub/tts/react also needs the peer dependencies @lobehub/ui@^6, react@^19 and react-dom@^19.
// index.js β run with `bun index.js`
import { EdgeSpeechTTS } from '@lobehub/tts';
import fs from 'node:fs';
const tts = new EdgeSpeechTTS({ locale: 'en-US' });
const response = await tts.create({
input: 'This is a speech demonstration',
options: { voice: 'en-US-GuyNeural' },
});
fs.writeFileSync('./speech.mp3', Buffer.from(await response.arrayBuffer()));Note
Edge Speech needs a global WebSocket. It is built into Bun and Node.js 22+; on older Node.js versions, set global.WebSocket from the ws package.
import { AudioPlayer, useEdgeSpeech } from '@lobehub/tts/react';
import { Button, Flexbox } from '@lobehub/ui';
export default () => {
const { isGlobalLoading, start, stop, audio } = useEdgeSpeech('Hello from Lobe TTS', {
options: { voice: 'en-US-GuyNeural' },
});
return (
<Flexbox gap={8}>
<Button loading={isGlobalLoading} onClick={isGlobalLoading ? stop : start}>
Speak
</Button>
<AudioPlayer audio={audio} isLoading={isGlobalLoading} onLoadingStop={stop} />
</Flexbox>
);
};Using Next.js? Add transpilePackages: ['@lobehub/tts'] to next.config.js. For other providers, speech-to-text and more examples, see the documentation.
Lobe TTS publishes agent-friendly docs, so your AI assistant can write code against the documented API.
| Resource | What it does |
|---|---|
| Agent Skills | tts.lobehub.com/skills.md β skill entry point with setup, workflow and an index of the docs |
| llms.txt | tts.lobehub.com/llms.txt β an llms.txt index of every docs page |
Paste this into Cursor, Claude Code, Codex or any agent that can fetch URLs:
Read https://tts.lobehub.com/skills.md, then use @lobehub/tts to add a "read aloud" button to my React app.
Works with Cursor, Claude Code, Windsurf, GitHub Copilot and other tools that read skills.md or llms.txt.
| Entry | Use it for |
|---|---|
@lobehub/tts |
Generate speech or transcribe audio, on the server or browser |
@lobehub/tts/server |
Proxy OpenAI speech and transcription from your own API route |
@lobehub/tts/react |
React hooks and audio player components |
Visit tts.lobehub.com for guides, API reference and live demos. See the Changelog for release notes.
You can use Github Codespaces for online development:
Or clone it for local development:
$ git clone https://github.com/lobehub/lobe-tts.git
$ cd lobe-tts
$ bun install
$ bun run docs:devContributions of all types are more than welcome, if you are interested in contributing code, feel free to check out our GitHub Issues to get stuck in to show us what youβre made of.
Every bit counts and your one-time donation sparkles in our galaxy of support! You're a shooting star, making a swift and bright impact on our journey. Thank you for believing in us β your generosity guides us toward our mission, one brilliant flash at a time.
- π Lobe UI - React component library for AI apps
- π₯¨ Lobe Icons - AI / LLM brand logos and icons
- π Lobe Charts - React chart components
- βοΈ Lobe Editor - Lexical-based rich text editor for React, with Markdown, plugins and a chat composer
- π€ Lobe TTS - TTS / STT speech library
- π Lobe Lint - ESLint, Prettier, Stylelint, Commitlint and more lint configs
- π Fluent Emoji - Fluent Emoji assets
- π Docs Kit - Reusable documentation toolkit and lobedocs CLI for LobeHub component libraries
- π Streamdown - Headless streaming markdown engine for React
