Skip to content

Commit bff5c69

Browse files
committed
Fixes issue when max_alternatives is more than 1 and confidence is missing.
1 parent 53c189a commit bff5c69

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

speech/google/cloud/speech/transcript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def from_api_repr(cls, transcript):
3838
:rtype: :class:`Transcript`
3939
:returns: Instance of ``Transcript``.
4040
"""
41-
return cls(transcript['transcript'], transcript['confidence'])
41+
return cls(transcript.get('transcript'), transcript.get('confidence'))
4242

4343
@classmethod
4444
def from_pb(cls, transcript):

speech/unit_tests/test_transcript.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ def test_ctor(self):
3131
self.assertEqual('how old is the Brooklyn Bridge',
3232
transcript.transcript)
3333
self.assertEqual(0.98267895, transcript.confidence)
34+
35+
def test_from_api_repr_with_no_confidence(self):
36+
data = {
37+
'transcript': 'testing 1 2 3'
38+
}
39+
40+
transcript = self._getTargetClass().from_api_repr(data)
41+
self.assertEqual(transcript.transcript, data['transcript'])
42+
self.assertIsNone(transcript.confidence)

0 commit comments

Comments
 (0)