SpeechRecognitionPhrase
SpeechRecognitionPhrase 接口是 Web Speech API 的一部分,它表示一个可以传递给语音识别引擎以进行上下文偏置的短语。
实例属性
SpeechRecognitionPhrase.boost只读 实验性-
一个浮点数,表示您想应用于相应
phrase的提升(boost)量。 SpeechRecognitionPhrase.phrase只读 实验性-
一个字符串,包含您希望在识别引擎的偏置中提升的单词或短语。
示例
基本用法
以下代码首先创建一个包含要提升的短语及其 boost 值的数组。我们通过将原始数组元素映射到 SpeechRecognitionPhrase() 构造函数调用,将此数据转换为 SpeechRecognitionPhrase 对象的 ObservableArray。
js
const phraseData = [
{ phrase: "azure", boost: 5.0 },
{ phrase: "khaki", boost: 3.0 },
{ phrase: "tan", boost: 2.0 },
];
const phraseObjects = phraseData.map(
(p) => new SpeechRecognitionPhrase(p.phrase, p.boost),
);
在创建 SpeechRecognition 实例后,我们通过将 phraseObjects 数组设置为 SpeechRecognition.phrases 属性的值来添加我们的上下文偏置短语。
js
const recognition = new SpeechRecognition();
recognition.continuous = false;
recognition.lang = "en-US";
recognition.interimResults = false;
recognition.processLocally = true;
recognition.phrases = phraseObjects;
// …
此代码摘自我们的 设备端语音颜色更改器(在线运行演示)。有关完整解释,请参阅 使用 Web 语音 API。
规范
| 规范 |
|---|
| Web Speech API # speechrecognitionphrase |
浏览器兼容性
加载中…