Skip to content

Commit

Permalink
Merge pull request googleapis#2646 from daspecster/fix-transcript-con…
Browse files Browse the repository at this point in the history
…fidence-missing-bug

Allow Transcript to handle missing 'confidence' fields
  • Loading branch information
daspecster authored Oct 31, 2016
2 parents 3dd44f0 + a2df24d commit b0f4dcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion speech/google/cloud/speech/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def from_api_repr(cls, transcript):
:rtype: :class:`Transcript`
:returns: Instance of ``Transcript``.
"""
return cls(transcript['transcript'], transcript['confidence'])
return cls(transcript['transcript'], transcript.get('confidence'))

@classmethod
def from_pb(cls, transcript):
Expand Down
9 changes: 9 additions & 0 deletions speech/unit_tests/test_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ def test_ctor(self):
self.assertEqual('how old is the Brooklyn Bridge',
transcript.transcript)
self.assertEqual(0.98267895, transcript.confidence)

def test_from_api_repr_with_no_confidence(self):
data = {
'transcript': 'testing 1 2 3'
}

transcript = self._getTargetClass().from_api_repr(data)
self.assertEqual(transcript.transcript, data['transcript'])
self.assertIsNone(transcript.confidence)

0 comments on commit b0f4dcb

Please sign in to comment.