def _make_result(transcript, confidence): from google.cloud.proto.speech.v1 import cloud_speech_pb2 return cloud_speech_pb2.SpeechRecognitionResult(alternatives=[ cloud_speech_pb2.SpeechRecognitionAlternative( transcript=transcript, confidence=confidence, ), ], )
def _make_result(alternatives=()): from google.cloud.proto.speech.v1 import cloud_speech_pb2 return cloud_speech_pb2.SpeechRecognitionResult(alternatives=[ cloud_speech_pb2.SpeechRecognitionAlternative( transcript=alternative['transcript'], confidence=alternative['confidence'], ) for alternative in alternatives ], )
def test_from_pb(self): from google.cloud.proto.speech.v1 import cloud_speech_pb2 confidence = 0.625 transcript = 'this is a test transcript' alternative = cloud_speech_pb2.SpeechRecognitionAlternative( transcript=transcript, confidence=confidence) result_pb = cloud_speech_pb2.SpeechRecognitionResult( alternatives=[alternative]) result = self._get_target_class().from_pb(result_pb) self.assertEqual(result.confidence, confidence) self.assertEqual(result.transcript, transcript)