SpeechGrammar:SpeechGrammar() 构造函数
非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!
SpeechGrammar
接口的 SpeechGrammar()
构造函数创建一个新的 SpeechGrammar
对象实例。
语法
js
new 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 newGrammar = new SpeechGrammar();
newGrammar.src =
"#JSGF V1.0; grammar names; public <name> = chris | kirsty | mike;";
speechRecognitionList[1] = newGrammar; // 应将新的 SpeechGrammar 对象添加到列表中。
规范
此 API 没有官方的 W3C 或 WHATWG 规范。
浏览器兼容性
BCD tables only load in the browser