这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

The Web Speech API enables you to incorporate voice data into web apps. The Web Speech API has two parts: SpeechSynthesis (Text-to-Speech), and SpeechRecognition (Asynchronous Speech Recognition.)

Web Speech Concepts and Usage

The Web Speech API makes web apps able to handle voice data. There are two components to this API:

  • Speech recognition is accessed via the SpeechRecognition interface, which provides the ability to recognize voice context from an audio input (normally via the device's default speech recognition service) and respond appropriately. Generally you'll use the interface's constructor to create a new SpeechRecognition object, which has a number of event handlers available for detecting when speech is input through the device's microphone. The SpeechGrammar interface represents a container for a particular set of grammar that your app should recognise. Grammar is defined using JSpeech Grammar Format ( JSGF )。
  • Speech synthesis is accessed via the SpeechSynthesis interface, a text-to-speech component that allows programs to read out their text content (normally via the device's default speech synthesiser.) Different voice types are represented by SpeechSynthesisVoice objects, and different parts of text that you want to be spoken are represented by SpeechSynthesisUtterance objects. You can get these spoken by passing them to the SpeechSynthesis.speak() 方法。

For more details on using these features, see Using the Web Speech API .

Web Speech API Interfaces

Speech recognition

SpeechRecognition
The controller interface for the recognition service; this also handles the SpeechRecognitionEvent sent from the recognition service.
SpeechRecognitionAlternative

Represents a single word that has been recognised by the speech recognition service.

SpeechRecognitionError

Represents error messages from the recognition service.

SpeechRecognitionEvent
The event object for the result and nomatch events, and contains all the data associated with an interim or final speech recognition result.
SpeechGrammar

The words or patterns of words that we want the recognition service to recognize.

SpeechGrammarList
Represents a list of SpeechGrammar 对象。
SpeechRecognitionResult
Represents a single recognition match, which may contain multiple SpeechRecognitionAlternative 对象。
SpeechRecognitionResultList
Represents a list of SpeechRecognitionResult objects, or a single one if results are being captured in continuous 模式。

Speech synthesis

SpeechSynthesis

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.

SpeechSynthesisErrorEvent
Contains information about any errors that occur while processing SpeechSynthesisUtterance objects in the speech service.
SpeechSynthesisEvent
Contains information about the current state of SpeechSynthesisUtterance objects that have been processed in the speech service.
SpeechSynthesisUtterance

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.)

SpeechSynthesisVoice
Represents a voice that the system supports. Every SpeechSynthesisVoice has its own relative speech service including information about language, name and URI.
Window.speechSynthesis
Specced out as part of a [NoInterfaceObject] interface called SpeechSynthesisGetter , and Implemented by the Window object, the speechSynthesis property provides access to the SpeechSynthesis controller, and therefore the entry point to speech synthesis functionality.

范例

Web Speech API repo on GitHub contains demos to illustrate speech recognition and synthesis.

规范

规范 状态 注释
Web 语音 API 草案 初始定义

浏览器兼容性

SpeechRecognition

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
SpeechRecognition Chrome 33 Prefixed 注意事项
33 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: webkit
You'll need to serve your code through a web server for recognition to work.
Edge ≤79 Prefixed 注意事项
≤79 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: webkit
You'll need to serve your code through a web server for recognition to work.
Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 4.4.3 Prefixed 注意事项
4.4.3 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: webkit
You'll need to serve your code through a web server for recognition to work.
Chrome Android 33 Prefixed 注意事项
33 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: webkit
You'll need to serve your code through a web server for recognition to work.
Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 2.0 Prefixed 注意事项
2.0 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: webkit
You'll need to serve your code through a web server for recognition to work.

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

SpeechSynthesis

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
SpeechSynthesis Chrome 33 Edge ≤18 Firefox 49 IE 不支持 No Opera 21 Safari 7 WebView Android 4.4.3 Chrome Android 33 Firefox Android 62 Opera Android 不支持 No Safari iOS 7 Samsung Internet Android 3.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. 接口
    1. SpeechGrammar
    2. SpeechGrammarList
    3. SpeechRecognition
    4. SpeechRecognitionAlternative
    5. SpeechRecognitionError
    6. SpeechRecognitionEvent
    7. SpeechRecognitionResult
    8. SpeechRecognitionResultList
    9. SpeechSynthesis
    10. SpeechSynthesisErrorEvent
    11. SpeechSynthesisEvent
    12. SpeechSynthesisUtterance
    13. SpeechSynthesisVoice

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1