使用 Python 语音客户端从 Google 语音到文本 API 请求 "get operation"

Request a "get operation" from Google Speech to text API using Python Speech Client

我正在寻找 get operations related to the Google speech API using the official Google Python Client 的方法。

似乎有一些与List OperationsGet Operations api交互的能力,如图所示here. However, the only three methods似乎被客户端公开,long_running_recognize,以及 streaming_recognize。 (我链接了测试版文档,但非测试版似乎是一样的)。

有没有办法通过 Python 客户端做到这一点,而不是直接访问 HTTP 路由?

经过更多搜索,this github issue 中的一位用户发布了几个解决方案:

1)

    client = speech.SpeechClient()
    api = operations_v1.OperationsClient(client.transport.channel)
    op = api.get_operation(operation_name)

对他来说,这没有 return 元数据,但对我来说(使用 google.cloud.speech_v1p1beta)它有 return 一些元数据,但不是全部(例如 return 名称,没有 return 其他名称,例如 startTime、progressPercent 等)。

2)

speech_service = discovery.build('speech', 'v1p1beta1')
operation = speech_service.operations().get(name=operation_name).execute()

(不调用 execute 将 return 一个 Google http 请求对象而不是一个操作)。这样效果更好,并且 returned 一个对象更像原始 long_running_recognize 请求 returned 的操作对象。

虽然我还没有找到这两种解决方案的官方文档。有一个例子可以或多或少地从 source code.

归纳得出