JavaScript text-to-speech libraries

Updated Nov 2026

JavaScript text-to-speech libraries turn written text into spoken audio from Node.js or the browser. Most send the text or SSML markup to a cloud speech service that returns audio in a chosen voice. These libraries let voice agents, accessibility features, and audiobook tools speak text aloud.

Popularity

ElevenLabs has the most monthly downloads among the speech-focused SDKs in this comparison, at 5.5M.

LibraryMonthly downloadsStarsLast releaseLicense
openai
223.6M
11.3KNov 2026Apache-2.0
@elevenlabs/elevenlabs-js
5.7M
454Nov 2026MIT
@deepgram/sdk
5.3M
286Nov 2026MIT
@aws-sdk/client-polly
3.7M
3.7KNov 2026Apache-2.0
microsoft-cognitiveservices-speech-sdk
2.7M
327Oct 2026MIT
@google-cloud/text-to-speech
1.7M
3.2KOct 2026Apache-2.0
kokoro-js
905.9K
10.2KMay 2025Apache-2.0
@cartesia/cartesia-js
534.3K
134Nov 2026Apache-2.0
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides the official TypeScript client for the OpenAI API.

Downloads / mo
223.6M
Stars
11.3K
Last release
7.60.0
License
Apache-2.0

Quickstart

From speech.d.ts
$ npm install openai
import OpenAI from 'openai';

const client = new OpenAI();
const audio = await client.audio.speech.create({
  model: 'gpt-4o-mini-tts', voice: 'alloy', input: 'Hello, world!'
});
const bytes = await audio.arrayBuffer();

openai examples

From open-source projects on GitHub

@elevenlabs/elevenlabs-js

Generates speech through ElevenLabs with streamed audio, voice selection, and surrounding-text context.

Downloads / mo
5.7M
Stars
454
Last release
2.79.0
License
MIT

Strengths

  • Streams generated audio. Consume response audio while it arrives.
  • Connects neighboring speech clips. Supply preceding text to improve continuity between generated clips.

Limitations

  • Some formats need upgraded plans. Higher-bitrate MP3 and some WAV outputs require eligible subscription tiers.
  • Playback needs local media tools. Install MPV and ffmpeg when using the SDK’s play helper.

Quickstart

From README.md
$ npm install @elevenlabs/elevenlabs-js
import { ElevenLabsClient } from '@elevenlabs/elevenlabs-js';

const client = new ElevenLabsClient();
const audio = await client.textToSpeech.convert('JBFqnCBsd6RMkjVDRZzb', {
  text: 'Hello, world!'
});

@elevenlabs/elevenlabs-js examples

From open-source projects on GitHub

@deepgram/sdk

Provides the official SDK for the Deepgram speech recognition, text-to-speech, and language understanding APIs.

Downloads / mo
5.3M
Stars
286
Last release
5.20.0
License
MIT

Quickstart

From README.md
$ npm install @deepgram/sdk
import { DeepgramClient } from '@deepgram/sdk';

const client = new DeepgramClient();
const audio = await client.speak.v1.audio.generate({
  text: 'Hello, world!', model: 'aura-2-thalia-en'
});

@aws-sdk/client-polly

Sends plain text or SSML to Amazon Polly and receives encoded speech or speech metadata.

Downloads / mo
3.7M
Stars
3.7K
Last release
3.1172.0
License
Apache-2.0

Strengths

  • Accepts marked-up speech input. Send plain text or SSML to control synthesis.
  • Returns word timing metadata. Request speech marks to locate words and sentences in generated audio.

Limitations

  • Timing metadata replaces audio. Request synthesized audio separately when speech marks are also needed.
  • SSML support varies by voice. Check tag availability before switching synthesis voices.
$ npm install @aws-sdk/client-polly
import { PollyClient, SynthesizeSpeechCommand } from '@aws-sdk/client-polly';

const client = new PollyClient({ region: 'us-east-1' });
const result = await client.send(new SynthesizeSpeechCommand({
  Text: 'Hello, world!', VoiceId: 'Joanna', OutputFormat: 'mp3'
}));

@aws-sdk/client-polly examples

From open-source projects on GitHub

microsoft-cognitiveservices-speech-sdk

Provides the Microsoft Speech SDK for JavaScript.

Downloads / mo
2.7M
Stars
327
Last release
1.53.0
License
MIT

Quickstart

From SpeechSynthesizer.d.ts
$ npm install microsoft-cognitiveservices-speech-sdk
import * as speech from 'microsoft-cognitiveservices-speech-sdk';

const config = speech.SpeechConfig.fromSubscription(
  process.env.SPEECH_KEY, process.env.SPEECH_REGION
);
const synthesizer = new speech.SpeechSynthesizer(config, null);
try {
  const result = await new Promise((resolve, reject) => {
    synthesizer.speakTextAsync('Hello, world!', resolve, reject);
  });
  console.log(result.audioData.byteLength);
} finally {
  synthesizer.close();
}

microsoft-cognitiveservices-speech-sdk examples

From open-source projects on GitHub

@google-cloud/text-to-speech

Synthesizes speech through Google Cloud, with SSML controls and compatible bidirectional streaming voices.

Downloads / mo
1.7M
Stars
3.2K
Last release
7.2.0
License
Apache-2.0

Strengths

  • Controls pauses through SSML. Mark pauses and spoken formatting in the synthesis request.
  • Receives audio while sending text. Bidirectional streaming accepts more text before the full input is ready.

Limitations

  • Streaming needs compatible voices. Use Chirp 3: HD voices for bidirectional streaming.
  • Requests allow 5,000 input bytes. Split longer input; some characters require multiple bytes.

Quickstart

From quickstart.js
$ npm install @google-cloud/text-to-speech
const { TextToSpeechClient } = require('@google-cloud/text-to-speech');

(async () => {
  const client = new TextToSpeechClient();
  const [result] = await client.synthesizeSpeech({
    input: { text: 'Hello, world!' },
    voice: { languageCode: 'en-US', ssmlGender: 'NEUTRAL' },
    audioConfig: { audioEncoding: 'MP3' }
  });
})();

@google-cloud/text-to-speech examples

From open-source projects on GitHub

Runs speech synthesis locally through Transformers.js, with voice selection and sentence-level streaming.

Downloads / mo
905.9K
Stars
10.2K
Last release
1.2.1
License
Apache-2.0

Strengths

  • Runs locally in the browser. Synthesize speech locally after the required model assets load.
  • Accepts text incrementally. Push new text through TextSplitterStream as it becomes available.

Limitations

  • Long chunks are truncated. Split long input into smaller chunks before synthesis.
  • Needs model assets before synthesis. Load the selected model before generating speech.

Quickstart

From README.md
$ npm install kokoro-js
import { KokoroTTS } from 'kokoro-js';

const tts = await KokoroTTS.from_pretrained(
  'onnx-community/Kokoro-82M-v1.0-ONNX', { dtype: 'q8', device: 'wasm' }
);
const audio = await tts.generate('Hello, world!', { voice: 'af_heart' });

kokoro-js examples

From open-source projects on GitHub

@cartesia/cartesia-js

Provides the official TypeScript client for the Cartesia API.

Downloads / mo
534.3K
Stars
134
Last release
5.1.0
License
Apache-2.0

Quickstart

From README.md
$ npm install @cartesia/cartesia-js
import Cartesia from '@cartesia/cartesia-js';

const client = new Cartesia({ apiKey: process.env.CARTESIA_API_KEY });
const response = await client.tts.generate({
  model_id: 'sonic-latest',
  transcript: 'Hello, world!',
  voice: 'f786b574-daa5-4673-aa0c-cbe3e8534c02',
  output_format: { container: 'wav', encoding: 'pcm_f32le', sample_rate: 44100 }
});
const audio = await response.blob();

@cartesia/cartesia-js examples

From open-source projects on GitHub

FAQ

ElevenLabs suits apps that need streamed, expressive voices. Amazon Polly and Google Cloud Text-to-Speech suit apps that already run on those clouds and want SSML control. Kokoro suits apps that must synthesize speech locally.

Amazon Polly is the AWS text-to-speech service. Its JavaScript client sends plain text or SSML and receives encoded speech or speech metadata.

Kokoro is an open-weight text-to-speech model. kokoro-js runs it locally through Transformers.js with voice selection and sentence-level streaming.

Amazon Polly, Google Cloud Text-to-Speech, Deepgram, and Cartesia offer hosted speech APIs with JavaScript SDKs. Kokoro runs speech synthesis locally with no API account.

Azure text to speech runs through the Microsoft Speech SDK for JavaScript. The same SDK also covers speech recognition.

The OpenAI TypeScript library calls the OpenAI speech endpoint. The endpoint returns audio of the input text in a chosen voice.

For coding agents

Found your text-to-speech library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official