网络语音API语法 [英] Web speech API grammar

查看:136
本文介绍了网络语音API语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这是什么吗

Can somebody please tell me what this

 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

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

If i want to incorporate my own grammar what changes to this line do I need to make?

推荐答案

该行是遵循 JSGF规范.存在更加用户友好"的界面. MDN 上的相关说明.

The line is a string following a set of rules of the JSGF specification. There is a more "user-friendly" explanation at MDN on this topic as well.

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

Basically in this case we can break this down to:

  • #JSGF V1.0;规范的标头,总是有必要知道它应该使用哪个版本.不应该为您改变.
  • grammar colors;是语法的(自定义)名称.
  • public <color> = 创建一个称为color的可公开访问的规则. 公众可访问"表示您的语法可以被其他人导入,并且他们可以访问此规则. color是规则名称.当从另一个规则(稍后示例)中引用时,这是必需的
  • aqua | azure | ...是与此匹配的选项. |表示或".因此,当它识别出aquaazure...之一时,便会匹配该<color>规则.
  • #JSGF V1.0; a header from the specification, always necessary to know which version it should use. Shouldn't change for you.
  • grammar colors; is a (custom) name of your grammar.
  • public <color> = creates a publicly accessible rule called color. "Publicly accessible" means your grammar can be imported by someone else and this rule is accessible to them. color is the rule name. This is necessary when referring from another rule (example later)
  • aqua | azure | ... are the options that match this. | means "or". So when it recognises one of aqua, azure, ..., it matches that <color> rule.

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

A bit more sophisticated example with referencing would be: #JSGF V1.0; grammar greeting; <greet> = hello | welcome; <name> = Alice | Bob; public <statement> = <greet> <name>;

但现在要讲究实用性:我玩过有点,我认为浏览器还没有真正使用该语法.如果您查看其来源代码,它将永远不会调用recognition.onnomatch函数,这使语法对我来说有点用处.它也不会显示在结果中,最后,您只能检索口头文字的笔录-至少在Chrome中是这样.

But now to the practicality of this: I've played around with 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, it will never call the recognition.onnomatch function, making the grammar feel a bit useless to me. It also doesn't show up in the results and in the end you only retrieve a transcript of the spoken text - at least in Chrome.

我对此的结论(2020年中)是您现在真的不需要它.也许将来会有所帮助,但是作为我可以使用...表格(仍然)看起来很红,我怀疑这将是用言语做事的最终方法.

My conclusion to this (mid 2020) is that you do not really need it right now. Maybe it could help in the future but as the Can I use... table (still) looks quite red, I doubt this will be the final way of doing things with speech.

这篇关于网络语音API语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆