A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.chrome.com/docs/extensions/reference/api/tts below:

chrome.tts | API | Chrome for Developers

Skip to main content chrome.tts

Stay organized with collections Save and categorize content based on your preferences.

Description

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 provides this capability on Windows (using SAPI 5), Mac OS X, and ChromeOS, using speech synthesis capabilities provided by the operating system. On all platforms, the user can install extensions that register themselves as alternative speech engines.

Permissions

tts

Concepts and usage Generate speech

Call speak() from your extension to speak. For example:

chrome.tts.speak('Hello, world.');

To stop speaking immediately, just call stop():

chrome.tts.stop();

You can provide options that control various properties of the speech, such as its rate, pitch, and more. For example:

chrome.tts.speak('Hello, world.', {'rate': 2.0});

It's also a good idea to specify the language so that a synthesizer supporting that language (and regional dialect, if applicable) is chosen.

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

By default, each call to speak() interrupts any ongoing speech and speaks immediately. To determine if a call would be interrupting anything, you can call isSpeaking(). In addition, you can use the enqueue option to cause this utterance to be added to a queue of utterances that will be spoken when the current utterance has finished.

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

A complete description of all options can be found under tts.speak(). Not all speech engines will support all options.

To catch errors and make sure you're calling speak() correctly, pass a callback function that takes no arguments. Inside the callback, check runtime.lastError to see if there were any errors.

chrome.tts.speak(
  utterance,
  options,
  function() {
    if (chrome.runtime.lastError) {
      console.log('Error: ' + chrome.runtime.lastError.message);
    }
  }
);

The callback returns right away, before the engine has started generating speech. The purpose of the callback is to alert you to syntax errors in your use of the TTS API, not to catch all possible errors that might occur in the process of synthesizing and outputting speech. To catch these errors too, you need to use an event listener, described in the next section.

Listen to events

To get more real-time information about the status of synthesized speech, pass an event listener in the options to speak(), like this:

chrome.tts.speak(
  utterance,
  {
    onEvent: function(event) {
      console.log('Event ' + event.type + ' at position ' + event.charIndex);
      if (event.type == 'error') {
        console.log('Error: ' + event.errorMessage);
      }
    }
  },
  callback
);

Each event includes an event type, the character index of the current speech relative to the utterance, and for error events, an optional error message. The event types are:

Four of the event types—'end', 'interrupted', 'cancelled', and 'error'—are final. After one of those events is received, this utterance will no longer speak and no new events from this utterance will be received.

Some voices may not support all event types, and some voices may not send any events at all. If you don't want to use a voice unless it sends certain events, pass the events you require in the requiredEventTypes member of the options object, or use getVoices() to choose a voice that meets your requirements. Both are described in what follows.

SSML markup

Utterances used in this API may include markup using the Speech Synthesis Markup Language (SSML). If you use SSML, the first argument to speak() should be a complete SSML document with an XML header and a top-level <speak> tag, not a document fragment.

For example:

chrome.tts.speak(
  '<?xml version="1.0"?>' +
  '<speak>' +
  '  The <emphasis>second</emphasis> ' +
  '  word of this sentence was emphasized.' +
  '</speak>'
);

Not all speech engines will support all SSML tags, and some may not support SSML at all, but all engines are required to ignore any SSML they don't support and to still speak the underlying text.

Choose a voice

By default, Chrome chooses the most appropriate voice for each utterance you want to speak, based on the language. On most Windows, Mac OS X, and ChromeOS systems, speech synthesis provided by the operating system should be able to speak any text in at least one language. Some users may have a variety of voices available, though, from their operating system and from speech engines implemented by other Chrome extensions. In those cases, you can implement custom code to choose the appropriate voice, or to present the user with a list of choices.

To get a list of all voices, call getVoices() and pass it a function that receives an array of TtsVoice objects as its argument:

chrome.tts.getVoices(
  function(voices) {
    for (var i = 0; i < voices.length; i++) {
      console.log('Voice ' + i + ':');
      console.log('  name: ' + voices[i].voiceName);
      console.log('  lang: ' + voices[i].lang);
      console.log('  extension id: ' + voices[i].extensionId);
      console.log('  event types: ' + voices[i].eventTypes);
    }
  }
);
Types Enum

"start"

"end"

"word"

"sentence"

"marker"

"interrupted"

"cancelled"

"error"

"pause"

"resume"

TtsEvent

An event from the TTS engine to communicate the status of an utterance.

Properties

TtsOptions

The speech options for the TTS engine.

Properties

TtsVoice

A description of a voice available for speech synthesis.

Properties

VoiceGender

Chrome 54+ Deprecated since Chrome 70

Gender is deprecated and is ignored.

Methods

getVoices()

chrome.tts.getVoices(): Promise<TtsVoice[]>

Gets an array of all available voices.

isSpeaking()

chrome.tts.isSpeaking(): Promise<boolean>

Checks whether the engine is currently speaking. On Mac OS X, the result is true whenever the system speech engine is speaking, even if the speech wasn't initiated by Chrome.

pause()

chrome.tts.pause(): void

Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech.

resume()

chrome.tts.resume(): void

If speech was paused, resumes speaking where it left off.

speak()

chrome.tts.speak(
  utterance: string,
  options?: TtsOptions,
)
: Promise<void>

Speaks text using a text-to-speech engine.

Parameters

stop()

chrome.tts.stop(): void

Stops any current speech and flushes the queue of any pending utterances. In addition, if speech was paused, it will now be un-paused for the next call to speak.

Events

onVoicesChanged

chrome.tts.onVoicesChanged.addListener(
  callback: function,
)

Called when the list of tts.TtsVoice that would be returned by getVoices has changed.

Parameters

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-11 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4