网络语音 API 语法
Web speech API grammar
谁能告诉我这是什么
const grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghost | white | 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 grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghost | white | 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
如果我想合并我自己的语法,我需要对此行做哪些更改?
该行也是遵循有关此主题的 JSGF specification. There is a more "user-friendly" explanation at MDN 一组规则的字符串。
基本上在这种情况下我们可以将其分解为:
#JSGF V1.0;
a header 来自规范,总是需要知道它应该使用哪个版本。不应该为你改变。
grammar colors;
是您的语法的(自定义)名称。
public <color> =
创建一个名为 color
的可公开访问的规则。 “可公开访问”意味着您的语法可以被其他人导入并且他们可以访问此规则。 color
是规则名称。从另一个规则引用时这是必要的(稍后的示例)
aqua | azure | ...
是匹配这个的选项。 |
表示“或”。因此,当它识别出 aqua
、azure
、...
之一时,它会匹配 <color>
规则。
一个更复杂的引用示例是:
#JSGF V1.0; grammar greeting; <greet> = hello | welcome; <name> = Alice | Bob; public <statement> = <greet> <name>;
但现在说到它的实用性:我玩过 the MDN Speech Recognition Demo a bit and I don't think that browsers are really using the grammar (yet). If you have a look into its source code,它永远不会调用 recognition.onnomatch
函数,这让我觉得语法有点无用。它也不会出现在结果中,最后您只能检索到口语文本的抄本 - 至少在 Chrome.
中是这样
我对此(2020 年年中)的结论是,您现在并不真正需要它。也许它在未来会有帮助,但由于 Can I use... table(仍然)看起来很红,我怀疑这将是用语音做事的最终方式。
谁能告诉我这是什么
const grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghost | white | 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 grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghost | white | 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
如果我想合并我自己的语法,我需要对此行做哪些更改?
该行也是遵循有关此主题的 JSGF specification. There is a more "user-friendly" explanation at MDN 一组规则的字符串。
基本上在这种情况下我们可以将其分解为:
#JSGF V1.0;
a header 来自规范,总是需要知道它应该使用哪个版本。不应该为你改变。grammar colors;
是您的语法的(自定义)名称。public <color> =
创建一个名为color
的可公开访问的规则。 “可公开访问”意味着您的语法可以被其他人导入并且他们可以访问此规则。color
是规则名称。从另一个规则引用时这是必要的(稍后的示例)aqua | azure | ...
是匹配这个的选项。|
表示“或”。因此,当它识别出aqua
、azure
、...
之一时,它会匹配<color>
规则。
一个更复杂的引用示例是:
#JSGF V1.0; grammar greeting; <greet> = hello | welcome; <name> = Alice | Bob; public <statement> = <greet> <name>;
但现在说到它的实用性:我玩过 the MDN Speech Recognition Demo a bit and I don't think that browsers are really using the grammar (yet). If you have a look into its source code,它永远不会调用 recognition.onnomatch
函数,这让我觉得语法有点无用。它也不会出现在结果中,最后您只能检索到口语文本的抄本 - 至少在 Chrome.
我对此(2020 年年中)的结论是,您现在并不真正需要它。也许它在未来会有帮助,但由于 Can I use... table(仍然)看起来很红,我怀疑这将是用语音做事的最终方式。