【问题标题】:Web speech API grammarWeb 语音 API 语法
【发布时间】:2020-11-09 13:48:38
【问题描述】:

谁能告诉我这是什么

 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

如果我想合并我自己的语法,我需要对这一行进行哪些更改?

【问题讨论】:

  • 你想要什么样的语法?像这里这样带颜色的单词?
  • 是的。但我什至可以定义这些单词的数组并将其传递到这里,但我首先要知道这条线的含义。无法从文档中理解。

标签: javascript ecmascript-6 speech-recognition webspeech-api


【解决方案1】:

该行是遵循JSGF specification 的一组规则的字符串。 MDN 也有关于这个主题的更“用户友好”的解释。

基本上在这种情况下,我们可以将其分解为:

  • #JSGF V1.0; 规范中的标头,始终需要知道它应该使用哪个版本。不应该为你改变。
  • grammar colors; 是您的语法的(自定义)名称。
  • public &lt;color&gt; = 创建一个名为 color 的可公开访问的规则。 “可公开访问”意味着您的语法可以由其他人导入,并且他们可以访问此规则。 color 是规则名称。从另一个规则引用时这是必要的(稍后示例)
  • aqua | azure | ... 是与此匹配的选项。 | 表示“或”。因此,当它识别出aquaazure... 之一时,它会匹配&lt;color&gt; 规则。

一个更复杂的引用示例是: #JSGF V1.0; grammar greeting; &lt;greet&gt; = hello | welcome; &lt;name&gt; = Alice | Bob; public &lt;statement&gt; = &lt;greet&gt; &lt;name&gt;;

但现在来看这个的实用性:我已经玩过the MDN Speech Recognition Demo 了一点,我认为浏览器还没有真正使用语法。如果你看一下its source code,它永远不会调用recognition.onnomatch 函数,这让我觉得语法有点没用。它也不会显示在结果中,最后您只能检索语音文本的抄本 - 至少在 Chrome 中是这样。

我对此(2020 年年中)的结论是,您现在并不真正需要它。也许将来会有所帮助,但由于Can I use... table(仍然)看起来很红,我怀疑这将是语音处理的最终方式。

【讨论】:

    猜你喜欢
    • 2016-10-31
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2017-10-29
    • 1970-01-01
    • 2015-04-05
    相关资源
    最近更新 更多