I'm using Google Cloud Speech-to-Text V2 API, specifically the BatchRecognizeResponse type. This response is structured as a protobuf object with multiple embedded fields, but I’m having difficulty figuring out the exact Python types they are converted into.
I have the following code:
operation = client.batch_recognize(request=request)
response = operation.result()
When I print response, I get:
results {
key: "gs://my-path"
value {
metadata {
total_billed_duration {
seconds: 121
}
}
cloud_storage_result {
srt_format_uri: "my-output-path"
}
}
}
total_billed_duration {
seconds: 121
}
I need to extract the value of srt_format_uri, which is "my-output-path".
I attempted to treat results as a dictionary using .items() and also tried iterating over operation.result() like this:
for result in operation.result():
key = result.key
...
None of these approaches worked.
How can I correctly extract srt_format_uri from the BatchRecognizeResponse in Python?
Or how can I figure out exactly what are the internal python structures that protobuf is converted into? I.e. is there documentation for .proto files available for this?
I'm using Google Cloud Speech-to-Text V2 API, specifically the BatchRecognizeResponse type. This response is structured as a protobuf object with multiple embedded fields, but I’m having difficulty figuring out the exact Python types they are converted into.
I have the following code:
operation = client.batch_recognize(request=request)
response = operation.result()
When I print response, I get:
results {
key: "gs://my-path"
value {
metadata {
total_billed_duration {
seconds: 121
}
}
cloud_storage_result {
srt_format_uri: "my-output-path"
}
}
}
total_billed_duration {
seconds: 121
}
I need to extract the value of srt_format_uri, which is "my-output-path".
I attempted to treat results as a dictionary using .items() and also tried iterating over operation.result() like this:
for result in operation.result():
key = result.key
...
None of these approaches worked.
How can I correctly extract srt_format_uri from the BatchRecognizeResponse in Python?
Or how can I figure out exactly what are the internal python structures that protobuf is converted into? I.e. is there documentation for .proto files available for this?
Oh well, this works:
for key, value in response.results.items():
print(f"Key: {key}")
print(f"Total Billed Duration: {value.metadata.total_billed_duration.seconds} seconds")
print(f"SRT Format URI: {value.cloud_storage_result.srt_format_uri}")