# Web Speech API

Web Speech API 是由 W3C 开发的一套 [JavaScript](https://www.edgepedia.org/zh/javascript) API，它让网页能够在脚本控制下集成语音识别（语音转文字）和[语音合成](https://www.edgepedia.org/zh/speech-synthesis)（文字转语音）功能。开发者可以用它生成语音输出，也可以把语音用作表单填写、连续听写和控制的输入，由页面来控制激活、时序、结果和备选项。<sup>[1](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi)</sup>

| 关键事实 | 详情 |
|---|---|
| 两大部分 | `SpeechRecognition` 负责语音转文字，`SpeechSynthesis`（通过 `window.speechSynthesis`）负责文字转语音<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup> |
| 首份规范 | 2012 年 10 月 19 日，由 Speech API 社区组发布；编辑为 Google 公司的 Glen Shires 和 Hans Wennborg，依据 W3C 社区最终规范协议发布<sup>[1](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi)</sup> |
| 首个实现 | Chromium 从版本 25 起提供，带有厂商前缀 `webkitSpeechRecognition`<sup>[3](https://developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api/)</sup> |
| 当今的识别支持 | Chrome（2025 年从版本 139 起使用标准名称）、Edge、Safari（iOS 从 14.5 起）、三星浏览器；Firefox 默认禁用<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup> |
| 全球覆盖 | 据 Can I use 统计，约覆盖 87.96% 的用户，所有支持浏览器均被标记为部分支持而非完全支持<sup>[4](https://caniuse.com/speech-recognition)</sup> |
| 处理位置 | 在 Chrome 中，识别音频默认发送到 Web 服务处理，因此无法离线工作；该 API 也允许设备端识别<sup>[5](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition)</sup> |
| 隐私控制 | `on-device-speech-recognition` Permissions-Policy 指令（默认允许列表为 `self`）控制设备端识别，被阻止时 `SpeechRecognition.available()` 和 `install()` 会失败<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy/on-device-speech-recognition)</sup> |

## API 提供的能力

该 API 包含两个组件。[语音识别](https://www.edgepedia.org/zh/speech-recognition)通过 `SpeechRecognition` 接口访问，其构造函数创建一个识别器，当来自设备麦克风或音轨的语音到达时触发事件。应用可以设置识别语言（`lang`，默认取 HTML 的 `lang` 属性或用户代理的语言）、请求连续结果、在最终结果之前请求临时结果，以及设置 `maxAlternatives`（默认值为 1）来指定每个结果的备选假设数量。方法包括 `start()`、`stop()`（尝试基于目前已捕获的音频返回结果）和 `abort()`（停止监听且不返回结果）。事件覆盖识别的整个生命周期，包括 `start`、`audiostart`、`speechstart`、`result`、`nomatch`、`error` 和 `end`。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup><sup> • </sup><sup>[5](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition)</sup>

语音合成通过 `SpeechSynthesis` 控制器接口访问，通常经由设备的默认语音合成器。要朗读的文本封装在 `SpeechSynthesisUtterance` 对象中，这些对象携带内容和朗读参数，如语言、音高和音量；可用的语音由 `SpeechSynthesisVoice` 对象表示，将话语对象传给 `SpeechSynthesis.speak()` 即可朗读。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup>

该规范不依赖底层语音引擎：它既支持基于服务器和基于客户端或嵌入式的识别与合成，也同时面向简短的一次性输入和连续语音输入。<sup>[7](https://wicg.github.io/speech-api/)</sup>

## 历史与标准化

该规范于 2012 年 10 月 19 日由 W3C Speech API 社区组依据社区最终规范协议首次发布，编辑为 Google 的 Glen Shires 和 Hans Wennborg。<sup>[1](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi)</sup> 2012 年 12 月的 Web Speech 工作组章程草案将该组的使命定为：通过可在 HTML 及任何带有 JavaScript 解释器的环境中使用的 JavaScript API，将语音引入 Web；初始主席为 Dan Burnett，截止日期为 2014 年 10 月 31 日，里程碑计划目标是在 2014 年第三季度成为 W3C 推荐标准。章程要求所有特性在进入提议推荐标准之前必须有两个独立实现，并指出这些 API 涉及对安全和隐私至关重要的能力的访问。<sup>[8](https://www.w3.org/2012/12/speech-charter.html)</sup>

实现早于标准化完成：Chromium 从版本 25 起就提供了带有厂商前缀的草案版本，而当时该规范既未定稿，也不在 W3C 标准轨道上。<sup>[3](https://developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api/)</sup> 开发工作后来移入 WebAudio 工作组的代码仓库，2026 年的一份工作组修订版为 `SpeechRecognitionResult` 增加了时间戳，作为不可为 null 的 `double` 值，以秒为单位，相对于音频流起点，旨在支持同步实时字幕，以及检测设备端识别延迟并故障转移到云端后端。参与该工作的规范编辑包括 Google 的 Alan Ding、Evan Liu 和 Mozilla 的 Paul Adenot。<sup>[9](https://lists.w3.org/Archives/Public/public-webapps-github/2026Aug/0314.html)</sup>

## 浏览器支持

该 API 的两大部分覆盖率差异悬殊。语音合成在所有当前主流浏览器中均可使用：Chrome、Edge、Safari、Firefox、Opera、三星浏览器及其移动版本。<sup>[10](https://textintoaudio.com/browser-support)</sup> 语音识别的范围则窄得多。Chrome 自版本 33 起以 `webkitSpeechRecognition` 前缀支持该功能，标准名称 `SpeechRecognition` 从 Chrome 139（2025 年 8 月 5 日发布）起可用；iOS 上的 Safari 自 14.5（2021 年 4 月）起支持，三星浏览器自版本 2 起支持。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup> Firefox 从未默认启用该功能：版本 22 至 157 均默认禁用，从 Firefox 143（2025 年 9 月 16 日）起，用户必须显式设置 `media.webspeech.recognition.enable` 首选项才能启用。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup> Can I use 给出的全球使用率为 87.96%，并将 Chrome、Safari、三星浏览器及相关浏览器标记为部分支持而非完全支持。<sup>[4](https://caniuse.com/speech-recognition)</sup>

Mozilla 自己的立场文件记录了这一差距：Duolingo、Google 翻译和 Google 语音搜索等网站依赖该 API，因此在 Firefox 中不提供语音输入，Mozilla 称随着语音输入日益普及，这构成了 Web 兼容性问题。Mozilla 还表示，Firefox 的实现可以提供更私密的语音体验，不会将可识别信息与用户的音频录音一同保存。<sup>[11](https://wiki.mozilla.org/Web_Speech_API_-_Speech_Recognition)</sup>

## 识别在何处进行，以及隐私

即使 `SpeechRecognition` 对象存在，识别通常也依赖厂商的在线服务。在 Chrome 中，在网页上使用语音识别默认涉及基于服务器的识别引擎：音频被发送到 Web 服务进行处理，因此无法离线工作。<sup>[5](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition)</sup> 规范本身则同时预见了基于服务器和设备端的引擎。<sup>[7](https://wicg.github.io/speech-api/)</sup>

**设备端识别**由 `on-device-speech-recognition` Permissions-Policy 指令管理，这是一个实验性的 HTTP 头指令，默认允许列表为 `self`。在已定义的策略阻止使用时，对 `SpeechRecognition.available()`（检查指定语言是否可用于识别）或 `SpeechRecognition.install()`（安装设备端识别所需的语言包）的调用会失败。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy/on-device-speech-recognition)</sup> `SpeechRecognition` 的 `processLocally` 属性指定识别是否必须在用户设备本地执行。<sup>[5](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition)</sup>

## 实际限制

若干约束条件影响着实际使用。Chrome 要求代码通过 Web 服务器提供，识别才能工作。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)</sup> 合成方面有文档记录的怪癖包括自动播放规则、15 秒截断以及 Android 上的暂停行为。<sup>[10](https://textintoaudio.com/browser-support)</sup>

## References

1. [Web Speech API Specification, 19 October 2012, W3C Speech API Community Group](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi)
2. [Web Speech API, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)
3. [Voice driven web apps: Introduction to the Web Speech API, Chrome for Developers](https://developer.chrome.com/blog/voice-driven-web-apps-introduction-to-the-web-speech-api/)
4. [Speech Recognition API, Can I use](https://caniuse.com/speech-recognition)
5. [SpeechRecognition, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition)
6. [Permissions-Policy: on-device-speech-recognition directive, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy/on-device-speech-recognition)
7. [Web Speech API, Draft Community Group Report, WICG](https://wicg.github.io/speech-api/)
8. [Web Speech Working Group Charter (draft), W3C](https://www.w3.org/2012/12/speech-charter.html)
9. [W3C TAG design review: Web Speech API SpeechRecognitionResult Timestamps, public-webapps-github archive](https://lists.w3.org/Archives/Public/public-webapps-github/2026Aug/0314.html)
10. [Web Speech API Browser Support: speechSynthesis and SpeechRecognition](https://textintoaudio.com/browser-support)
11. [Web Speech API - Speech Recognition, MozillaWiki](https://wiki.mozilla.org/Web_Speech_API_-_Speech_Recognition)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Web development and web-platform technologies › Web platform APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/web-speech-api

English original: https://www.edgepedia.org/web-speech-api
