SpeechGrammarList: item() 方法
item
是 SpeechGrammarList
接口的标准 getter——它允许使用数组语法从 SpeechGrammarList
中检索单个 SpeechGrammar
对象。
语法
js
item(index)
参数
index
-
要检索的项目的索引。
返回值
一个 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;
const myFirstGrammar = speechRecognitionList[0]; // variable contain the object created above
规范
规范 |
---|
Web 语音 API # dom-speechgrammarlist-item |
浏览器兼容性
BCD 表格仅在浏览器中加载