From 881abcca1d3b04a79127b9270caa7f5d9372d5d0 Mon Sep 17 00:00:00 2001 From: Thomas Schultz Date: Thu, 10 Nov 2016 12:58:42 -0500 Subject: [PATCH 1/2] Fix bug with speech streaming speech_context. --- speech/google/cloud/speech/_gax.py | 3 ++- speech/unit_tests/test__gax.py | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/speech/google/cloud/speech/_gax.py b/speech/google/cloud/speech/_gax.py index 3cad482dd53a..aa9e9aa95d58 100644 --- a/speech/google/cloud/speech/_gax.py +++ b/speech/google/cloud/speech/_gax.py @@ -329,7 +329,8 @@ def _stream_requests(sample, language_code=None, max_alternatives=None, """ config_request = _make_streaming_request( sample, language_code=language_code, max_alternatives=max_alternatives, - profanity_filter=profanity_filter, speech_context=speech_context, + profanity_filter=profanity_filter, + speech_context=SpeechContext(phrases=speech_context), single_utterance=single_utterance, interim_results=interim_results) # The config request MUST go first and not contain any audio data. diff --git a/speech/unit_tests/test__gax.py b/speech/unit_tests/test__gax.py index 31af01178613..2b208cbf553a 100644 --- a/speech/unit_tests/test__gax.py +++ b/speech/unit_tests/test__gax.py @@ -130,8 +130,6 @@ def test_stream_requests(self): from io import BytesIO from google.cloud import speech from google.cloud.speech.sample import Sample - from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( - SpeechContext) from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( StreamingRecognitionConfig) from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( @@ -143,7 +141,7 @@ def test_stream_requests(self): language_code = 'US-en' max_alternatives = 2 profanity_filter = True - speech_context = SpeechContext(phrases=self.HINTS) + speech_context = self.HINTS single_utterance = True interim_results = False streaming_requests = self._callFUT(sample, language_code, From 5fbbc1bfd2faaf508820f98754b58244ad815fe5 Mon Sep 17 00:00:00 2001 From: Thomas Schultz Date: Thu, 10 Nov 2016 13:49:01 -0500 Subject: [PATCH 2/2] Add speech_context to streaming system test. --- system_tests/speech.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system_tests/speech.py b/system_tests/speech.py index 175674dbc96b..37eb16b22e49 100644 --- a/system_tests/speech.py +++ b/system_tests/speech.py @@ -125,7 +125,8 @@ def _make_streaming_request(self, file_obj, single_utterance=True, sample_rate=16000) return client.streaming_recognize(sample, single_utterance=single_utterance, - interim_results=interim_results) + interim_results=interim_results, + speech_context=['hello', 'google']) def _check_results(self, results, num_results=1): self.assertEqual(len(results), num_results)