Search code examples
pythongoogle-api-python-clientgoogle-speech-api

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


I'm looking for a way to get operations related to the Google speech API using the official Google Python Client.

There seems to be some ability to interact with the List Operations and Get Operations apis, as shown here. However, the only three methods that seem to be exposed by the client are recognize, long_running_recognize, and streaming_recognize. (I linked the Beta docs, but the non-beta seem to be the same).

Is there a way to do this through the Python client, without just hitting the HTTP route directly?


Solution

  • After searching more, one user in this github issue posted a couple solutions:

    1)

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

    For him, this did not return metadata, though for me (using google.cloud.speech_v1p1beta) it did return some metadata, but not all (e.g., did return name, did not return others such as startTime, progressPercent, etc).

    2)

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

    (not calling execute will return a Google http request object rather than an operation). This worked better, and returned an object more like the operation object returned by the original long_running_recognize request.

    I have still not found official documentation for either solution though. There is the example that can more or less be inductively derived from the source code.