@kirillasyamov/text-to-speech
v1.5.1
Published
Autonomous Edge TTS library with streaming synthesis and local playback
Readme
Install
npm installLibrary
Autonomous Edge TTS library - pooled ws connections, streaming audio, no server required.
npm install @kirillasyamov/text-to-speechimport { createWriteStream } from "node:fs";
import { pipeline } from "node:stream/promises";
import { Readable } from "node:stream";
import TextToSpeech from "@kirillasyamov/text-to-speech";
const tts = new TextToSpeech({
voice: "ru-RU-SvetlanaNeural",
speed: 1.2,
warm: true,
});
for await (const chunk of tts.stream("Hello world")) {
process.stdout.write(chunk);
}
// await pipeline(Readable.from(stream), createWriteStream('out.mp3'));
// const audio = await tts.speak("Save me to a buffer as MP3.");
// const small = await tts.speak("Smaller stream.", { format: "webm-24khz-16bit-mono-opus" });
await tts.play("Play me through ffplay.");
const voices = await tts.voices({ language: "ru-RU" });Default export and named export TextToSpeech are the same class. The package also exports play, listVoices, close, TtsError and PlayerError.
Audio is streamed in chunks as it is synthesized, so playback can start before the whole text is ready. The format option (constructor, setDefaults, or per call) accepts audio-24khz-48kbitrate-mono-mp3 (default), audio-24khz-96kbitrate-mono-mp3 or webm-24khz-16bit-mono-opus. The server, CLI and UI also accept the short aliases mp3, mp3-96 and opus (also webm).
Server
npm run ui
make uiOpenAI-compatible endpoint POST /v1/audio/speech takes input, voice, speed and response_format (mp3, mp3-96, opus/webm, or a raw engine id); response Content-Type follows the format (audio/mpeg / audio/webm). GET /v1/models and GET /v1/voices list models and voices.
CLI
node src/index.js "Hello world"
node src/index.js "Hello world" --format opus --out out.webm
make ARGS="Hello world"Web UI
http://localhost:5051
Publishing
Local publish (token is read from .env):
make publish
make publish-patch
make publish-minor
make publish-majorLimitations
- The Microsoft Edge TTS endpoint is unofficial and has no SLA, so heavy or sustained use can trigger throttling or 403 rejections that the library cannot recover from.
- The server enforces no rate limiting, concurrency cap, or API key, so anyone who reaches the port can send unlimited requests.
- The full request body is buffered in memory with no upper bound, and long text is synthesized sequentially in 4000-byte turns.
- Only three output formats are supported (
mp3,mp3-96,opus/webm); any otherresponse_formatreturns 400. No transcoding is performed. - /v1/voices returns only DEFAULT_LANGUAGE voices unless you pass ?language=all.
- The connection pool lives only in memory and is lost on restart, with warm connections expiring after about 120 seconds of inactivity.
- If synthesis fails mid-stream, the already-sent headers cannot be changed, so the client receives a silently truncated audio stream.
License
MIT
