The Web Speech API is a browser JavaScript interface that gives web pages two voice capabilities: speech recognition, which converts spoken audio into text, and speech synthesis, which reads text aloud. Among Web APIs, it is one of the few that exposes voice input and output directly to page scripts without plugins or a separate server integration.
The API is defined in a W3C Community Group specification rather than a full W3C Recommendation, and browser support is uneven. Speech synthesis works in all major browsers, while speech recognition remains partial and often prefixed, which makes feature detection essential.
The two interfaces of the Web Speech API
The Web Speech API consists of two independent parts that share a name but solve opposite problems. A page can use either one alone, and support for each is detected separately.
| Aspect | Speech recognition | Speech synthesis |
|---|---|---|
| Direction | Audio to text | Text to audio |
| Main object | SpeechRecognition | speechSynthesis with SpeechSynthesisUtterance |
| Input required | Microphone access | A text string |
| Permission prompt | Yes, microphone permission | No |
| Browser support | Partial, often prefixed | Broad across major browsers |
| Typical engine | Often a cloud service | Operating system voices |
Both interfaces are event driven. Scripts start an operation and then react to events such as result, end, error or boundary, rather than waiting for a return value. This model suits the unpredictable timing of human speech.
Because support differs, robust code first checks for window.SpeechRecognition or its prefixed variant and for window.speechSynthesis. This progressive enhancement approach shows voice controls only where they work and keeps the standard keyboard interface for everyone else.
How speech recognition works in the browser
Speech recognition starts when a script calls start() on a SpeechRecognition object, which in Chromium-based browsers is still exposed as webkitSpeechRecognition. The browser asks for microphone permission, captures audio and passes it to a recognition engine. In Chrome, that engine has traditionally been a remote server-based service, so recognition needs a network connection and sends audio off the device.
Results arrive as a SpeechRecognitionEvent containing a list of results, each with one or more alternatives ranked by a confidence score between 0 and 1. Recognition can return interim results that change while the user speaks and final results that no longer change.
| Property | Effect | Typical value |
|---|---|---|
| lang | Sets the recognition language | A BCP 47 tag such as en-US |
| continuous | Keeps listening after a pause | false for commands, true for dictation |
| interimResults | Returns provisional text | true for live captions |
| maxAlternatives | Number of candidate transcripts | 1 to 5 |
The specification also describes grammars through SpeechGrammarList, originally based on the JSGF format, but most engines ignore them in practice. Newer browser versions have begun to add on-device recognition options, which improve privacy and offline use, though support is still evolving and varies by browser.
How speech synthesis produces voice output
Speech synthesis uses a global speechSynthesis controller and one SpeechSynthesisUtterance object per piece of text. The script sets the text and optional voice parameters, then calls speechSynthesis.speak(), which places the utterance in a queue. Methods such as pause(), resume() and cancel() control playback.
Available voices come from speechSynthesis.getVoices(). The list depends on the operating system and browser, and in several browsers it loads asynchronously, so scripts should wait for the voiceschanged event before choosing a voice. Some voices are local and work offline, while others are network voices.
| Parameter | Range | What it changes |
|---|---|---|
| rate | 0.1 to 10, default 1 | Speaking speed |
| pitch | 0 to 2, default 1 | Voice height |
| volume | 0 to 1, default 1 | Loudness |
| voice | One SpeechSynthesisVoice | Speaker and accent |
| lang | BCP 47 language tag | Pronunciation rules |
In practice, rates above about 2 become hard to understand, and many voices ignore parts of the range. The boundary event reports word and sentence positions, which allows a page to highlight text as it is spoken.
Web Speech API compared with related audio technologies
The Web Speech API is a high-level interface focused on language. Related Web APIs work at a lower level and are often confused with it.
| Technology | Level | Main purpose |
|---|---|---|
| Web Speech API | High-level, language aware | Recognize and speak words |
| Web Audio API | Low-level signal processing | Generate, mix and analyze sound |
| WebRTC | Real-time media transport | Stream audio and video between peers |
| Cloud speech services | Server-side, called over HTTP | Accurate, configurable transcription |
Teams that need consistent accuracy across browsers, speaker diarization or custom vocabulary usually capture audio with getUserMedia and send it to a dedicated speech service instead. The built-in API is best for lightweight voice features where zero integration cost matters more than control.
Limitations, privacy and accessibility concerns
- Inconsistent support: recognition is unavailable in some browsers, so every feature needs a text fallback.
- Privacy: server-based recognition sends voice data to a third party, which may require disclosure under data protection rules such as the GDPR.
- Secure context: microphone access works only on HTTPS pages and requires a user permission grant.
- Autoplay rules: some browsers block speech synthesis until the user has interacted with the page.
- Accuracy: noise, accents and domain vocabulary reduce recognition quality, and the API offers no training or tuning.
Speech synthesis is not a replacement for screen readers. Users who rely on assistive technology already have a preferred reader, and a page that speaks on its own can talk over the screen reader. Voice features should be optional and clearly controllable.
The idea in brief
The Web Speech API lets a website listen and talk. With permission to use the microphone, a page can turn what a person says into written words. In the other direction, it can take written text and read it aloud with a computer voice.
It works a bit like built-in dictation and read-aloud tools, but a website can switch them on for a specific task. The catch is that not every browser supports listening, so good sites always keep the keyboard as a backup.
A practical scenario
A language-learning web application wants students to practice pronunciation. The page shows a phrase, reads it aloud with speech synthesis at a rate of 0.8 in a Spanish voice, and then asks the student to repeat it.
When the student presses a button, the page starts speech recognition with lang set to es-ES and interim results enabled, so the transcript appears as the student speaks. The script compares the final transcript with the target phrase and uses the confidence score to decide whether to praise the attempt or suggest another try. In browsers without recognition, the button is hidden and a typing exercise appears instead.
The result is a voice practice feature built in a few hundred lines of JavaScript, with no paid speech service, while students on unsupported browsers still complete every lesson.