Google Cloud Speech API的元数据元素使用什么编码?
我正在使用谷歌云语音API的第二版,来查看一个长时间运行的识别任务的状态。
from google.cloud.speech_v2 import SpeechClient
client_options_ = client_options.ClientOptions(
api_endpoint = "us-west1-speech.googleapis.com"
)
client = SpeechClient(client_options = client_options_)
ops_obj = { "name": "{{name-of-my-job}}" }
resp_obj = client.get_operation(ops_obj)
resp_metadata = resp_obj.metadata.value
print(resp_metadata)
我在使用返回的数据时遇到了一些问题(下面是相关代码片段):
b'\n\x0c\x08\xf0\x8a\xc7\xaf\x06\x10\xa0\xdf\xb3\xce\x03\x12\x0c\x08\x89\xac\xc7\xaf\x06\x10\xe0\xef...
当我尝试解码这些数据时:
resp_metadata.decode('utf-8')
我遇到了这个错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 3: invalid continuation byte
有没有人能给我指个方向?我想把这些元数据变得可用。
1 个回答
0
我搞明白了。感谢Frank Yellin提醒我,我在处理一个protobuf。这让我开始朝着正确的方向思考。
这是我用的代码:
from google.protobuf.json_format import MessageToJson
print(MessageToJson(resp_obj))
结果是格式非常漂亮的JSON。