SpeechGrammar
已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。
非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!
Web Speech API 的 SpeechGrammar
接口表示一组希望识别服务识别的单词或单词模式。
语法使用 JSpeech 语法格式(JSGF)定义。未来可能还会支持其他格式。
构造函数
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); // 应返回与 grammar 变量的内容相同的结果。
console.log(speechRecognitionList[0].weight); // 应返回 1 - 与 addFromString 中设置的权重相同。