Google 云语音到文本语法将结果缩小为数字?

Google cloud speech to text grammar to narrow results to a number?

我只是想传递一个包含一位数字的微型音频剪辑(8Khz 电话),然后返回一个作为文本的一位数字,缩小为一个数字。

文件输入 > 数字作为文本输出。最好通过 python 命令行 API。

问题是,默认情况下,它会将 1,2,3,4,5 之类的东西识别为 won,too,free,fore,5 ... 不好!

我相信我想要什么叫语法?或者像亚马逊在 Alexa 中使用的数字槽类型?我查看了云语音文档,但找不到。我唯一能想到的就是遍历给定的备选方案,看看是否有任何匹配 int 而不是单词。如果 none 做了,那会怎样?

谢谢。

尝试添加 speechContexts。然后您可以添加一些您认为最有可能的短语。

A.Queue的答案是正确的,但是,以防其他人被文档咬伤:

link given建议:

{ "phrases": [ string], } 

python documentation 说:

speech_contexts

Optional: A means to provide context to assist the speech recognition.

python 示例显示:

language_code='en-US',
max_alternatives=max_alternatives,
profanity_filter=True,
speech_contexts=['Google', 'cloud'],

实际有效的是:

speech_contexts=[speech.types.SpeechContext(
     phrases=['Google', 'cloud'],
 )]

我设法从 Slack 上的一位 Google 员工那里得到了这个,他向我指出了一些更全面、更准确的替代方案 documentation。书签最后 link 以备将来使用。