这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

Web Speech API 使您能够将语音数据合并到 Web 应用程序中。 Web Speech API 有两个部分:SpeechSynthesis 语音合成 (文本到语音 TTS)和 SpeechRecognition  语音识别(异步语音识别)。

Web Speech 的概念及用法

Web Speech API 使 Web 应用能够处理语音数据,该项 API 包含以下两个部分:

  • 语音识别通过 SpeechRecognition 接口进行访问,它提供了识别从音频输入(通常是设备默认的语音识别服务)中识别语音情景的能力。一般来说,你将使用该接口的构造函数来构造一个新的 SpeechRecognition 对象,该对象包含了一些列有效的对象处理函数来检测识别设备麦克风中的语音输入。SpeechGrammar 接口则表示了你应用中想要识别的特定文法。文法则通过 JSpeech Grammar Format (JSGF.) 来定义。
  • 语音合成通过 SpeechSynthesis 接口进行访问,它提供了文字到语音(TTS)的能力,这使得程序能够读出它们的文字内容(通常使用设备默认的语音合成器)。不同的声音类类型通过 SpeechSynthesisVoice 对象进行表示,不同部分的文字则由 SpeechSynthesisUtterance 对象来表示。你可以将它们传递给 SpeechSynthesis.speak() 方法来产生语音。

更多关于这些特性的细节请参考 Using the Web Speech API

Web Speech 的 API 接口

 语音识别

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 objects.
SpeechRecognitionResult
Represents a single recognition match, which may contain multiple SpeechRecognitionAlternative objects.
SpeechRecognitionResultList
Represents a list of SpeechRecognitionResult objects, or a single one if results are being captured in continuous mode.

语音合成

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.

示例

GitHub 上的 Web Speech API repo 的示例程序展示了语音识别及合成。

规范

规范 状态 描述
Web Speech API Draft 原始定义

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 33[1] 49 (49)[2] 未实现 未实现 未实现
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes)[1] ? 2.5 未实现 未实现 未实现
  • [1] 语音识别接口目前在 Chrome 中是带前缀的,因此你需要使用带有前缀的名称,例如 webkitSpeechRecognition;此外你还需要将你的代码运行在一个 Web 服务器上来保证其正常工作。
  • [2] 虽然当前的语音识别在桌面版的 Firefox 中不会正常工作,但还是可以在 about:config 中,可以通过 media.webspeech.recognition.enable 来启用 —— 一旦所需的内部权限解决后,它很快就会启用。

Firefox OS 权限

如需在应用中使用语音识别,你必须在你的 manifest 中指明下面的权限:

"permissions": {
  "audio-capture" : {
    "description" : "Audio capture"
  },
  "speech-recognition" : {
    "description" : "Speech recognition"
  }
}

若还需要设置应用的特权类型,因此你还需要包含以下这项:

  "type": "privileged"

语音合成则不需要设置权限。

相关链接

文档标签和贡献者

此页面的贡献者: changkun, rzYunjing, xgqfrms-GitHub
最后编辑者: changkun,