SpeechGrammarList:length 属性
length
是 SpeechGrammarList
接口的只读属性,它返回 SpeechGrammarList
中包含的 SpeechGrammar
对象的数量。
值
一个数字,表示 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;
speechRecognitionList.length; // should return 1.
规范
规范 |
---|
Web 语音 API # dom-speechgrammarlist-length |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。