SpeechGrammar
已弃用:此特性不再推荐。虽然某些浏览器可能仍然支持它,但它可能已经从相关的网络标准中删除,可能正在删除过程中,或者可能仅为兼容性目的而保留。请避免使用它,如果可能,请更新现有代码;请参阅本页底部的兼容性表格以指导您的决策。请注意,此特性可能随时停止工作。
SpeechGrammar 接口是 Web Speech API 的一部分,它表示一套供识别服务识别的词语或词语模式。
语法使用 JSpeech Grammar Format (JSGF) 定义。
注意: 语法概念已从 Web Speech API 中移除。相关的特性仍然保留在规范中,并且仍然被支持的浏览器识别以保持向后兼容,但它们对语音识别服务没有影响。
构造函数
SpeechGrammar()非标准 已弃用-
创建一个新的
SpeechGrammar对象。
实例属性
SpeechGrammar.src已弃用-
设置并返回
SpeechGrammar对象实例中包含的语法的字符串。 SpeechGrammar.weight可选 已弃用-
设置并返回
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;
console.log(speechRecognitionList[0].src); // should return the same as the contents of the grammar variable
console.log(speechRecognitionList[0].weight); // should return 1 - the same as the weight set in addFromString.
规范
| 规范 |
|---|
| Web Speech API # speechreco-speechgrammar |
浏览器兼容性
加载中…