Speech synthesis
The SpeechSynthesis interface of the Web Speech API is the controller interface for the speech service; this can be used to retrieve information about the synthesis voices available on the device, start and pause speech, and other commands besides.
EventTarget SpeechSynthesis
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 33 | 14 | 49 | 7 | 33 | 7 | |
| The cancel() method of the SpeechSynthesis interface removes all utterances from the utterance queue. | 33 | 14 | 49 | 7 | 33 | 7 |
| The getVoices() method of the SpeechSynthesis interface returns a list of SpeechSynthesisVoice objects representing all the available voices on the current device. | 33 | 14 | 49 | 7 | 33 | 7 |
| The pause() method of the SpeechSynthesis interface puts the SpeechSynthesis object into a paused state. | 33 | 14 | 49 | 7 | 33 | 7 |
| The paused read-only property of the SpeechSynthesis interface is a boolean value that returns true if the SpeechSynthesis object is in a paused state, or false if not. | 33 | 14 | 49 | 7 | 33 | 7 |
| The pending read-only property of the SpeechSynthesis interface is a boolean value that returns true if the utterance queue contains as-yet-unspoken utterances. | 33 | 14 | 49 | 7 | 33 | 7 |
| The resume() method of the SpeechSynthesis interface puts the SpeechSynthesis object into a non-paused state: resumes it if it was already paused. | 33 | 14 | 49 | 7 | 33 | 7 |
| The speak() method of the SpeechSynthesis interface adds an SpeechSynthesisUtterance to the utterance queue; it will be spoken when any other utterances queued before it have been spoken. | 33 | 14 | 49 | 7 | 33 | 7 |
| The speaking read-only property of the SpeechSynthesis interface is a boolean value that returns true if an utterance is currently in the process of being spoken — even if SpeechSynthesis is in a SpeechSynthesis/pause() state. | 33 | 14 | 49 | 7 | 33 | 7 |
| The voiceschanged event of the Web Speech API is fired when the list of SpeechSynthesisVoice objects that would be returned by the SpeechSynthesis.getVoices() method has changed (when the voiceschanged event fires.) | 33 | 14 | 49 | 16 | 33 | 16 |
| The SpeechSynthesisErrorEvent interface of the Web Speech API contains information about any errors that occur while processing SpeechSynthesisUtterance objects in the speech service. | 33 | ≤18 | 49 | 7 | 33 | 7 |
| The error property of the SpeechSynthesisErrorEvent interface returns an error code indicating what has gone wrong with a speech synthesis attempt. | 33 | ≤18 | 49 | 7 | 33 | 7 |
| The SpeechSynthesisErrorEvent() constructor creates a new SpeechSynthesisErrorEvent object. | 71 | 79 | 49 | 16 | 71 | 16 |
| The SpeechSynthesisEvent interface of the Web Speech API contains information about the current state of SpeechSynthesisUtterance objects that have been processed in the speech service. | 33 | 14 | 49 | 7 | 33 | 7 |
| The charIndex read-only property of the SpeechSynthesisUtterance interface returns the index position of the character in SpeechSynthesisUtterance.text that was being spoken when the event was triggered. | 33 | 14 | 49 | 7 | 33 | 7 |
| The read-only charLength property of the SpeechSynthesisEvent interface returns the number of characters left to be spoken after the character at the SpeechSynthesisEvent.charIndex position. | 77 | 15 | 53 | 16 | 77 | 16 |
| The elapsedTime read-only property of the SpeechSynthesisEvent returns the elapsed time in seconds, after the SpeechSynthesisUtterance.text started being spoken, at which the event was triggered. | 33 | 14 | 49 | 7 | 33 | 7 |
| The name read-only property of the SpeechSynthesisUtterance interface returns the name associated with certain types of events occurring as the SpeechSynthesisUtterance.text is being spoken: the name of the SSML marker reached in the case of a SpeechSynthesisUtterance.markevent event, or the type of boundary reached in the case of a… | 33 | 14 | 49 | 7 | 33 | 7 |
| The SpeechSynthesisEvent() constructor creates a new SpeechSynthesisEvent object. | 71 | 14 | 49 | 16 | 71 | 16 |
| The utterance read-only property of the SpeechSynthesisUtterance interface returns the SpeechSynthesisUtterance instance that the event was triggered on. | 33 | 14 | 49 | 16 | 33 | 16 |
| The SpeechSynthesisUtterance interface of the Web Speech API represents a speech request. It contains the content the speech service should read and information about how to read it (e.g., language, pitch and volume.) | 33 | 14 | 49 | 7 | 33 | 7 |
| The boundary event of the Web Speech API is fired when the spoken utterance reaches a word or sentence boundary. | 33 | 14 | 49 | 7 | 33 | 7 |
| The end event of the Web Speech API SpeechSynthesisUtterance object is fired when the utterance has finished being spoken. | 33 | 14 | 49 | 7 | 33 | 7 |
| The error event of the Web Speech API SpeechSynthesisUtterance object is fired when an error occurs that prevents the utterance from being successfully spoken. | 33 | 14 | 49 | 7 | 33 | 7 |
| The lang property of the SpeechSynthesisUtterance interface gets and sets the language of the utterance. | 33 | 14 | 49 | 7 | 33 | 7 |
| The mark event of the Web Speech API SpeechSynthesisUtterance object is fired when the spoken utterance reaches a named SSML "mark" tag. | 33 | 14 | 49 | 7 | 33 | 7 |
| The pause event of the Web Speech API SpeechSynthesisUtterance object is fired when the utterance is paused part way through. | 33 | 14 | 49 | 7 | 33 | 7 |
| The pitch property of the SpeechSynthesisUtterance interface gets and sets the pitch at which the utterance will be spoken at. | 33 | 14 | 49 | 7 | 33 | 7 |
| The rate property of the SpeechSynthesisUtterance interface gets and sets the speed at which the utterance will be spoken at. | 33 | 14 | 49 | 7 | 33 | 7 |
| The resume event of the Web Speech API SpeechSynthesisUtterance object is fired when a paused utterance is resumed. | 33 | 14 | 49 | 7 | 33 | 7 |
| The SpeechSynthesisUtterance() constructor of the SpeechSynthesisUtterance interface returns a new SpeechSynthesisUtterance object instance. | 33 | 14 | 49 | 7 | 33 | 7 |
| The start event of the Web Speech API SpeechSynthesisUtterance object is fired when the utterance has begun to be spoken. | 33 | 14 | 49 | 7 | 33 | 7 |
| The text property of the SpeechSynthesisUtterance interface gets and sets the text that will be synthesized when the utterance is spoken. | 33 | 14 | 49 | 7 | 33 | 7 |
| The voice property of the SpeechSynthesisUtterance interface gets and sets the voice that will be used to speak the utterance. | 33 | 14 | 49 | 7 | 33 | 7 |
| The volume property of the SpeechSynthesisUtterance interface gets and sets the volume that the utterance will be spoken at. | 33 | 14 | 49 | 7 | 33 | 7 |
| The SpeechSynthesisVoice interface of the Web Speech API represents a voice that the system supports. Every SpeechSynthesisVoice has its own relative speech service including information about language, name and URI. | 33 | 14 | 49 | 7 | 33 | 7 |
| The default read-only property of the SpeechSynthesisVoice interface returns a boolean value indicating whether the voice is the default voice for the current app (true), or not (false.) | 33 | 14 | 49 | 7 | 33 | 7 |
| The lang read-only property of the SpeechSynthesisVoice interface returns a BCP 47 language tag indicating the language of the voice. | 33 | 14 | 49 | 7 | 33 | 7 |
| The localService read-only property of the SpeechSynthesisVoice interface returns a boolean value indicating whether the voice is supplied by a local speech synthesizer service (true), or a remote speech synthesizer service (false.) | 33 | 14 | 49 | 7 | 33 | 7 |
| The name read-only property of the SpeechSynthesisVoice interface returns a human-readable name that represents the voice. | 33 | 14 | 49 | 7 | 33 | 7 |
| The voiceURI read-only property of the SpeechSynthesisVoice interface returns the type of URI and location of the speech synthesis service for this voice. | 33 | 14 | 49 | 7 | 33 | 7 |
| The speechSynthesis read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. | 33 | 14 | 49 | 7 | 33 | 7 |
- In Android, `pause()` ends the current utterance. `pause()` behaves the same as `cancel()`.
- This browser only partially implements this feature
- The `boundary` event does not fire as expected. See bug 40715888.
- This browser only partially implements this feature
- The `boundary` event does not fire as expected. See bug 40715888.
- In Firefox, speech synthesis voices do not start loading until after the first call to `window.speechSynthesis.getVoices()`. A way to mitigate this issue is to call the method at the beginning of page load, then wait a few seconds before calling the method again. Voices will remain loaded until all tabs that have called this method have been closed.
Syntax
let utterance = new SpeechSynthesisUtterance("Hello world!");
speechSynthesis.speak(utterance); Use cases
-
Using Speech synthesis
The SpeechSynthesis interface of the Web Speech API is the controller interface for the speech service; this can be used to retrieve information about the synthesis voices available on the device, start and pause speech, and other commands besides.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.