Skip to content

Commit bffe3d9

Browse files
authored
Merge pull request #2646 from daspecster/fix-transcript-confidence-missing-bug
Allow Transcript to handle missing 'confidence' fields
2 parents ef9d7fc + 427f9b6 commit bffe3d9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/google-cloud-python-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['transcript'], transcript.get('confidence'))
4242

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

packages/google-cloud-python-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)