diff --git a/docs/speech-streaming.rst b/docs/speech-streaming.rst index 6fa42dbd9f79d..eab505b4d06df 100644 --- a/docs/speech-streaming.rst +++ b/docs/speech-streaming.rst @@ -1,33 +1,23 @@ -Speech StreamingResponseContainer -================================= +Streaming Speech Response +========================= -.. automodule:: google.cloud.speech.streaming.container +.. automodule:: google.cloud.speech.streaming_response :members: :undoc-members: :show-inheritance: -Speech Streaming Request helpers -================================ +Streaming Speech Result +======================= -.. automodule:: google.cloud.speech.streaming.request +.. automodule:: google.cloud.speech.streaming_result :members: :undoc-members: :show-inheritance: -Speech StreamingSpeechResponse -============================== +Streaming Endpointer Type +========================= -.. automodule:: google.cloud.speech.streaming.response - :members: - :undoc-members: - :show-inheritance: - - - -Speech StreamingSpeechResult -============================ - -.. automodule:: google.cloud.speech.streaming.result +.. automodule:: google.cloud.speech.endpointer_type :members: :undoc-members: :show-inheritance: diff --git a/docs/speech-usage.rst b/docs/speech-usage.rst index 3e1ada07b6bce..8b649fae9dce5 100644 --- a/docs/speech-usage.rst +++ b/docs/speech-usage.rst @@ -51,10 +51,9 @@ See: `Speech Asynchronous Recognize`_ >>> import time >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> sample = client.sample(source_uri='gs://my-bucket/recording.flac', - ... encoding=Encoding.LINEAR16, + ... encoding=speech.Encoding.LINEAR16, ... sample_rate=44100) >>> operation = client.async_recognize(sample, max_alternatives=2) >>> retry_count = 100 @@ -82,10 +81,9 @@ Great Britian. .. code-block:: python >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> sample = client.sample(source_uri='gs://my-bucket/recording.flac', - ... encoding=Encoding.FLAC, + ... encoding=speech.Encoding.FLAC, ... sample_rate=44100) >>> operation = client.async_recognize(sample, max_alternatives=2) >>> alternatives = client.sync_recognize( @@ -107,10 +105,9 @@ Example of using the profanity filter. .. code-block:: python >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> sample = client.sample(source_uri='gs://my-bucket/recording.flac', - ... encoding=Encoding.FLAC, + ... encoding=speech.Encoding.FLAC, ... sample_rate=44100) >>> alternatives = client.sync_recognize(sample, max_alternatives=1, ... profanity_filter=True) @@ -129,10 +126,9 @@ words to the vocabulary of the recognizer. .. code-block:: python >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> sample = client.sample(source_uri='gs://my-bucket/recording.flac', - ... encoding=Encoding.FLAC, + ... encoding=speech.Encoding.FLAC, ... sample_rate=44100) >>> hints = ['hi', 'good afternoon'] >>> alternatives = client.sync_recognize(sample, max_alternatives=2, @@ -161,12 +157,11 @@ data to possible text alternatives on the fly. >>> import io >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> with io.open('./hello.wav', 'rb') as stream: - >>> sample = client.sample(stream=stream, encoding=Encoding.LINEAR16, + ... sample = client.sample(stream=stream, encoding=speech.Encoding.LINEAR16, ... sample_rate=16000) - >>> for response in client.stream_recognize(sample): + ... for response in client.stream_recognize(sample): ... print(response.transcript) hello ... print(response.is_final) @@ -182,12 +177,11 @@ result(s) are returned. >>> import io >>> from google.cloud import speech - >>> from google.cloud.speech.encoding import Encoding >>> client = speech.Client() >>> with io.open('./hello.wav', 'rb') as stream: - >>> sample = client.sample(stream=stream, encoding=Encoding.LINEAR16, + >>> sample = client.sample(stream=stream, encoding=speech.Encoding.LINEAR16, ... sample_rate=16000) - >>> for response in client.stream_recognize(sample, + ... for response in client.stream_recognize(sample, ... interim_results=True): ... print(response.transcript) hell @@ -211,9 +205,9 @@ See: `Single Utterance`_ .. code-block:: python >>> with io.open('./hello_pause_goodbye.wav', 'rb') as stream: - >>> sample = client.sample(stream=stream, encoding=Encoding.LINEAR16, + >>> sample = client.sample(stream=stream, encoding=speech.Encoding.LINEAR16, ... sample_rate=16000) - >>> stream_container = client.stream_recognize(sample, + ... stream_container = client.stream_recognize(sample, ... single_utterance=True) >>> print(stream_container.get_full_text()) hello diff --git a/speech/google/cloud/speech/__init__.py b/speech/google/cloud/speech/__init__.py index ef55810893a76..4a9e4e4f6fc60 100644 --- a/speech/google/cloud/speech/__init__.py +++ b/speech/google/cloud/speech/__init__.py @@ -16,3 +16,4 @@ from google.cloud.speech.client import Client from google.cloud.speech.connection import Connection +from google.cloud.speech.encoding import Encoding diff --git a/speech/google/cloud/speech/client.py b/speech/google/cloud/speech/client.py index 8809b4eed5408..afb98513da380 100644 --- a/speech/google/cloud/speech/client.py +++ b/speech/google/cloud/speech/client.py @@ -24,12 +24,17 @@ from google.cloud.speech.connection import Connection from google.cloud.speech.encoding import Encoding from google.cloud.speech.operation import Operation -from google.cloud.speech.streaming.request import _make_request_stream from google.cloud.speech.sample import Sample -from google.cloud.speech.streaming.response import StreamingSpeechResponse +from google.cloud.speech.streaming_response import StreamingSpeechResponse try: from google.cloud.gapic.speech.v1beta1.speech_api import SpeechApi + from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( + RecognitionConfig) + from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( + StreamingRecognitionConfig) + from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( + StreamingRecognizeRequest) except ImportError: # pragma: NO COVER _HAVE_GAX = False else: @@ -284,16 +289,9 @@ def stream_recognize(self, sample, language_code=None, with the is_final=false flag). If false or omitted, only is_final=true result(s) are returned. - - :rtype: :class:`~streaming.StreamingResponseContainer` - :returns: An instance of ``StreamingReponseContainer``. - """ if not _USE_GAX: - raise EnvironmentError('GRPC is required to use this API.') - - if sample.stream.closed: - raise ValueError('Stream is closed.') + raise EnvironmentError('gRPC is required to use this API.') requests = _make_request_stream(sample, language_code=language_code, max_alternatives=max_alternatives, @@ -379,3 +377,168 @@ def _build_request_data(sample, language_code=None, max_alternatives=None, } return data + + +def _make_request_stream(sample, language_code=None, max_alternatives=None, + profanity_filter=None, speech_context=None, + single_utterance=None, interim_results=None): + """Generate stream of requests from sample. + + :type sample: :class:`~google.cloud.speech.sample.Sample` + :param sample: Instance of ``Sample`` containing audio information. + + :type language_code: str + :param language_code: (Optional) The language of the supplied audio as + BCP-47 language tag. Example: ``'en-GB'``. + If omitted, defaults to ``'en-US'``. + + :type max_alternatives: int + :param max_alternatives: (Optional) Maximum number of recognition + hypotheses to be returned. The server may + return fewer than maxAlternatives. + Valid values are 0-30. A value of 0 or 1 + will return a maximum of 1. Defaults to 1 + + :type profanity_filter: bool + :param profanity_filter: If True, the server will attempt to filter + out profanities, replacing all but the + initial character in each filtered word with + asterisks, e.g. ``'f***'``. If False or + omitted, profanities won't be filtered out. + + :type speech_context: list + :param speech_context: A list of strings (max 50) containing words and + phrases "hints" so that the speech recognition + is more likely to recognize them. This can be + used to improve the accuracy for specific words + and phrases. This can also be used to add new + words to the vocabulary of the recognizer. + + :type single_utterance: boolean + :param single_utterance: [Optional] If false or omitted, the recognizer + will perform continuous recognition + (continuing to process audio even if the user + pauses speaking) until the client closes the + output stream (gRPC API) or when the maximum + time limit has been reached. Multiple + SpeechRecognitionResults with the is_final + flag set to true may be returned. + + If true, the recognizer will detect a single + spoken utterance. When it detects that the + user has paused or stopped speaking, it will + return an END_OF_UTTERANCE event and cease + recognition. It will return no more than one + SpeechRecognitionResult with the is_final flag + set to true. + + :type interim_results: boolean + :param interim_results: [Optional] If true, interim results (tentative + hypotheses) may be returned as they become + available (these interim results are indicated + with the is_final=false flag). If false or + omitted, only is_final=true result(s) are + returned. + """ + config_request = _make_streaming_config( + sample, language_code=language_code, max_alternatives=max_alternatives, + profanity_filter=profanity_filter, speech_context=speech_context, + single_utterance=single_utterance, interim_results=interim_results) + + # The config request MUST go first and not contain any audio data. + yield config_request + + buff = b'' + while True: + data = sample.stream.read(sample.chunk_size) + if not data: + break + # Optimize the request data size to around 100ms. + if len(buff) + len(data) >= sample.chunk_size: + yield StreamingRecognizeRequest(audio_content=buff) + buff = data + else: + b''.join((buff, data)) + + # Clear final contents of buffer. + yield StreamingRecognizeRequest(audio_content=buff) + + +def _make_streaming_config(sample, language_code, + max_alternatives, profanity_filter, + speech_context, single_utterance, + interim_results): + """Build streaming configuration. + + :type sample: :class:`~google.cloud.speech.sample.Sample` + :param sample: Instance of ``Sample`` containing audio information. + + :type language_code: str + :param language_code: (Optional) The language of the supplied audio as + BCP-47 language tag. Example: ``'en-GB'``. + If omitted, defaults to ``'en-US'``. + + :type max_alternatives: int + :param max_alternatives: (Optional) Maximum number of recognition + hypotheses to be returned. The server may + return fewer than maxAlternatives. + Valid values are 0-30. A value of 0 or 1 + will return a maximum of 1. Defaults to 1 + + :type profanity_filter: bool + :param profanity_filter: If True, the server will attempt to filter + out profanities, replacing all but the + initial character in each filtered word with + asterisks, e.g. ``'f***'``. If False or + omitted, profanities won't be filtered out. + + :type speech_context: list + :param speech_context: A list of strings (max 50) containing words and + phrases "hints" so that the speech recognition + is more likely to recognize them. This can be + used to improve the accuracy for specific words + and phrases. This can also be used to add new + words to the vocabulary of the recognizer. + + :type single_utterance: boolean + :param single_utterance: [Optional] If false or omitted, the recognizer + will perform continuous recognition + (continuing to process audio even if the user + pauses speaking) until the client closes the + output stream (gRPC API) or when the maximum + time limit has been reached. Multiple + SpeechRecognitionResults with the is_final + flag set to true may be returned. + + If true, the recognizer will detect a single + spoken utterance. When it detects that the + user has paused or stopped speaking, it will + return an END_OF_UTTERANCE event and cease + recognition. It will return no more than one + SpeechRecognitionResult with the is_final flag + set to true. + + :type interim_results: boolean + :param interim_results: [Optional] If true, interim results (tentative + hypotheses) may be returned as they become + available (these interim results are indicated + with the is_final=false flag). If false or + omitted, only is_final=true result(s) are + returned. + + :rtype: :class:`~StreamingRecognitionConfig` + :returns: Instance of ``StreamingRecognitionConfig``. + """ + config = RecognitionConfig( + encoding=sample.encoding, sample_rate=sample.sample_rate, + language_code=language_code, max_alternatives=max_alternatives, + profanity_filter=profanity_filter, speech_context=speech_context) + + streaming_config = StreamingRecognitionConfig( + config=config, single_utterance=single_utterance, + interim_results=interim_results) + + config_request = StreamingRecognizeRequest( + streaming_config=streaming_config) + + return config_request diff --git a/speech/google/cloud/speech/streaming/__init__.py b/speech/google/cloud/speech/endpointer_type.py similarity index 100% rename from speech/google/cloud/speech/streaming/__init__.py rename to speech/google/cloud/speech/endpointer_type.py diff --git a/speech/google/cloud/speech/sample.py b/speech/google/cloud/speech/sample.py index 5b1608f80e798..fbc97adf1d0d4 100644 --- a/speech/google/cloud/speech/sample.py +++ b/speech/google/cloud/speech/sample.py @@ -52,7 +52,7 @@ class Sample(object): def __init__(self, content=None, source_uri=None, stream=None, encoding=None, sample_rate=None): - if [content, source_uri, stream].count(None) != 2: + if (content, source_uri, stream).count(None) != 2: raise ValueError('Supply only one of \'content\', \'source_uri\'' ' or stream.') diff --git a/speech/google/cloud/speech/streaming/endpointer_type.py b/speech/google/cloud/speech/streaming/endpointer_type.py deleted file mode 100644 index 987775a6a75d0..0000000000000 --- a/speech/google/cloud/speech/streaming/endpointer_type.py +++ /dev/null @@ -1,14 +0,0 @@ -class EndpointerType(object): - ENDPOINTER_EVENT_UNSPECIFIED = 0 - START_OF_SPEECH = 1 - END_OF_SPEECH = 2 - END_OF_AUDIO = 3 - END_OF_UTTERANCE = 4 - - reverse_map = { - 0: 'ENDPOINTER_EVENT_UNSPECIFIED', - 1: 'START_OF_SPEECH', - 2: 'END_OF_SPEECH', - 3: 'END_OF_AUDIO', - 4: 'END_OF_UTTERANCE' - } diff --git a/speech/google/cloud/speech/streaming/request.py b/speech/google/cloud/speech/streaming/request.py deleted file mode 100644 index 794e3f992a678..0000000000000 --- a/speech/google/cloud/speech/streaming/request.py +++ /dev/null @@ -1,183 +0,0 @@ -# Copyright 2016 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Helper to make Speech requests from IO stream""" - -from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import RecognitionConfig -from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( - StreamingRecognitionConfig) -from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( - StreamingRecognizeRequest) - - -def _make_request_stream(sample, language_code=None, max_alternatives=None, - profanity_filter=None, speech_context=None, - single_utterance=None, interim_results=None): - """Generate stream of requests from sample. - - :type sample: :class:`~google.cloud.speech.sample.Sample` - :param sample: Instance of ``Sample`` containing audio information. - - :type language_code: str - :param language_code: (Optional) The language of the supplied audio as - BCP-47 language tag. Example: ``'en-GB'``. - If omitted, defaults to ``'en-US'``. - - :type max_alternatives: int - :param max_alternatives: (Optional) Maximum number of recognition - hypotheses to be returned. The server may - return fewer than maxAlternatives. - Valid values are 0-30. A value of 0 or 1 - will return a maximum of 1. Defaults to 1 - - :type profanity_filter: bool - :param profanity_filter: If True, the server will attempt to filter - out profanities, replacing all but the - initial character in each filtered word with - asterisks, e.g. ``'f***'``. If False or - omitted, profanities won't be filtered out. - - :type speech_context: list - :param speech_context: A list of strings (max 50) containing words and - phrases "hints" so that the speech recognition - is more likely to recognize them. This can be - used to improve the accuracy for specific words - and phrases. This can also be used to add new - words to the vocabulary of the recognizer. - - :type single_utterance: boolean - :param single_utterance: [Optional] If false or omitted, the recognizer - will perform continuous recognition - (continuing to process audio even if the user - pauses speaking) until the client closes the - output stream (gRPC API) or when the maximum - time limit has been reached. Multiple - SpeechRecognitionResults with the is_final - flag set to true may be returned. - - If true, the recognizer will detect a single - spoken utterance. When it detects that the - user has paused or stopped speaking, it will - return an END_OF_UTTERANCE event and cease - recognition. It will return no more than one - SpeechRecognitionResult with the is_final flag - set to true. - - :type interim_results: boolean - :param interim_results: [Optional] If true, interim results (tentative - hypotheses) may be returned as they become - available (these interim results are indicated - with the is_final=false flag). If false or - omitted, only is_final=true result(s) are - returned. - """ - config_request = _make_streaming_config( - sample, language_code=language_code, max_alternatives=max_alternatives, - profanity_filter=profanity_filter, speech_context=speech_context, - single_utterance=single_utterance, interim_results=interim_results) - - # The config request MUST go first and not contain any audio data. - yield config_request - - buff = b'' - for data in sample.stream: - # Optimize the request data size to around 100ms. - if len(buff) + len(data) >= sample.chunk_size: - yield StreamingRecognizeRequest(audio_content=buff) - buff = data - else: - buff += data - - # Clear final contents of buffer. - yield StreamingRecognizeRequest(audio_content=buff) - - -def _make_streaming_config(sample, language_code, - max_alternatives, profanity_filter, - speech_context, single_utterance, - interim_results): - """Build streaming configuration. - - :type sample: :class:`~google.cloud.speech.sample.Sample` - :param sample: Instance of ``Sample`` containing audio information. - - :type language_code: str - :param language_code: (Optional) The language of the supplied audio as - BCP-47 language tag. Example: ``'en-GB'``. - If omitted, defaults to ``'en-US'``. - - :type max_alternatives: int - :param max_alternatives: (Optional) Maximum number of recognition - hypotheses to be returned. The server may - return fewer than maxAlternatives. - Valid values are 0-30. A value of 0 or 1 - will return a maximum of 1. Defaults to 1 - - :type profanity_filter: bool - :param profanity_filter: If True, the server will attempt to filter - out profanities, replacing all but the - initial character in each filtered word with - asterisks, e.g. ``'f***'``. If False or - omitted, profanities won't be filtered out. - - :type speech_context: list - :param speech_context: A list of strings (max 50) containing words and - phrases "hints" so that the speech recognition - is more likely to recognize them. This can be - used to improve the accuracy for specific words - and phrases. This can also be used to add new - words to the vocabulary of the recognizer. - - :type single_utterance: boolean - :param single_utterance: [Optional] If false or omitted, the recognizer - will perform continuous recognition - (continuing to process audio even if the user - pauses speaking) until the client closes the - output stream (gRPC API) or when the maximum - time limit has been reached. Multiple - SpeechRecognitionResults with the is_final - flag set to true may be returned. - - If true, the recognizer will detect a single - spoken utterance. When it detects that the - user has paused or stopped speaking, it will - return an END_OF_UTTERANCE event and cease - recognition. It will return no more than one - SpeechRecognitionResult with the is_final flag - set to true. - - :type interim_results: boolean - :param interim_results: [Optional] If true, interim results (tentative - hypotheses) may be returned as they become - available (these interim results are indicated - with the is_final=false flag). If false or - omitted, only is_final=true result(s) are - returned. - - :rtype: :class:`~StreamingRecognitionConfig` - :returns: Instance of ``StreamingRecognitionConfig``. - """ - config = RecognitionConfig( - encoding=sample.encoding, sample_rate=sample.sample_rate, - language_code=language_code, max_alternatives=max_alternatives, - profanity_filter=profanity_filter, speech_context=speech_context) - - streaming_config = StreamingRecognitionConfig( - config=config, single_utterance=single_utterance, - interim_results=interim_results) - - config_request = StreamingRecognizeRequest( - streaming_config=streaming_config) - - return config_request diff --git a/speech/google/cloud/speech/streaming/response.py b/speech/google/cloud/speech/streaming_response.py similarity index 83% rename from speech/google/cloud/speech/streaming/response.py rename to speech/google/cloud/speech/streaming_response.py index 4caf39ba186c0..55e2321f1a1d1 100644 --- a/speech/google/cloud/speech/streaming/response.py +++ b/speech/google/cloud/speech/streaming_response.py @@ -14,8 +14,7 @@ """Representation of a GAPIC Speech API response.""" -from google.cloud.speech.streaming.endpointer_type import EndpointerType -from google.cloud.speech.streaming.result import StreamingSpeechResult +from google.cloud.speech.streaming_result import StreamingSpeechResult class StreamingSpeechResponse(object): @@ -71,7 +70,7 @@ def confidence(self): :returns: Confidence score of recognized speech [0.0-1.0]. """ if self.results and self.results[0].alternatives: - return self.results[0].alternatives[0].confidence + return self.results[0].alternatives[0].confidence else: return 0.0 @@ -91,8 +90,8 @@ def is_final(self): :rtype: bool :returns: True if the result has completed it's processing. """ - if len(self.results): - return self.results[0].is_final + if self.results: + return bool(self.results[0].is_final) else: return False @@ -122,6 +121,28 @@ def transcript(self): :returns: Transcript text from response. """ if self.results and self.results[0].alternatives: - return self.results[0].alternatives[0].transcript + return self.results[0].alternatives[0].transcript else: return '' + + +class EndpointerType(object): + """Endpointer type for tracking state of Speech API detection. + + See: + https://cloud.google.com/speech/reference/rpc/\ + google.cloud.speech.v1beta1#endpointertype + """ + ENDPOINTER_EVENT_UNSPECIFIED = 0 + START_OF_SPEECH = 1 + END_OF_SPEECH = 2 + END_OF_AUDIO = 3 + END_OF_UTTERANCE = 4 + + reverse_map = { + 0: 'ENDPOINTER_EVENT_UNSPECIFIED', + 1: 'START_OF_SPEECH', + 2: 'END_OF_SPEECH', + 3: 'END_OF_AUDIO', + 4: 'END_OF_UTTERANCE' + } diff --git a/speech/google/cloud/speech/streaming/result.py b/speech/google/cloud/speech/streaming_result.py similarity index 100% rename from speech/google/cloud/speech/streaming/result.py rename to speech/google/cloud/speech/streaming_result.py diff --git a/speech/unit_tests/streaming/__init__.py b/speech/unit_tests/streaming/__init__.py deleted file mode 100644 index 58e0d91536321..0000000000000 --- a/speech/unit_tests/streaming/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2016 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/speech/unit_tests/test_client.py b/speech/unit_tests/test_client.py index 9d3176c56ba95..b9a436d1e22c7 100644 --- a/speech/unit_tests/test_client.py +++ b/speech/unit_tests/test_client.py @@ -218,23 +218,6 @@ def test_set_speech_api(self): speech_api = client.speech_api self.assertIsInstance(speech_api, _MockGAPICSpeechAPI) - def test_streaming_closed_stream(self): - from io import BytesIO - from google.cloud.speech.encoding import Encoding - - stream = BytesIO(b'Some audio data...') - credentials = _Credentials() - client = self._makeOne(credentials=credentials) - client.connection = _Connection() - client._speech_api = _MockGAPICSpeechAPI() - - stream.close() - sample = client.sample(stream=stream, - encoding=Encoding.LINEAR16, - sample_rate=self.SAMPLE_RATE) - with self.assertRaises(ValueError): - next(client.stream_recognize(sample)) - def test_streaming_with_empty_response(self): from io import BytesIO from google.cloud.speech.encoding import Encoding @@ -256,7 +239,7 @@ def test_streaming_with_empty_response(self): def test_stream_recognize(self): from io import BytesIO from google.cloud.speech.encoding import Encoding - from google.cloud.speech.streaming.response import ( + from google.cloud.speech.streaming_response import ( StreamingSpeechResponse) stream = BytesIO(b'Some audio data...') diff --git a/speech/unit_tests/streaming/test_request.py b/speech/unit_tests/test_request.py similarity index 87% rename from speech/unit_tests/streaming/test_request.py rename to speech/unit_tests/test_request.py index 798a13b0acd34..86e761fecf529 100644 --- a/speech/unit_tests/streaming/test_request.py +++ b/speech/unit_tests/test_request.py @@ -20,7 +20,7 @@ def test_make_request_stream(self): from io import BytesIO from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( StreamingRecognizeRequest) - from google.cloud.speech.streaming.request import _make_request_stream + from google.cloud.speech.client import _make_request_stream from google.cloud.speech.sample import Sample stream = BytesIO(b'g' * 1702) # Something bigger than a chunk. @@ -30,13 +30,13 @@ def test_make_request_stream(self): for req in _make_request_stream(sample): request_count += 1 self.assertIsInstance(req, StreamingRecognizeRequest) - self.assertEqual(request_count, 3) + self.assertEqual(request_count, 4) def test_make_request_stream_short(self): from io import BytesIO from google.cloud.grpc.speech.v1beta1.cloud_speech_pb2 import ( StreamingRecognizeRequest) - from google.cloud.speech.streaming.request import _make_request_stream + from google.cloud.speech.client import _make_request_stream from google.cloud.speech.sample import Sample stream = BytesIO(b'g' * (1599 * 2)) # Something bigger than a chunk. @@ -47,4 +47,4 @@ def test_make_request_stream_short(self): request_count += 1 self.assertIsInstance(req, StreamingRecognizeRequest) - self.assertEqual(request_count, 3) + self.assertEqual(request_count, 4) diff --git a/speech/unit_tests/streaming/test_response.py b/speech/unit_tests/test_response.py similarity index 96% rename from speech/unit_tests/streaming/test_response.py rename to speech/unit_tests/test_response.py index d2a695d3f14d2..413aa6b728715 100644 --- a/speech/unit_tests/streaming/test_response.py +++ b/speech/unit_tests/test_response.py @@ -17,7 +17,7 @@ class TestStreamingSpeechResponse(unittest.TestCase): def _getTargetClass(self): - from google.cloud.speech.streaming.response import ( + from google.cloud.speech.streaming_response import ( StreamingSpeechResponse) return StreamingSpeechResponse