def _make_result(alternatives=()): from google.cloud.grpc.speech.v1beta1 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 _make_result(transcript, confidence): from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 return cloud_speech_pb2.SpeechRecognitionResult(alternatives=[ cloud_speech_pb2.SpeechRecognitionAlternative( transcript=transcript, confidence=confidence, ), ], )
def test_from_pb_with_no_confidence(self): from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 text = 'the double trouble' pb_value = cloud_speech_pb2.SpeechRecognitionAlternative( transcript=text) self.assertEqual(pb_value.confidence, 0.0) klass = self._get_target_class() alternative = klass.from_pb(pb_value) self.assertEqual(alternative.transcript, text) self.assertIsNone(alternative.confidence)
def _make_streaming_result(alternatives=(), is_final=True, stability=1.0): from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 return cloud_speech_pb2.StreamingRecognitionResult( alternatives=[ cloud_speech_pb2.SpeechRecognitionAlternative( transcript=alternative['transcript'], confidence=alternative['confidence'], ) for alternative in alternatives ], is_final=is_final, stability=stability, )