SpeechGrammarList

已弃用:此特性不再推荐。虽然某些浏览器可能仍然支持它,但它可能已经从相关的网络标准中删除,可能正在删除过程中,或者可能仅为兼容性目的而保留。请避免使用它,如果可能,请更新现有代码;请参阅本页底部的兼容性表格以指导您的决策。请注意,此特性可能随时停止工作。

Web Speech APISpeechGrammarList 接口表示一个 SpeechGrammar 对象列表,其中包含我们希望识别服务识别的单词或单词模式。

语法使用 JSpeech Grammar Format (JSGF) 定义。

注意: 语法概念已从 Web Speech API 中移除。相关的特性仍然保留在规范中,并且仍然被支持的浏览器识别以保持向后兼容,但它们对语音识别服务没有影响。

构造函数

SpeechGrammarList() 已弃用

创建一个新的 SpeechGrammarList 对象。

实例属性

SpeechGrammarList.length 只读 已弃用

返回 SpeechGrammarList 中包含的 SpeechGrammar 对象的数量。

实例方法

SpeechGrammarList.item() 已弃用

标准 getter — 允许使用数组语法从 SpeechGrammarList 中检索单个 SpeechGrammar 对象。

SpeechGrammarList.addFromURI() 已弃用

获取位于特定 URI 的语法,并将其作为新的 SpeechGrammar 对象添加到 SpeechGrammarList 中。

SpeechGrammarList.addFromString() 已弃用

将字符串中的语法作为新的 SpeechGrammar 对象添加到 SpeechGrammarList 中。

示例

js
const grammar =
  "#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;";
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;

规范

规范
Web Speech API
# speechgrammarlist

浏览器兼容性

另见