I have obtained the results from google speech in a variable
data = {'name': '1235433175192040985', 'metadata': {'@type': 'type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeMetadata', 'progressPercent': 100, 'startTime': '2018-04-11T12:56:58.237060Z', 'lastUpdateTime': '2018-04-11T12:57:44.944653Z'}, 'done': true, 'response': {'@type': 'type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeResponse', 'results': [{'alternatives': [{'transcript': 'hi how are you', 'confidence': 0.92438406}]}, {'alternatives': [{'transcript': 'How are you doing?', 'confidence': 0.9402676}]}]}}
json_dict = json.loads(data)
On this it throws error
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
For the rest of parsing I wrote
for result in json_dict["response"]["results"]:
if "alternatives" in result:
alternatives = result["alternatives"][0]
if "confidence" in alternatives:
print(alternatives["confidence"])
if "transcript" in alternatives:
print(alternatives["transcript"])
What am I doing wrong?