from google.protobuf.json_format import MessageToDict
audio={'results': [{'alternatives':
[{'transcript': 'His name is Charlie', 'confidence': 0.9259988}], 'resultEndTime': '7.700s', 'languageCode': 'en'},
{'alternatives':
[{'transcript': 'and he lives in xxx street', 'confidence': 0.9259988}], 'resultEndTime': '11.900s', 'languageCode': 'en'}
],
'totalBilledTime': '14s',
'requestId': '68687945678899765555'}
Hi! I want to extract ‘transcript and’ ‘resultEndTime’ from my dictionary. When I did
audio['results'][0]['alternatives'][0]['transcript']
it only prints "His name is Charlie", but what I want is "His name is Charlie and he lives in xxx street". Sometimes there are more than 2 dictionaries so I do not know how to merge them.
I also only want to extract the last ‘resultEndTime’ which is ‘11.900s’
>Solution :
Get each transcript and join it with a space between each one, and then get the last result’s resultEndTime.
transcript = " ".join(res['alternatives'][0]['transcript'] for res in audio['results'])
end_time = audio['results'][-1]['resultEndTime']
output from print:
His name is Charlie and he lives in xxx street
11.900s