Skip to content
AnswerWell geo Documentation

Research · 6 min read · Answerwell

Extension Text-to-Speech API: speak, Voices, Engine, and SSML

How extension tts and ttsEngine APIs speak text, queue utterances, choose voices, handle events, and register custom speech engines.

This page summarizes Chrome extension platform documentation on text-to-speech (TTS) for extensions. Consumer extensions call browser.tts (also exposed as chrome.tts in Manifest V2 reference material); separate extensions can register replacement speech engines with browser.ttsEngine / chrome.ttsEngine. The pair covers everything from “read this string aloud” to shipping a cloud or on-device synthesizer inside an extension.

browser.tts and chrome.tts: what the client API is for

Section titled “browser.tts and chrome.tts: what the client API is for”

The client API plays synthesized speech from an extension context—typically a service worker or background page after you declare the tts permission.

Use the chrome.tts API to play synthesized text-to-speech (TTS). See also the related ttsEngine API, which allows an extension to implement a speech engine.

— Chrome, browser.tts

On Windows (SAPI 5), macOS, and ChromeOS, Chrome uses OS speech synthesis. On every platform, users can install extensions that register as alternative engines via browser.ttsEngine.

Role Permission Primary methods
Speak text from your extension tts speak(), stop(), pause(), resume(), getVoices()
Provide voices other extensions use ttsEngine onSpeak, onStop, updateVoices(), optional onSpeakWithAudioStream

Language tags passed to speak() follow the same style as other extension i18n APIs: ISO-style codes such as en or en-US (see browser.i18n for language code conventions).

tts.speak(): how to make an extension read text aloud

Section titled “tts.speak(): how to make an extension read text aloud”

speak() takes an utterance string (plain text or SSML), optional TtsOptions, and optionally a callback. The utterance limit is 32,768 characters.

browser.tts.speak('Hello, world.');
browser.tts.speak('Hello, world.', { lang: 'en-US', rate: 2.0 });

By default, each speak() interrupts ongoing speech and clears the queue. To append instead, set enqueue: true on the second call:

browser.tts.speak('Speak this first.');
browser.tts.speak(
'Speak this next, when the first sentence is done.',
{ enqueue: true }
);

stop() ends current speech and drops pending queue items; it also clears a paused state before the next speak(). pause() may halt mid-utterance; resume() continues, and either resume() or stop() ends the paused state.

Use lang (en, en-US, en-GB, zh-CN, and similar) so Chrome picks a synthesizer that supports the language and region. Optional voiceName and extensionId pin a specific engine when several extensions expose the same name.

Option Range / behavior
rate Default 1.0 (~180–220 WPM); 2.0 is twice as fast. API disallows below 0.1 or above 10.0; voices may clamp further.
pitch 0–2, default 1.0
volume 0–1, default 1.0
gender Deprecated; ignored

Engines receiving SpeakOptions through ttsEngine must accept rate between 0.1 and 10.0 without error—clip to the voice’s real range instead of failing.

tts events: queueing, progress, and errors

Section titled “tts events: queueing, progress, and errors”

Syntax problems surface quickly via an optional speak() callback: it runs before synthesis starts; check browser.runtime.lastError (or chrome.runtime.lastError). Runtime synthesis failures need onEvent in options:

browser.tts.speak(
utterance,
{
onEvent(event) {
if (event.type === 'error') {
console.log(event.errorMessage);
}
}
},
() => {
if (browser.runtime.lastError) {
console.log(browser.runtime.lastError.message);
}
}
);

Event types include start, word, sentence, marker, end, interrupted, cancelled, error, plus pause and resume when supported. end, interrupted, cancelled, and error are final—no further events for that utterance.

Some voices omit events entirely. Filter with requiredEventTypes or pick a voice from getVoices() whose eventTypes meet your needs. Use desiredEventTypes to limit which events you receive.

SSML in tts.speak(): markup rules and engine limits

Section titled “SSML in tts.speak(): markup rules and engine limits”

Utterances may use Speech Synthesis Markup Language (SSML). The first argument must be a complete SSML document with an XML declaration and a top-level speak element—not a fragment.

Engines may ignore unsupported tags but must still speak the underlying text. Not every engine supports every SSML feature.

getVoices() and onVoicesChanged: list available synthesizers

Section titled “getVoices() and onVoicesChanged: list available synthesizers”

getVoices() returns TtsVoice objects with voiceName, lang, extensionId, eventTypes, and optional remote (network engine—higher latency and possible bandwidth cost). Subscribe to browser.tts.onVoicesChanged when engines install voices or call ttsEngine.updateVoices().

Default voice selection is automatic from lang unless you set voiceName / extensionId.

ttsEngine: how to build a custom speech engine extension

Section titled “ttsEngine: how to build a custom speech engine extension”

An engine extension intercepts matching tts.speak() / tts.stop() calls when manifest voices and registered listeners align.

Use the chrome.ttsEngine API to implement a text-to-speech(TTS) engine using an extension. If your extension registers using this API, it will receive events containing an utterance to be spoken and other parameters when any extension or Chrome App uses the tts API to generate speech.

— Chrome, browser.ttsEngine

Engines may stream from a server, play HTML5 audio, show captions, or log utterances—any web technology is allowed.

Declare permissions: ["ttsEngine"] and a tts_engine.voices array. voice_name is required and should identify both voice and engine. lang is optional but recommended (one voice per language is normal; omit lang only for a deliberate “any language” voice). List event_types when the engine can report progress—at minimum end is strongly recommended for queueing.

Manifest keys use snake_case (voice_name); updateVoices() uses camelCase (voiceName) and replaces manifest-declared voices.

You must register both onSpeak and onStop. Without both, the extension will not intercept speech regardless of manifest voices.

Caution: If your extension does not register listeners for both onSpeak and onStop, it will not intercept any speech calls, regardless of what is in the manifest.

— Chrome, browser.ttsEngine

Routing is deterministic: Chrome sends a request when manifest voice parameters match speak() options and listeners exist—engines cannot dynamically decline a matched request.

Engines send start, word, sentence, marker, end, and error via sendTtsEvent. Chrome synthesizes interrupted and cancelled for clients; engines do not emit those.

onSpeakWithAudioStream and language lifecycle

Section titled “onSpeakWithAudioStream and language lifecycle”

From Chrome 92+, onSpeakWithAudioStream lets the engine push linear PCM (Float32Array-style) mono buffers at audioStreamOptions.sampleRate while Chrome plays audio and dispatches client events.

From Chrome 131–132+, engines may handle onInstallLanguageRequest, onLanguageStatusRequest, and onUninstallLanguageRequest, reporting status through updateLanguage() and refreshing voices with updateVoices() after install or uninstall.

Optional onPause / onResume pair with client tts.pause() / tts.resume(); onStop must clear paused state even if speech already stopped (no error in that case).

  • Calling speak() without lang when multiple voices exist, then wondering why the wrong language plays.
  • Expecting the speak() callback to mean “playback finished”—only onEvent with type: 'end' marks completion.
  • Using enqueue: true with an engine that never fires end.
  • Publishing a ttsEngine manifest but forgetting onStop (silently breaks interception).
  • Passing SSML fragments instead of a full document with XML header and speak root.
  • Relying on deprecated gender in client or engine options.

Input method APIs such as browser.input.ime (contextID, spellCheck, field type) are unrelated to TTS—they target custom IMEs in text fields, not speech output.

  1. Add "tts" to permissions in manifest.json for a client extension, or "ttsEngine" plus a tts_engine.voices block for an engine—see browser.tts and browser.ttsEngine.

  2. Load the unpacked extension in chrome://extensions, open the service worker DevTools console, and run chrome.tts.getVoices(console.log) to confirm voices and eventTypes.

  3. Run chrome.tts.speak('Test utterance', { lang: 'en-US', onEvent: console.log }) and confirm start and end (or error with errorMessage).

  4. For an engine build, verify both chrome.ttsEngine.onSpeak and onStop listeners are registered before testing; trigger speech from a second extension that targets your voice_name.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match your experience or the official APIs, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong or unclear.