SpeechRecognition:grammars 属性
SpeechRecognitiongrammars 属性会返回并设置一个 SpeechGrammar 对象集合,这些对象代表当前 SpeechRecognition 所能理解的语法。
注意: 语法概念已从 Web Speech API 中移除。相关的特性仍然保留在规范中,并且仍然被支持的浏览器识别以保持向后兼容,但它们对语音识别服务没有影响。
值
一个 SpeechGrammarList,其中包含代表你的应用所使用的语法的 SpeechGrammar 对象。
示例
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 # dom-speechrecognition-grammars | 
浏览器兼容性
加载中…