Google Cloud Platform 语音转文本 - 自定义转录文本

问题描述

我正在使用 Google Cloud Platform (GCP) model adaptation feature of speech to text 来识别行业独有的话语,例如当用户说出 JSON 时,应将其转录为 JSON 而不是“Jason”。我通过使用短语集和相关的提升值来实现这一点。

本示例中的文本转录为 Json。我希望将其转录为 JSON(全部大写)

我已彻底阅读 GCP 文档,但没有找到与我的问题相关的文档。我也试过 Azure,其中 there's an option to upload a pronunciation file。我正在 GCP 中寻找类似的解决方案。

解决方法

我自己试过,结果一样。即使 maxAlternatives 设置为 20。

目前没有像发音文件这样的选项,所以我创建了一个 Feature Request 来要求它的实现。
请记住给它加星标,以便在每次更新时收到电子邮件通知。并且,如果可以,请添加您的业务案例和/或影响以提供完整的图片。

目前,解决方法是在您的代码上实现一个“捕手”。 在 Python 中,您可以使用 replace()upper()
内容如下:

for result in response.results:
    print("Transcript: {}".format(result.alternatives[0].transcript.replace('Json','JSON')))

如果您需要捕获更多单词,请使用 if 条件循环遍历列表:

result='I need a Json file'
lower_words = ['Json','csv']
upper_words = ['JSON','CSV']
for result in response.results:
    for lower_word,upper_word in zip(lower_words,upper_words):
        if lower_word in result:
            print("Transcript: {}".format(result.alternatives[0].transcript.replace(lower_word,upper_word)))

当然,这将在满足条件的每次迭代中打印,因此如果结果中可能有多个这些单词之一,您可能希望存储中间结果并在嵌套循环之后打印。

不过我希望你不要有太多的词要改,否则这会大大减慢你的申请速度。