From 5ff00b1a8f0516b551bb10f67f7d6ed394834651 Mon Sep 17 00:00:00 2001 From: Thea Flowers Date: Fri, 29 Jun 2018 11:27:11 -0700 Subject: [PATCH 1/2] Write synthesis script, regenerate library --- speech/README.rst | 113 +++++-- speech/docs/gapic/v1/api.rst | 6 + speech/docs/gapic/v1/types.rst | 5 + speech/docs/gapic/v1p1beta1/api.rst | 6 + speech/docs/gapic/v1p1beta1/types.rst | 5 + speech/docs/index.rst | 108 ++++++ speech/google/cloud/speech_v1/gapic/enums.py | 6 +- .../cloud/speech_v1/gapic/speech_client.py | 165 ++++++---- .../speech_v1/gapic/speech_client_config.py | 10 +- .../speech_v1/gapic/transports/__init__.py | 0 .../gapic/transports/speech_grpc_transport.py | 140 ++++++++ speech/google/cloud/speech_v1/helpers.py | 2 +- .../cloud/speech_v1/proto/cloud_speech_pb2.py | 311 +++++------------- .../speech_v1/proto/cloud_speech_pb2_grpc.py | 4 +- speech/google/cloud/speech_v1/types.py | 8 +- .../cloud/speech_v1p1beta1/gapic/enums.py | 14 +- .../speech_v1p1beta1/gapic/speech_client.py | 163 +++++---- .../gapic/transports/__init__.py | 0 .../gapic/transports/speech_grpc_transport.py | 140 ++++++++ .../proto/cloud_speech_pb2.py | 264 ++++++++++++--- speech/google/cloud/speech_v1p1beta1/types.py | 8 +- speech/synth.py | 86 +++++ speech/tests/unit/gapic/v1/test_helpers.py | 71 ---- .../unit/gapic/v1/test_speech_client_v1.py | 6 +- .../v1p1beta1/test_speech_client_v1p1beta1.py | 6 +- speech/tests/unit/test_helpers.py | 53 +++ 26 files changed, 1146 insertions(+), 554 deletions(-) create mode 100644 speech/docs/gapic/v1/api.rst create mode 100644 speech/docs/gapic/v1/types.rst create mode 100644 speech/docs/gapic/v1p1beta1/api.rst create mode 100644 speech/docs/gapic/v1p1beta1/types.rst create mode 100644 speech/docs/index.rst create mode 100644 speech/google/cloud/speech_v1/gapic/transports/__init__.py create mode 100644 speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py create mode 100644 speech/google/cloud/speech_v1p1beta1/gapic/transports/__init__.py create mode 100644 speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py create mode 100644 speech/synth.py delete mode 100644 speech/tests/unit/gapic/v1/test_helpers.py create mode 100644 speech/tests/unit/test_helpers.py diff --git a/speech/README.rst b/speech/README.rst index 4497e1e5f7b4..d4d185bc780f 100644 --- a/speech/README.rst +++ b/speech/README.rst @@ -1,54 +1,97 @@ -Python Client for Google Cloud Speech -===================================== +Python Client for Google Cloud Speech API (`Beta`_) +==================================================== - Python idiomatic client for `Google Cloud Speech`_ +`Google Cloud Speech API`_: Google Cloud Speech API. -.. _Google Cloud Speech: https://cloud.google.com/speech/ +- `Client Library Documentation`_ +- `Product Documentation`_ -|pypi| |versions| - -- `Documentation`_ - -.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/speech/ +.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Google Cloud Speech API: https://cloud.google.com/speech +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html +.. _Product Documentation: https://cloud.google.com/speech Quick Start ----------- +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the Google Cloud Speech API.`_ +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the Google Cloud Speech API.: https://cloud.google.com/speech +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install google-cloud-speech + + +Windows +^^^^^^^ + .. code-block:: console - $ pip install --upgrade google-cloud-speech + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install google-cloud-speech -For more information on setting up your Python development environment, -such as installing ``pip`` and ``virtualenv`` on your system, please refer -to `Python Development Environment Setup Guide`_ for Google Cloud Platform. +Preview +~~~~~~~ -.. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup +SpeechClient +^^^^^^^^^^^^ -Authentication --------------- +.. code:: py -With ``google-cloud-python`` we try to make authentication as painless as -possible. Check out the `Authentication section`_ in our documentation to -learn more. You may also find the `authentication document`_ shared by all -the ``google-cloud-*`` libraries to be helpful. + from google.cloud import speech_v1 + from google.cloud.speech_v1 import enums -.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html -.. _authentication document: https://github.com/GoogleCloudPlatform/google-cloud-common/tree/master/authentication + client = speech_v1.SpeechClient() -Using the API -------------- + encoding = enums.RecognitionConfig.AudioEncoding.FLAC + sample_rate_hertz = 44100 + language_code = 'en-US' + config = {'encoding': encoding, 'sample_rate_hertz': sample_rate_hertz, 'language_code': language_code} + uri = 'gs://bucket_name/file_name.flac' + audio = {'uri': uri} -`Cloud Speech API`_ enables easy integration of Google speech -recognition technologies into developer applications. Send audio -and receive a text transcription from the Cloud Speech API service. + response = client.recognize(config, audio) -.. _Cloud Speech API: https://cloud.google.com/speech/ +Next Steps +~~~~~~~~~~ -See the ``google-cloud-python`` API `speech documentation`_ to learn how to -connect to the Google Cloud Speech API using this Client Library. +- Read the `Client Library Documentation`_ for Google Cloud Speech API + API to see other available methods on the client. +- Read the `Google Cloud Speech API Product documentation`_ to learn + more about the product and see How-to Guides. +- View this `repository’s main README`_ to see the full list of Cloud + APIs that we cover. -.. _speech documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/speech/ -.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-speech.svg - :target: https://pypi.org/project/google-cloud-speech/ -.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-speech.svg - :target: https://pypi.org/project/google-cloud-speech/ +.. _Google Cloud Speech API Product documentation: https://cloud.google.com/speech +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst \ No newline at end of file diff --git a/speech/docs/gapic/v1/api.rst b/speech/docs/gapic/v1/api.rst new file mode 100644 index 000000000000..03ceab7b77c7 --- /dev/null +++ b/speech/docs/gapic/v1/api.rst @@ -0,0 +1,6 @@ +Client for Google Cloud Speech API +================================== + +.. automodule:: google.cloud.speech_v1 + :members: + :inherited-members: \ No newline at end of file diff --git a/speech/docs/gapic/v1/types.rst b/speech/docs/gapic/v1/types.rst new file mode 100644 index 000000000000..a403d5a4aa3d --- /dev/null +++ b/speech/docs/gapic/v1/types.rst @@ -0,0 +1,5 @@ +Types for Google Cloud Speech API Client +======================================== + +.. automodule:: google.cloud.speech_v1.types + :members: \ No newline at end of file diff --git a/speech/docs/gapic/v1p1beta1/api.rst b/speech/docs/gapic/v1p1beta1/api.rst new file mode 100644 index 000000000000..4779930fdd9e --- /dev/null +++ b/speech/docs/gapic/v1p1beta1/api.rst @@ -0,0 +1,6 @@ +Client for Cloud Speech API +=========================== + +.. automodule:: google.cloud.speech_v1p1beta1 + :members: + :inherited-members: \ No newline at end of file diff --git a/speech/docs/gapic/v1p1beta1/types.rst b/speech/docs/gapic/v1p1beta1/types.rst new file mode 100644 index 000000000000..ce33f105e230 --- /dev/null +++ b/speech/docs/gapic/v1p1beta1/types.rst @@ -0,0 +1,5 @@ +Types for Cloud Speech API Client +================================= + +.. automodule:: google.cloud.speech_v1p1beta1.types + :members: \ No newline at end of file diff --git a/speech/docs/index.rst b/speech/docs/index.rst new file mode 100644 index 000000000000..97951fd381a9 --- /dev/null +++ b/speech/docs/index.rst @@ -0,0 +1,108 @@ +Python Client for Google Cloud Speech API (`Beta`_) +==================================================== + +`Google Cloud Speech API`_: Google Cloud Speech API. + +- `Client Library Documentation`_ +- `Product Documentation`_ + +.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Google Cloud Speech API: https://cloud.google.com/speech +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html +.. _Product Documentation: https://cloud.google.com/speech + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the Google Cloud Speech API.`_ +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the Google Cloud Speech API.: https://cloud.google.com/speech +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install google-cloud-speech + + +Windows +^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install google-cloud-speech + +Preview +~~~~~~~ + +SpeechClient +^^^^^^^^^^^^ + +.. code:: py + + from google.cloud import speech_v1 + from google.cloud.speech_v1 import enums + + client = speech_v1.SpeechClient() + + encoding = enums.RecognitionConfig.AudioEncoding.FLAC + sample_rate_hertz = 44100 + language_code = 'en-US' + config = {'encoding': encoding, 'sample_rate_hertz': sample_rate_hertz, 'language_code': language_code} + uri = 'gs://bucket_name/file_name.flac' + audio = {'uri': uri} + + response = client.recognize(config, audio) + +Next Steps +~~~~~~~~~~ + +- Read the `Client Library Documentation`_ for Google Cloud Speech API + API to see other available methods on the client. +- Read the `Google Cloud Speech API Product documentation`_ to learn + more about the product and see How-to Guides. +- View this `repository’s main README`_ to see the full list of Cloud + APIs that we cover. + +.. _Google Cloud Speech API Product documentation: https://cloud.google.com/speech +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst + +Api Reference +------------- +.. toctree:: + :maxdepth: 2 + + gapic/v1/api + gapic/v1/types + gapic/v1p1beta1/api + gapic/v1p1beta1/types + changelog diff --git a/speech/google/cloud/speech_v1/gapic/enums.py b/speech/google/cloud/speech_v1/gapic/enums.py index ff9b829fac28..225fbc8dcf05 100644 --- a/speech/google/cloud/speech_v1/gapic/enums.py +++ b/speech/google/cloud/speech_v1/gapic/enums.py @@ -13,9 +13,11 @@ # limitations under the License. """Wrappers for protocol buffer enum types.""" +import enum + class RecognitionConfig(object): - class AudioEncoding(object): + class AudioEncoding(enum.IntEnum): """ Audio encoding of the data sent in the audio message. All encodings support only 1 channel (mono) audio. Only ``FLAC`` and ``WAV`` include a header that @@ -68,7 +70,7 @@ class AudioEncoding(object): class StreamingRecognizeResponse(object): - class SpeechEventType(object): + class SpeechEventType(enum.IntEnum): """ Indicates the type of speech event. diff --git a/speech/google/cloud/speech_v1/gapic/speech_client.py b/speech/google/cloud/speech_v1/gapic/speech_client.py index 6640957b26e1..d2315011bcaa 100644 --- a/speech/google/cloud/speech_v1/gapic/speech_client.py +++ b/speech/google/cloud/speech_v1/gapic/speech_client.py @@ -14,6 +14,7 @@ """Accesses the google.cloud.speech.v1 Speech API.""" import pkg_resources +import warnings import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config @@ -22,10 +23,14 @@ import google.api_core.operation import google.api_core.operations_v1 import google.api_core.protobuf_helpers +import grpc from google.cloud.speech_v1.gapic import enums from google.cloud.speech_v1.gapic import speech_client_config +from google.cloud.speech_v1.gapic.transports import speech_grpc_transport from google.cloud.speech_v1.proto import cloud_speech_pb2 +from google.cloud.speech_v1.proto import cloud_speech_pb2_grpc +from google.longrunning import operations_pb2 _GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( 'google-cloud-speech', ).version @@ -37,15 +42,12 @@ class SpeechClient(object): SERVICE_ADDRESS = 'speech.googleapis.com:443' """The default address of the service.""" - # The scopes needed to make gRPC calls to all of the methods defined in - # this service - _DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) - - # The name of the interface for this client. This is the key used to find - # method configuration in the client_config dictionary. + # The name of the interface for this client. This is the key used to + # find the method configuration in the client_config dictionary. _INTERFACE_NAME = 'google.cloud.speech.v1.Speech' def __init__(self, + transport=None, channel=None, credentials=None, client_config=speech_client_config.config, @@ -53,79 +55,81 @@ def __init__(self, """Constructor. Args: - channel (grpc.Channel): A ``Channel`` instance through - which to make calls. This argument is mutually exclusive + transport (Union[~.SpeechGrpcTransport, + Callable[[~.Credentials, type], ~.SpeechGrpcTransport]): A transport + instance, responsible for actually making the API calls. + The default transport uses the gRPC protocol. + This argument may also be a callable which returns a + transport instance. Callables will be sent the credentials + as the first argument and the default transport class as + the second argument. + channel (grpc.Channel): DEPRECATED. A ``Channel`` instance + through which to make calls. This argument is mutually exclusive with ``credentials``; providing both will raise an exception. credentials (google.auth.credentials.Credentials): The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. - client_config (dict): A dictionary of call options for each - method. If not specified, the default configuration is used. + This argument is mutually exclusive with providing a + transport instance to ``transport``; doing so will raise + an exception. + client_config (dict): DEPRECATED. A dictionary of call options for + each method. If not specified, the default configuration is used. client_info (google.api_core.gapic_v1.client_info.ClientInfo): The client info used to send a user-agent string along with API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. """ - # If both `channel` and `credentials` are specified, raise an - # exception (channels come with credentials baked in already). - if channel is not None and credentials is not None: - raise ValueError( - 'The `channel` and `credentials` arguments to {} are mutually ' - 'exclusive.'.format(self.__class__.__name__), ) - - # Create the channel. - if channel is None: - channel = google.api_core.grpc_helpers.create_channel( - self.SERVICE_ADDRESS, - credentials=credentials, - scopes=self._DEFAULT_SCOPES, - ) - - # Create the gRPC stubs. - self.speech_stub = (cloud_speech_pb2.SpeechStub(channel)) - - # Operations client for methods that return long-running operations - # futures. - self.operations_client = ( - google.api_core.operations_v1.OperationsClient(channel)) + # Raise deprecation warnings for things we want to go away. + if client_config: + warnings.warn('The `client_config` argument is deprecated.', + PendingDeprecationWarning) + if channel: + warnings.warn( + 'The `channel` argument is deprecated; use ' + '`transport` instead.', PendingDeprecationWarning) + + # Instantiate the transport. + # The transport is responsible for handling serialization and + # deserialization and actually sending data to the service. + if transport: + if callable(transport): + self.transport = transport( + credentials=credentials, + default_class=speech_grpc_transport.SpeechGrpcTransport, + ) + else: + if credentials: + raise ValueError( + 'Received both a transport instance and ' + 'credentials; these are mutually exclusive.') + self.transport = transport + self.transport = speech_grpc_transport.SpeechGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, + credentials=credentials, + ) if client_info is None: client_info = ( google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO) client_info.gapic_version = _GAPIC_LIBRARY_VERSION + self._client_info = client_info # Parse out the default settings for retry and timeout for each RPC # from the client configuration. # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) - method_configs = google.api_core.gapic_v1.config.parse_method_configs( + self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( client_config['interfaces'][self._INTERFACE_NAME], ) - # Write the "inner API call" methods to the class. - # These are wrapped versions of the gRPC stub methods, with retry and - # timeout configuration applied, called by the public methods on - # this class. - self._recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.Recognize, - default_retry=method_configs['Recognize'].retry, - default_timeout=method_configs['Recognize'].timeout, - client_info=client_info, - ) - self._long_running_recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.LongRunningRecognize, - default_retry=method_configs['LongRunningRecognize'].retry, - default_timeout=method_configs['LongRunningRecognize'].timeout, - client_info=client_info, - ) - self._streaming_recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.StreamingRecognize, - default_retry=method_configs['StreamingRecognize'].retry, - default_timeout=method_configs['StreamingRecognize'].timeout, - client_info=client_info, - ) + # Save a dictionary of cached API call functions. + # These are the actual callables which invoke the proper + # transport methods, wrapped with `wrap_method` to add retry, + # timeout, and the like. + self._inner_api_calls = {} # Service calls def recognize(self, @@ -180,14 +184,21 @@ def recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.recognize, + default_retry=self._method_configs['Recognize'].retry, + default_timeout=self._method_configs['Recognize'].timeout, + client_info=self._client_info, + ) + request = cloud_speech_pb2.RecognizeRequest( config=config, audio=audio, ) - return self._recognize( + return self._inner_api_calls['recognize']( request, retry=retry, timeout=timeout, metadata=metadata) def long_running_recognize(self, @@ -253,18 +264,27 @@ def long_running_recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'long_running_recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'long_running_recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.long_running_recognize, + default_retry=self._method_configs['LongRunningRecognize'] + .retry, + default_timeout=self._method_configs[ + 'LongRunningRecognize'].timeout, + client_info=self._client_info, + ) + request = cloud_speech_pb2.LongRunningRecognizeRequest( config=config, audio=audio, ) - operation = self._long_running_recognize( + operation = self._inner_api_calls['long_running_recognize']( request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, - self.operations_client, + self.transport._operations_client, cloud_speech_pb2.LongRunningRecognizeResponse, metadata_type=cloud_speech_pb2.LongRunningRecognizeMetadata, ) @@ -314,8 +334,17 @@ def streaming_recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) - return self._streaming_recognize( + # Wrap the transport method to add retry and timeout logic. + if 'streaming_recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'streaming_recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.streaming_recognize, + default_retry=self._method_configs[ + 'StreamingRecognize'].retry, + default_timeout=self._method_configs['StreamingRecognize'] + .timeout, + client_info=self._client_info, + ) + + return self._inner_api_calls['streaming_recognize']( requests, retry=retry, timeout=timeout, metadata=metadata) diff --git a/speech/google/cloud/speech_v1/gapic/speech_client_config.py b/speech/google/cloud/speech_v1/gapic/speech_client_config.py index 7d6138694011..4d64fa62132c 100644 --- a/speech/google/cloud/speech_v1/gapic/speech_client_config.py +++ b/speech/google/cloud/speech_v1/gapic/speech_client_config.py @@ -10,15 +10,15 @@ "initial_retry_delay_millis": 100, "retry_delay_multiplier": 1.3, "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 190000, + "initial_rpc_timeout_millis": 1000000, "rpc_timeout_multiplier": 1.0, - "max_rpc_timeout_millis": 190000, - "total_timeout_millis": 600000 + "max_rpc_timeout_millis": 1000000, + "total_timeout_millis": 5000000 } }, "methods": { "Recognize": { - "timeout_millis": 190000, + "timeout_millis": 1000000, "retry_codes_name": "idempotent", "retry_params_name": "default" }, @@ -28,7 +28,7 @@ "retry_params_name": "default" }, "StreamingRecognize": { - "timeout_millis": 190000, + "timeout_millis": 1000000, "retry_codes_name": "idempotent", "retry_params_name": "default" } diff --git a/speech/google/cloud/speech_v1/gapic/transports/__init__.py b/speech/google/cloud/speech_v1/gapic/transports/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py b/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py new file mode 100644 index 000000000000..107b64c2ee5f --- /dev/null +++ b/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py @@ -0,0 +1,140 @@ +# Copyright 2018 Google LLC +# +# 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 +# +# https://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. + +import google.api_core.grpc_helpers +import google.api_core.operations_v1 + +from google.cloud.speech_v1.proto import cloud_speech_pb2_grpc + + +class SpeechGrpcTransport(object): + """gRPC transport class providing stubs for + google.cloud.speech.v1 Speech API. + + The transport provides access to the raw gRPC stubs, + which can be used to take advantage of advanced + features of gRPC. + """ + # The scopes needed to make gRPC calls to all of the methods defined + # in this service. + _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + + def __init__(self, + channel=None, + credentials=None, + address='speech.googleapis.com:443'): + """Instantiate the transport class. + + Args: + channel (grpc.Channel): A ``Channel`` instance through + which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + address (str): The address where the service is hosted. + """ + # If both `channel` and `credentials` are specified, raise an + # exception (channels come with credentials baked in already). + if channel is not None and credentials is not None: + raise ValueError( + 'The `channel` and `credentials` arguments are mutually ' + 'exclusive.', ) + + # Create the channel. + if channel is None: + channel = self.create_channel( + address=address, + credentials=credentials, + ) + + # gRPC uses objects called "stubs" that are bound to the + # channel and provide a basic method for each RPC. + self._stubs = { + 'speech_stub': cloud_speech_pb2_grpc.SpeechStub(channel), + } + + # Because this API includes a method that returns a + # long-running operation (proto: google.longrunning.Operation), + # instantiate an LRO client. + self._operations_client = google.api_core.operations_v1.OperationsClient(channel) + + @classmethod + def create_channel(cls, + address='speech.googleapis.com:443', + credentials=None): + """Create and return a gRPC channel object. + + Args: + address (str): The host for the channel to use. + credentials (~.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return google.api_core.grpc_helpers.create_channel( + address, + credentials=credentials, + scopes=cls._OAUTH_SCOPES, + ) + + @property + def recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs synchronous speech recognition: receive results after all audio + has been sent and processed. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].Recognize + + @property + def long_running_recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs asynchronous speech recognition: receive results via the + google.longrunning.Operations interface. Returns either an + ``Operation.error`` or an ``Operation.response`` which contains + a ``LongRunningRecognizeResponse`` message. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].LongRunningRecognize + + @property + def streaming_recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs bidirectional streaming speech recognition: receive results while + sending audio. This method is only available via the gRPC API (not REST). + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].StreamingRecognize diff --git a/speech/google/cloud/speech_v1/helpers.py b/speech/google/cloud/speech_v1/helpers.py index 8e910eac1c90..cee59ba052c5 100644 --- a/speech/google/cloud/speech_v1/helpers.py +++ b/speech/google/cloud/speech_v1/helpers.py @@ -73,7 +73,7 @@ def streaming_recognize( :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ - return self._streaming_recognize( + return super(SpeechHelpers, self).streaming_recognize( self._streaming_request_iterable(config, requests), retry=retry, timeout=timeout ) diff --git a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py index 25aa3da7d15d..e9a3eb47aee6 100644 --- a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py +++ b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py @@ -28,7 +28,6 @@ serialized_pb=_b('\n/google/cloud/speech_v1/proto/cloud_speech.proto\x12\x16google.cloud.speech.v1\x1a\x1cgoogle/api/annotations.proto\x1a#google/longrunning/operations.proto\x1a\x19google/protobuf/any.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\x86\x01\n\x10RecognizeRequest\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x37\n\x05\x61udio\x18\x02 \x01(\x0b\x32(.google.cloud.speech.v1.RecognitionAudio\"\x91\x01\n\x1bLongRunningRecognizeRequest\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x37\n\x05\x61udio\x18\x02 \x01(\x0b\x32(.google.cloud.speech.v1.RecognitionAudio\"\x99\x01\n\x19StreamingRecognizeRequest\x12N\n\x10streaming_config\x18\x01 \x01(\x0b\x32\x32.google.cloud.speech.v1.StreamingRecognitionConfigH\x00\x12\x17\n\raudio_content\x18\x02 \x01(\x0cH\x00\x42\x13\n\x11streaming_request\"\x8a\x01\n\x1aStreamingRecognitionConfig\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x18\n\x10single_utterance\x18\x02 \x01(\x08\x12\x17\n\x0finterim_results\x18\x03 \x01(\x08\"\xb4\x03\n\x11RecognitionConfig\x12I\n\x08\x65ncoding\x18\x01 \x01(\x0e\x32\x37.google.cloud.speech.v1.RecognitionConfig.AudioEncoding\x12\x19\n\x11sample_rate_hertz\x18\x02 \x01(\x05\x12\x15\n\rlanguage_code\x18\x03 \x01(\t\x12\x18\n\x10max_alternatives\x18\x04 \x01(\x05\x12\x18\n\x10profanity_filter\x18\x05 \x01(\x08\x12>\n\x0fspeech_contexts\x18\x06 \x03(\x0b\x32%.google.cloud.speech.v1.SpeechContext\x12 \n\x18\x65nable_word_time_offsets\x18\x08 \x01(\x08\"\x8b\x01\n\rAudioEncoding\x12\x18\n\x14\x45NCODING_UNSPECIFIED\x10\x00\x12\x0c\n\x08LINEAR16\x10\x01\x12\x08\n\x04\x46LAC\x10\x02\x12\t\n\x05MULAW\x10\x03\x12\x07\n\x03\x41MR\x10\x04\x12\n\n\x06\x41MR_WB\x10\x05\x12\x0c\n\x08OGG_OPUS\x10\x06\x12\x1a\n\x16SPEEX_WITH_HEADER_BYTE\x10\x07\" \n\rSpeechContext\x12\x0f\n\x07phrases\x18\x01 \x03(\t\"D\n\x10RecognitionAudio\x12\x11\n\x07\x63ontent\x18\x01 \x01(\x0cH\x00\x12\r\n\x03uri\x18\x02 \x01(\tH\x00\x42\x0e\n\x0c\x61udio_source\"U\n\x11RecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"`\n\x1cLongRunningRecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"\x9e\x01\n\x1cLongRunningRecognizeMetadata\x12\x18\n\x10progress_percent\x18\x01 \x01(\x05\x12.\n\nstart_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x10last_update_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xb1\x02\n\x1aStreamingRecognizeResponse\x12!\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12\x43\n\x07results\x18\x02 \x03(\x0b\x32\x32.google.cloud.speech.v1.StreamingRecognitionResult\x12]\n\x11speech_event_type\x18\x04 \x01(\x0e\x32\x42.google.cloud.speech.v1.StreamingRecognizeResponse.SpeechEventType\"L\n\x0fSpeechEventType\x12\x1c\n\x18SPEECH_EVENT_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x45ND_OF_SINGLE_UTTERANCE\x10\x01\"\x8d\x01\n\x1aStreamingRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\x12\x10\n\x08is_final\x18\x02 \x01(\x08\x12\x11\n\tstability\x18\x03 \x01(\x02\"e\n\x17SpeechRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\"w\n\x1cSpeechRecognitionAlternative\x12\x12\n\ntranscript\x18\x01 \x01(\t\x12\x12\n\nconfidence\x18\x02 \x01(\x02\x12/\n\x05words\x18\x03 \x03(\x0b\x32 .google.cloud.speech.v1.WordInfo\"t\n\x08WordInfo\x12-\n\nstart_time\x18\x01 \x01(\x0b\x32\x19.google.protobuf.Duration\x12+\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04word\x18\x03 \x01(\t2\xa6\x03\n\x06Speech\x12\x81\x01\n\tRecognize\x12(.google.cloud.speech.v1.RecognizeRequest\x1a).google.cloud.speech.v1.RecognizeResponse\"\x1f\x82\xd3\xe4\x93\x02\x19\"\x14/v1/speech:recognize:\x01*\x12\x96\x01\n\x14LongRunningRecognize\x12\x33.google.cloud.speech.v1.LongRunningRecognizeRequest\x1a\x1d.google.longrunning.Operation\"*\x82\xd3\xe4\x93\x02$\"\x1f/v1/speech:longrunningrecognize:\x01*\x12\x7f\n\x12StreamingRecognize\x12\x31.google.cloud.speech.v1.StreamingRecognizeRequest\x1a\x32.google.cloud.speech.v1.StreamingRecognizeResponse(\x01\x30\x01\x42l\n\x1a\x63om.google.cloud.speech.v1B\x0bSpeechProtoP\x01Z=0.15.0.""" - """Service that implements Google Cloud Speech API. - """ - def Recognize(self, request, context): - """Performs synchronous speech recognition: receive results after all audio - has been sent and processed. - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def LongRunningRecognize(self, request, context): - """Performs asynchronous speech recognition: receive results via the - google.longrunning.Operations interface. Returns either an - `Operation.error` or an `Operation.response` which contains - a `LongRunningRecognizeResponse` message. - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def StreamingRecognize(self, request_iterator, context): - """Performs bidirectional streaming speech recognition: receive results while - sending audio. This method is only available via the gRPC API (not REST). - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - - - class BetaSpeechStub(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """Service that implements Google Cloud Speech API. - """ - def Recognize(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """Performs synchronous speech recognition: receive results after all audio - has been sent and processed. - """ - raise NotImplementedError() - Recognize.future = None - def LongRunningRecognize(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """Performs asynchronous speech recognition: receive results via the - google.longrunning.Operations interface. Returns either an - `Operation.error` or an `Operation.response` which contains - a `LongRunningRecognizeResponse` message. - """ - raise NotImplementedError() - LongRunningRecognize.future = None - def StreamingRecognize(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None): - """Performs bidirectional streaming speech recognition: receive results while - sending audio. This method is only available via the gRPC API (not REST). - """ - raise NotImplementedError() - - - def beta_create_Speech_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_deserializers = { - ('google.cloud.speech.v1.Speech', 'LongRunningRecognize'): LongRunningRecognizeRequest.FromString, - ('google.cloud.speech.v1.Speech', 'Recognize'): RecognizeRequest.FromString, - ('google.cloud.speech.v1.Speech', 'StreamingRecognize'): StreamingRecognizeRequest.FromString, - } - response_serializers = { - ('google.cloud.speech.v1.Speech', 'LongRunningRecognize'): google_dot_longrunning_dot_operations__pb2.Operation.SerializeToString, - ('google.cloud.speech.v1.Speech', 'Recognize'): RecognizeResponse.SerializeToString, - ('google.cloud.speech.v1.Speech', 'StreamingRecognize'): StreamingRecognizeResponse.SerializeToString, - } - method_implementations = { - ('google.cloud.speech.v1.Speech', 'LongRunningRecognize'): face_utilities.unary_unary_inline(servicer.LongRunningRecognize), - ('google.cloud.speech.v1.Speech', 'Recognize'): face_utilities.unary_unary_inline(servicer.Recognize), - ('google.cloud.speech.v1.Speech', 'StreamingRecognize'): face_utilities.stream_stream_inline(servicer.StreamingRecognize), - } - server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) - return beta_implementations.server(method_implementations, options=server_options) - - - def beta_create_Speech_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_serializers = { - ('google.cloud.speech.v1.Speech', 'LongRunningRecognize'): LongRunningRecognizeRequest.SerializeToString, - ('google.cloud.speech.v1.Speech', 'Recognize'): RecognizeRequest.SerializeToString, - ('google.cloud.speech.v1.Speech', 'StreamingRecognize'): StreamingRecognizeRequest.SerializeToString, - } - response_deserializers = { - ('google.cloud.speech.v1.Speech', 'LongRunningRecognize'): google_dot_longrunning_dot_operations__pb2.Operation.FromString, - ('google.cloud.speech.v1.Speech', 'Recognize'): RecognizeResponse.FromString, - ('google.cloud.speech.v1.Speech', 'StreamingRecognize'): StreamingRecognizeResponse.FromString, - } - cardinalities = { - 'LongRunningRecognize': cardinality.Cardinality.UNARY_UNARY, - 'Recognize': cardinality.Cardinality.UNARY_UNARY, - 'StreamingRecognize': cardinality.Cardinality.STREAM_STREAM, - } - stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) - return beta_implementations.dynamic_stub(channel, 'google.cloud.speech.v1.Speech', cardinalities, options=stub_options) -except ImportError: - pass # @@protoc_insertion_point(module_scope) diff --git a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2_grpc.py b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2_grpc.py index 668215cc9deb..06b2e1b089b3 100644 --- a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2_grpc.py +++ b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2_grpc.py @@ -1,8 +1,8 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc -import google.cloud.speech_v1.proto.cloud_speech_pb2 as google_dot_cloud_dot_speech__v1_dot_proto_dot_cloud__speech__pb2 -import google.longrunning.operations_pb2 as google_dot_longrunning_dot_operations__pb2 +from google.cloud.speech_v1.proto import cloud_speech_pb2 as google_dot_cloud_dot_speech__v1_dot_proto_dot_cloud__speech__pb2 +from google.longrunning import operations_pb2 as google_dot_longrunning_dot_operations__pb2 class SpeechStub(object): diff --git a/speech/google/cloud/speech_v1/types.py b/speech/google/cloud/speech_v1/types.py index 414d4d91ad60..78a660a3fc4a 100644 --- a/speech/google/cloud/speech_v1/types.py +++ b/speech/google/cloud/speech_v1/types.py @@ -15,7 +15,10 @@ from __future__ import absolute_import import sys +from google.api_core.protobuf_helpers import get_messages + from google.api import http_pb2 +from google.cloud.speech_v1.proto import cloud_speech_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -24,10 +27,6 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 -from google.api_core.protobuf_helpers import get_messages -from google.cloud.speech_v1.proto import cloud_speech_pb2 - - _shared_modules = [ http_pb2, operations_pb2, @@ -49,7 +48,6 @@ for name, message in get_messages(module).items(): setattr(sys.modules[__name__], name, message) names.append(name) - for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.speech_v1.types' diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/enums.py b/speech/google/cloud/speech_v1p1beta1/gapic/enums.py index 52a68458239d..7fe2c8f69459 100644 --- a/speech/google/cloud/speech_v1p1beta1/gapic/enums.py +++ b/speech/google/cloud/speech_v1p1beta1/gapic/enums.py @@ -13,9 +13,11 @@ # limitations under the License. """Wrappers for protocol buffer enum types.""" +import enum + class RecognitionConfig(object): - class AudioEncoding(object): + class AudioEncoding(enum.IntEnum): """ The encoding of the audio data sent in the request. @@ -78,7 +80,7 @@ class AudioEncoding(object): class RecognitionMetadata(object): - class InteractionType(object): + class InteractionType(enum.IntEnum): """ Use case categories that the audio recognition request can be described by. @@ -111,7 +113,7 @@ class InteractionType(object): VOICE_COMMAND = 7 DICTATION = 8 - class MicrophoneDistance(object): + class MicrophoneDistance(enum.IntEnum): """ Enumerates the types of capture settings describing an audio file. @@ -128,7 +130,7 @@ class MicrophoneDistance(object): MIDFIELD = 2 FARFIELD = 3 - class OriginalMediaType(object): + class OriginalMediaType(enum.IntEnum): """ The original media the speech was recorded on. @@ -141,7 +143,7 @@ class OriginalMediaType(object): AUDIO = 1 VIDEO = 2 - class RecordingDeviceType(object): + class RecordingDeviceType(enum.IntEnum): """ The type of device the speech was recorded with. @@ -164,7 +166,7 @@ class RecordingDeviceType(object): class StreamingRecognizeResponse(object): - class SpeechEventType(object): + class SpeechEventType(enum.IntEnum): """ Indicates the type of speech event. diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py b/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py index 53e6c80412ee..111e0899aad5 100644 --- a/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py +++ b/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py @@ -14,6 +14,7 @@ """Accesses the google.cloud.speech.v1p1beta1 Speech API.""" import pkg_resources +import warnings import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config @@ -22,9 +23,11 @@ import google.api_core.operation import google.api_core.operations_v1 import google.api_core.protobuf_helpers +import grpc from google.cloud.speech_v1p1beta1.gapic import enums from google.cloud.speech_v1p1beta1.gapic import speech_client_config +from google.cloud.speech_v1p1beta1.gapic.transports import speech_grpc_transport from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2 from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2_grpc from google.longrunning import operations_pb2 @@ -39,15 +42,12 @@ class SpeechClient(object): SERVICE_ADDRESS = 'speech.googleapis.com:443' """The default address of the service.""" - # The scopes needed to make gRPC calls to all of the methods defined in - # this service - _DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) - - # The name of the interface for this client. This is the key used to find - # method configuration in the client_config dictionary. + # The name of the interface for this client. This is the key used to + # find the method configuration in the client_config dictionary. _INTERFACE_NAME = 'google.cloud.speech.v1p1beta1.Speech' def __init__(self, + transport=None, channel=None, credentials=None, client_config=speech_client_config.config, @@ -55,79 +55,81 @@ def __init__(self, """Constructor. Args: - channel (grpc.Channel): A ``Channel`` instance through - which to make calls. This argument is mutually exclusive + transport (Union[~.SpeechGrpcTransport, + Callable[[~.Credentials, type], ~.SpeechGrpcTransport]): A transport + instance, responsible for actually making the API calls. + The default transport uses the gRPC protocol. + This argument may also be a callable which returns a + transport instance. Callables will be sent the credentials + as the first argument and the default transport class as + the second argument. + channel (grpc.Channel): DEPRECATED. A ``Channel`` instance + through which to make calls. This argument is mutually exclusive with ``credentials``; providing both will raise an exception. credentials (google.auth.credentials.Credentials): The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. - client_config (dict): A dictionary of call options for each - method. If not specified, the default configuration is used. + This argument is mutually exclusive with providing a + transport instance to ``transport``; doing so will raise + an exception. + client_config (dict): DEPRECATED. A dictionary of call options for + each method. If not specified, the default configuration is used. client_info (google.api_core.gapic_v1.client_info.ClientInfo): The client info used to send a user-agent string along with API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. """ - # If both `channel` and `credentials` are specified, raise an - # exception (channels come with credentials baked in already). - if channel is not None and credentials is not None: - raise ValueError( - 'The `channel` and `credentials` arguments to {} are mutually ' - 'exclusive.'.format(self.__class__.__name__), ) - - # Create the channel. - if channel is None: - channel = google.api_core.grpc_helpers.create_channel( - self.SERVICE_ADDRESS, - credentials=credentials, - scopes=self._DEFAULT_SCOPES, - ) - - # Create the gRPC stubs. - self.speech_stub = (cloud_speech_pb2_grpc.SpeechStub(channel)) - - # Operations client for methods that return long-running operations - # futures. - self.operations_client = ( - google.api_core.operations_v1.OperationsClient(channel)) + # Raise deprecation warnings for things we want to go away. + if client_config: + warnings.warn('The `client_config` argument is deprecated.', + PendingDeprecationWarning) + if channel: + warnings.warn( + 'The `channel` argument is deprecated; use ' + '`transport` instead.', PendingDeprecationWarning) + + # Instantiate the transport. + # The transport is responsible for handling serialization and + # deserialization and actually sending data to the service. + if transport: + if callable(transport): + self.transport = transport( + credentials=credentials, + default_class=speech_grpc_transport.SpeechGrpcTransport, + ) + else: + if credentials: + raise ValueError( + 'Received both a transport instance and ' + 'credentials; these are mutually exclusive.') + self.transport = transport + self.transport = speech_grpc_transport.SpeechGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, + credentials=credentials, + ) if client_info is None: client_info = ( google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO) client_info.gapic_version = _GAPIC_LIBRARY_VERSION + self._client_info = client_info # Parse out the default settings for retry and timeout for each RPC # from the client configuration. # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) - method_configs = google.api_core.gapic_v1.config.parse_method_configs( + self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( client_config['interfaces'][self._INTERFACE_NAME], ) - # Write the "inner API call" methods to the class. - # These are wrapped versions of the gRPC stub methods, with retry and - # timeout configuration applied, called by the public methods on - # this class. - self._recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.Recognize, - default_retry=method_configs['Recognize'].retry, - default_timeout=method_configs['Recognize'].timeout, - client_info=client_info, - ) - self._long_running_recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.LongRunningRecognize, - default_retry=method_configs['LongRunningRecognize'].retry, - default_timeout=method_configs['LongRunningRecognize'].timeout, - client_info=client_info, - ) - self._streaming_recognize = google.api_core.gapic_v1.method.wrap_method( - self.speech_stub.StreamingRecognize, - default_retry=method_configs['StreamingRecognize'].retry, - default_timeout=method_configs['StreamingRecognize'].timeout, - client_info=client_info, - ) + # Save a dictionary of cached API call functions. + # These are the actual callables which invoke the proper + # transport methods, wrapped with `wrap_method` to add retry, + # timeout, and the like. + self._inner_api_calls = {} # Service calls def recognize(self, @@ -182,14 +184,21 @@ def recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.recognize, + default_retry=self._method_configs['Recognize'].retry, + default_timeout=self._method_configs['Recognize'].timeout, + client_info=self._client_info, + ) + request = cloud_speech_pb2.RecognizeRequest( config=config, audio=audio, ) - return self._recognize( + return self._inner_api_calls['recognize']( request, retry=retry, timeout=timeout, metadata=metadata) def long_running_recognize(self, @@ -255,18 +264,27 @@ def long_running_recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'long_running_recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'long_running_recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.long_running_recognize, + default_retry=self._method_configs['LongRunningRecognize'] + .retry, + default_timeout=self._method_configs[ + 'LongRunningRecognize'].timeout, + client_info=self._client_info, + ) + request = cloud_speech_pb2.LongRunningRecognizeRequest( config=config, audio=audio, ) - operation = self._long_running_recognize( + operation = self._inner_api_calls['long_running_recognize']( request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, - self.operations_client, + self.transport._operations_client, cloud_speech_pb2.LongRunningRecognizeResponse, metadata_type=cloud_speech_pb2.LongRunningRecognizeMetadata, ) @@ -316,8 +334,17 @@ def streaming_recognize(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) - return self._streaming_recognize( + # Wrap the transport method to add retry and timeout logic. + if 'streaming_recognize' not in self._inner_api_calls: + self._inner_api_calls[ + 'streaming_recognize'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.streaming_recognize, + default_retry=self._method_configs[ + 'StreamingRecognize'].retry, + default_timeout=self._method_configs['StreamingRecognize'] + .timeout, + client_info=self._client_info, + ) + + return self._inner_api_calls['streaming_recognize']( requests, retry=retry, timeout=timeout, metadata=metadata) diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/transports/__init__.py b/speech/google/cloud/speech_v1p1beta1/gapic/transports/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py b/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py new file mode 100644 index 000000000000..8029a73c6f50 --- /dev/null +++ b/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py @@ -0,0 +1,140 @@ +# Copyright 2018 Google LLC +# +# 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 +# +# https://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. + +import google.api_core.grpc_helpers +import google.api_core.operations_v1 + +from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2_grpc + + +class SpeechGrpcTransport(object): + """gRPC transport class providing stubs for + google.cloud.speech.v1p1beta1 Speech API. + + The transport provides access to the raw gRPC stubs, + which can be used to take advantage of advanced + features of gRPC. + """ + # The scopes needed to make gRPC calls to all of the methods defined + # in this service. + _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + + def __init__(self, + channel=None, + credentials=None, + address='speech.googleapis.com:443'): + """Instantiate the transport class. + + Args: + channel (grpc.Channel): A ``Channel`` instance through + which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + address (str): The address where the service is hosted. + """ + # If both `channel` and `credentials` are specified, raise an + # exception (channels come with credentials baked in already). + if channel is not None and credentials is not None: + raise ValueError( + 'The `channel` and `credentials` arguments are mutually ' + 'exclusive.', ) + + # Create the channel. + if channel is None: + channel = self.create_channel( + address=address, + credentials=credentials, + ) + + # gRPC uses objects called "stubs" that are bound to the + # channel and provide a basic method for each RPC. + self._stubs = { + 'speech_stub': cloud_speech_pb2_grpc.SpeechStub(channel), + } + + # Because this API includes a method that returns a + # long-running operation (proto: google.longrunning.Operation), + # instantiate an LRO client. + self._operations_client = google.api_core.operations_v1.OperationsClient(channel) + + @classmethod + def create_channel(cls, + address='speech.googleapis.com:443', + credentials=None): + """Create and return a gRPC channel object. + + Args: + address (str): The host for the channel to use. + credentials (~.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return google.api_core.grpc_helpers.create_channel( + address, + credentials=credentials, + scopes=cls._OAUTH_SCOPES, + ) + + @property + def recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs synchronous speech recognition: receive results after all audio + has been sent and processed. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].Recognize + + @property + def long_running_recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs asynchronous speech recognition: receive results via the + google.longrunning.Operations interface. Returns either an + ``Operation.error`` or an ``Operation.response`` which contains + a ``LongRunningRecognizeResponse`` message. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].LongRunningRecognize + + @property + def streaming_recognize(self): + """Return the gRPC stub for {$apiMethod.name}. + + Performs bidirectional streaming speech recognition: receive results while + sending audio. This method is only available via the gRPC API (not REST). + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['speech_stub'].StreamingRecognize diff --git a/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py b/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py index 6c102e3b4456..3af7a03275b8 100644 --- a/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py +++ b/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py @@ -25,7 +25,7 @@ name='google/cloud/speech_v1p1beta1/proto/cloud_speech.proto', package='google.cloud.speech.v1p1beta1', syntax='proto3', - serialized_pb=_b('\n6google/cloud/speech_v1p1beta1/proto/cloud_speech.proto\x12\x1dgoogle.cloud.speech.v1p1beta1\x1a\x1cgoogle/api/annotations.proto\x1a#google/longrunning/operations.proto\x1a\x19google/protobuf/any.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\x94\x01\n\x10RecognizeRequest\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12>\n\x05\x61udio\x18\x02 \x01(\x0b\x32/.google.cloud.speech.v1p1beta1.RecognitionAudio\"\x9f\x01\n\x1bLongRunningRecognizeRequest\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12>\n\x05\x61udio\x18\x02 \x01(\x0b\x32/.google.cloud.speech.v1p1beta1.RecognitionAudio\"\xa0\x01\n\x19StreamingRecognizeRequest\x12U\n\x10streaming_config\x18\x01 \x01(\x0b\x32\x39.google.cloud.speech.v1p1beta1.StreamingRecognitionConfigH\x00\x12\x17\n\raudio_content\x18\x02 \x01(\x0cH\x00\x42\x13\n\x11streaming_request\"\x91\x01\n\x1aStreamingRecognitionConfig\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12\x18\n\x10single_utterance\x18\x02 \x01(\x08\x12\x17\n\x0finterim_results\x18\x03 \x01(\x08\"\xd3\x04\n\x11RecognitionConfig\x12P\n\x08\x65ncoding\x18\x01 \x01(\x0e\x32>.google.cloud.speech.v1p1beta1.RecognitionConfig.AudioEncoding\x12\x19\n\x11sample_rate_hertz\x18\x02 \x01(\x05\x12\x15\n\rlanguage_code\x18\x03 \x01(\t\x12\x18\n\x10max_alternatives\x18\x04 \x01(\x05\x12\x18\n\x10profanity_filter\x18\x05 \x01(\x08\x12\x45\n\x0fspeech_contexts\x18\x06 \x03(\x0b\x32,.google.cloud.speech.v1p1beta1.SpeechContext\x12 \n\x18\x65nable_word_time_offsets\x18\x08 \x01(\x08\x12$\n\x1c\x65nable_automatic_punctuation\x18\x0b \x01(\x08\x12\x44\n\x08metadata\x18\t \x01(\x0b\x32\x32.google.cloud.speech.v1p1beta1.RecognitionMetadata\x12\r\n\x05model\x18\r \x01(\t\x12\x14\n\x0cuse_enhanced\x18\x0e \x01(\x08\"\x8b\x01\n\rAudioEncoding\x12\x18\n\x14\x45NCODING_UNSPECIFIED\x10\x00\x12\x0c\n\x08LINEAR16\x10\x01\x12\x08\n\x04\x46LAC\x10\x02\x12\t\n\x05MULAW\x10\x03\x12\x07\n\x03\x41MR\x10\x04\x12\n\n\x06\x41MR_WB\x10\x05\x12\x0c\n\x08OGG_OPUS\x10\x06\x12\x1a\n\x16SPEEX_WITH_HEADER_BYTE\x10\x07\"\xd3\x08\n\x13RecognitionMetadata\x12\\\n\x10interaction_type\x18\x01 \x01(\x0e\x32\x42.google.cloud.speech.v1p1beta1.RecognitionMetadata.InteractionType\x12$\n\x1cindustry_naics_code_of_audio\x18\x03 \x01(\r\x12\x62\n\x13microphone_distance\x18\x04 \x01(\x0e\x32\x45.google.cloud.speech.v1p1beta1.RecognitionMetadata.MicrophoneDistance\x12\x61\n\x13original_media_type\x18\x05 \x01(\x0e\x32\x44.google.cloud.speech.v1p1beta1.RecognitionMetadata.OriginalMediaType\x12\x65\n\x15recording_device_type\x18\x06 \x01(\x0e\x32\x46.google.cloud.speech.v1p1beta1.RecognitionMetadata.RecordingDeviceType\x12\x1d\n\x15recording_device_name\x18\x07 \x01(\t\x12\x1a\n\x12original_mime_type\x18\x08 \x01(\t\x12\x15\n\robfuscated_id\x18\t \x01(\x03\x12\x13\n\x0b\x61udio_topic\x18\n \x01(\t\"\xc5\x01\n\x0fInteractionType\x12 \n\x1cINTERACTION_TYPE_UNSPECIFIED\x10\x00\x12\x0e\n\nDISCUSSION\x10\x01\x12\x10\n\x0cPRESENTATION\x10\x02\x12\x0e\n\nPHONE_CALL\x10\x03\x12\r\n\tVOICEMAIL\x10\x04\x12\x1b\n\x17PROFESSIONALLY_PRODUCED\x10\x05\x12\x10\n\x0cVOICE_SEARCH\x10\x06\x12\x11\n\rVOICE_COMMAND\x10\x07\x12\r\n\tDICTATION\x10\x08\"d\n\x12MicrophoneDistance\x12#\n\x1fMICROPHONE_DISTANCE_UNSPECIFIED\x10\x00\x12\r\n\tNEARFIELD\x10\x01\x12\x0c\n\x08MIDFIELD\x10\x02\x12\x0c\n\x08\x46\x41RFIELD\x10\x03\"N\n\x11OriginalMediaType\x12#\n\x1fORIGINAL_MEDIA_TYPE_UNSPECIFIED\x10\x00\x12\t\n\x05\x41UDIO\x10\x01\x12\t\n\x05VIDEO\x10\x02\"\xa4\x01\n\x13RecordingDeviceType\x12%\n!RECORDING_DEVICE_TYPE_UNSPECIFIED\x10\x00\x12\x0e\n\nSMARTPHONE\x10\x01\x12\x06\n\x02PC\x10\x02\x12\x0e\n\nPHONE_LINE\x10\x03\x12\x0b\n\x07VEHICLE\x10\x04\x12\x18\n\x14OTHER_OUTDOOR_DEVICE\x10\x05\x12\x17\n\x13OTHER_INDOOR_DEVICE\x10\x06\" \n\rSpeechContext\x12\x0f\n\x07phrases\x18\x01 \x03(\t\"D\n\x10RecognitionAudio\x12\x11\n\x07\x63ontent\x18\x01 \x01(\x0cH\x00\x12\r\n\x03uri\x18\x02 \x01(\tH\x00\x42\x0e\n\x0c\x61udio_source\"\\\n\x11RecognizeResponse\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.google.cloud.speech.v1p1beta1.SpeechRecognitionResult\"g\n\x1cLongRunningRecognizeResponse\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.google.cloud.speech.v1p1beta1.SpeechRecognitionResult\"\x9e\x01\n\x1cLongRunningRecognizeMetadata\x12\x18\n\x10progress_percent\x18\x01 \x01(\x05\x12.\n\nstart_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x10last_update_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xbf\x02\n\x1aStreamingRecognizeResponse\x12!\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12J\n\x07results\x18\x02 \x03(\x0b\x32\x39.google.cloud.speech.v1p1beta1.StreamingRecognitionResult\x12\x64\n\x11speech_event_type\x18\x04 \x01(\x0e\x32I.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse.SpeechEventType\"L\n\x0fSpeechEventType\x12\x1c\n\x18SPEECH_EVENT_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x45ND_OF_SINGLE_UTTERANCE\x10\x01\"\x94\x01\n\x1aStreamingRecognitionResult\x12Q\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32;.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative\x12\x10\n\x08is_final\x18\x02 \x01(\x08\x12\x11\n\tstability\x18\x03 \x01(\x02\"l\n\x17SpeechRecognitionResult\x12Q\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32;.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative\"~\n\x1cSpeechRecognitionAlternative\x12\x12\n\ntranscript\x18\x01 \x01(\t\x12\x12\n\nconfidence\x18\x02 \x01(\x02\x12\x36\n\x05words\x18\x03 \x03(\x0b\x32\'.google.cloud.speech.v1p1beta1.WordInfo\"t\n\x08WordInfo\x12-\n\nstart_time\x18\x01 \x01(\x0b\x32\x19.google.protobuf.Duration\x12+\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04word\x18\x03 \x01(\t2\xd8\x03\n\x06Speech\x12\x96\x01\n\tRecognize\x12/.google.cloud.speech.v1p1beta1.RecognizeRequest\x1a\x30.google.cloud.speech.v1p1beta1.RecognizeResponse\"&\x82\xd3\xe4\x93\x02 \"\x1b/v1p1beta1/speech:recognize:\x01*\x12\xa4\x01\n\x14LongRunningRecognize\x12:.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest\x1a\x1d.google.longrunning.Operation\"1\x82\xd3\xe4\x93\x02+\"&/v1p1beta1/speech:longrunningrecognize:\x01*\x12\x8d\x01\n\x12StreamingRecognize\x12\x38.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest\x1a\x39.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse(\x01\x30\x01\x42z\n!com.google.cloud.speech.v1p1beta1B\x0bSpeechProtoP\x01ZCgoogle.golang.org/genproto/googleapis/cloud/speech/v1p1beta1;speech\xf8\x01\x01\x62\x06proto3') + serialized_pb=_b('\n6google/cloud/speech_v1p1beta1/proto/cloud_speech.proto\x12\x1dgoogle.cloud.speech.v1p1beta1\x1a\x1cgoogle/api/annotations.proto\x1a#google/longrunning/operations.proto\x1a\x19google/protobuf/any.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\x94\x01\n\x10RecognizeRequest\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12>\n\x05\x61udio\x18\x02 \x01(\x0b\x32/.google.cloud.speech.v1p1beta1.RecognitionAudio\"\x9f\x01\n\x1bLongRunningRecognizeRequest\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12>\n\x05\x61udio\x18\x02 \x01(\x0b\x32/.google.cloud.speech.v1p1beta1.RecognitionAudio\"\xa0\x01\n\x19StreamingRecognizeRequest\x12U\n\x10streaming_config\x18\x01 \x01(\x0b\x32\x39.google.cloud.speech.v1p1beta1.StreamingRecognitionConfigH\x00\x12\x17\n\raudio_content\x18\x02 \x01(\x0cH\x00\x42\x13\n\x11streaming_request\"\x91\x01\n\x1aStreamingRecognitionConfig\x12@\n\x06\x63onfig\x18\x01 \x01(\x0b\x32\x30.google.cloud.speech.v1p1beta1.RecognitionConfig\x12\x18\n\x10single_utterance\x18\x02 \x01(\x08\x12\x17\n\x0finterim_results\x18\x03 \x01(\x08\"\xac\x06\n\x11RecognitionConfig\x12P\n\x08\x65ncoding\x18\x01 \x01(\x0e\x32>.google.cloud.speech.v1p1beta1.RecognitionConfig.AudioEncoding\x12\x19\n\x11sample_rate_hertz\x18\x02 \x01(\x05\x12\x1b\n\x13\x61udio_channel_count\x18\x07 \x01(\x05\x12/\n\'enable_separate_recognition_per_channel\x18\x0c \x01(\x08\x12\x15\n\rlanguage_code\x18\x03 \x01(\t\x12\"\n\x1a\x61lternative_language_codes\x18\x12 \x03(\t\x12\x18\n\x10max_alternatives\x18\x04 \x01(\x05\x12\x18\n\x10profanity_filter\x18\x05 \x01(\x08\x12\x45\n\x0fspeech_contexts\x18\x06 \x03(\x0b\x32,.google.cloud.speech.v1p1beta1.SpeechContext\x12 \n\x18\x65nable_word_time_offsets\x18\x08 \x01(\x08\x12\x1e\n\x16\x65nable_word_confidence\x18\x0f \x01(\x08\x12$\n\x1c\x65nable_automatic_punctuation\x18\x0b \x01(\x08\x12\"\n\x1a\x65nable_speaker_diarization\x18\x10 \x01(\x08\x12!\n\x19\x64iarization_speaker_count\x18\x11 \x01(\x05\x12\x44\n\x08metadata\x18\t \x01(\x0b\x32\x32.google.cloud.speech.v1p1beta1.RecognitionMetadata\x12\r\n\x05model\x18\r \x01(\t\x12\x14\n\x0cuse_enhanced\x18\x0e \x01(\x08\"\x8b\x01\n\rAudioEncoding\x12\x18\n\x14\x45NCODING_UNSPECIFIED\x10\x00\x12\x0c\n\x08LINEAR16\x10\x01\x12\x08\n\x04\x46LAC\x10\x02\x12\t\n\x05MULAW\x10\x03\x12\x07\n\x03\x41MR\x10\x04\x12\n\n\x06\x41MR_WB\x10\x05\x12\x0c\n\x08OGG_OPUS\x10\x06\x12\x1a\n\x16SPEEX_WITH_HEADER_BYTE\x10\x07\"\xd3\x08\n\x13RecognitionMetadata\x12\\\n\x10interaction_type\x18\x01 \x01(\x0e\x32\x42.google.cloud.speech.v1p1beta1.RecognitionMetadata.InteractionType\x12$\n\x1cindustry_naics_code_of_audio\x18\x03 \x01(\r\x12\x62\n\x13microphone_distance\x18\x04 \x01(\x0e\x32\x45.google.cloud.speech.v1p1beta1.RecognitionMetadata.MicrophoneDistance\x12\x61\n\x13original_media_type\x18\x05 \x01(\x0e\x32\x44.google.cloud.speech.v1p1beta1.RecognitionMetadata.OriginalMediaType\x12\x65\n\x15recording_device_type\x18\x06 \x01(\x0e\x32\x46.google.cloud.speech.v1p1beta1.RecognitionMetadata.RecordingDeviceType\x12\x1d\n\x15recording_device_name\x18\x07 \x01(\t\x12\x1a\n\x12original_mime_type\x18\x08 \x01(\t\x12\x15\n\robfuscated_id\x18\t \x01(\x03\x12\x13\n\x0b\x61udio_topic\x18\n \x01(\t\"\xc5\x01\n\x0fInteractionType\x12 \n\x1cINTERACTION_TYPE_UNSPECIFIED\x10\x00\x12\x0e\n\nDISCUSSION\x10\x01\x12\x10\n\x0cPRESENTATION\x10\x02\x12\x0e\n\nPHONE_CALL\x10\x03\x12\r\n\tVOICEMAIL\x10\x04\x12\x1b\n\x17PROFESSIONALLY_PRODUCED\x10\x05\x12\x10\n\x0cVOICE_SEARCH\x10\x06\x12\x11\n\rVOICE_COMMAND\x10\x07\x12\r\n\tDICTATION\x10\x08\"d\n\x12MicrophoneDistance\x12#\n\x1fMICROPHONE_DISTANCE_UNSPECIFIED\x10\x00\x12\r\n\tNEARFIELD\x10\x01\x12\x0c\n\x08MIDFIELD\x10\x02\x12\x0c\n\x08\x46\x41RFIELD\x10\x03\"N\n\x11OriginalMediaType\x12#\n\x1fORIGINAL_MEDIA_TYPE_UNSPECIFIED\x10\x00\x12\t\n\x05\x41UDIO\x10\x01\x12\t\n\x05VIDEO\x10\x02\"\xa4\x01\n\x13RecordingDeviceType\x12%\n!RECORDING_DEVICE_TYPE_UNSPECIFIED\x10\x00\x12\x0e\n\nSMARTPHONE\x10\x01\x12\x06\n\x02PC\x10\x02\x12\x0e\n\nPHONE_LINE\x10\x03\x12\x0b\n\x07VEHICLE\x10\x04\x12\x18\n\x14OTHER_OUTDOOR_DEVICE\x10\x05\x12\x17\n\x13OTHER_INDOOR_DEVICE\x10\x06\" \n\rSpeechContext\x12\x0f\n\x07phrases\x18\x01 \x03(\t\"D\n\x10RecognitionAudio\x12\x11\n\x07\x63ontent\x18\x01 \x01(\x0cH\x00\x12\r\n\x03uri\x18\x02 \x01(\tH\x00\x42\x0e\n\x0c\x61udio_source\"\\\n\x11RecognizeResponse\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.google.cloud.speech.v1p1beta1.SpeechRecognitionResult\"g\n\x1cLongRunningRecognizeResponse\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.google.cloud.speech.v1p1beta1.SpeechRecognitionResult\"\x9e\x01\n\x1cLongRunningRecognizeMetadata\x12\x18\n\x10progress_percent\x18\x01 \x01(\x05\x12.\n\nstart_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x10last_update_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xbf\x02\n\x1aStreamingRecognizeResponse\x12!\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12J\n\x07results\x18\x02 \x03(\x0b\x32\x39.google.cloud.speech.v1p1beta1.StreamingRecognitionResult\x12\x64\n\x11speech_event_type\x18\x04 \x01(\x0e\x32I.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse.SpeechEventType\"L\n\x0fSpeechEventType\x12\x1c\n\x18SPEECH_EVENT_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x45ND_OF_SINGLE_UTTERANCE\x10\x01\"\xc0\x01\n\x1aStreamingRecognitionResult\x12Q\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32;.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative\x12\x10\n\x08is_final\x18\x02 \x01(\x08\x12\x11\n\tstability\x18\x03 \x01(\x02\x12\x13\n\x0b\x63hannel_tag\x18\x05 \x01(\x05\x12\x15\n\rlanguage_code\x18\x06 \x01(\t\"\x98\x01\n\x17SpeechRecognitionResult\x12Q\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32;.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative\x12\x13\n\x0b\x63hannel_tag\x18\x02 \x01(\x05\x12\x15\n\rlanguage_code\x18\x05 \x01(\t\"~\n\x1cSpeechRecognitionAlternative\x12\x12\n\ntranscript\x18\x01 \x01(\t\x12\x12\n\nconfidence\x18\x02 \x01(\x02\x12\x36\n\x05words\x18\x03 \x03(\x0b\x32\'.google.cloud.speech.v1p1beta1.WordInfo\"\x9d\x01\n\x08WordInfo\x12-\n\nstart_time\x18\x01 \x01(\x0b\x32\x19.google.protobuf.Duration\x12+\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04word\x18\x03 \x01(\t\x12\x12\n\nconfidence\x18\x04 \x01(\x02\x12\x13\n\x0bspeaker_tag\x18\x05 \x01(\x05\x32\xd8\x03\n\x06Speech\x12\x96\x01\n\tRecognize\x12/.google.cloud.speech.v1p1beta1.RecognizeRequest\x1a\x30.google.cloud.speech.v1p1beta1.RecognizeResponse\"&\x82\xd3\xe4\x93\x02 \"\x1b/v1p1beta1/speech:recognize:\x01*\x12\xa4\x01\n\x14LongRunningRecognize\x12:.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest\x1a\x1d.google.longrunning.Operation\"1\x82\xd3\xe4\x93\x02+\"&/v1p1beta1/speech:longrunningrecognize:\x01*\x12\x8d\x01\n\x12StreamingRecognize\x12\x38.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest\x1a\x39.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse(\x01\x30\x01\x42z\n!com.google.cloud.speech.v1p1beta1B\x0bSpeechProtoP\x01ZCgoogle.golang.org/genproto/googleapis/cloud/speech/v1p1beta1;speech\xf8\x01\x01\x62\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_longrunning_dot_operations__pb2.DESCRIPTOR,google_dot_protobuf_dot_any__pb2.DESCRIPTOR,google_dot_protobuf_dot_duration__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,google_dot_rpc_dot_status__pb2.DESCRIPTOR,]) @@ -72,8 +72,8 @@ ], containing_type=None, options=None, - serialized_start=1354, - serialized_end=1493, + serialized_start=1571, + serialized_end=1710, ) _sym_db.RegisterEnumDescriptor(_RECOGNITIONCONFIG_AUDIOENCODING) @@ -122,8 +122,8 @@ ], containing_type=None, options=None, - serialized_start=2057, - serialized_end=2254, + serialized_start=2274, + serialized_end=2471, ) _sym_db.RegisterEnumDescriptor(_RECOGNITIONMETADATA_INTERACTIONTYPE) @@ -152,8 +152,8 @@ ], containing_type=None, options=None, - serialized_start=2256, - serialized_end=2356, + serialized_start=2473, + serialized_end=2573, ) _sym_db.RegisterEnumDescriptor(_RECOGNITIONMETADATA_MICROPHONEDISTANCE) @@ -178,8 +178,8 @@ ], containing_type=None, options=None, - serialized_start=2358, - serialized_end=2436, + serialized_start=2575, + serialized_end=2653, ) _sym_db.RegisterEnumDescriptor(_RECOGNITIONMETADATA_ORIGINALMEDIATYPE) @@ -220,8 +220,8 @@ ], containing_type=None, options=None, - serialized_start=2439, - serialized_end=2603, + serialized_start=2656, + serialized_end=2820, ) _sym_db.RegisterEnumDescriptor(_RECOGNITIONMETADATA_RECORDINGDEVICETYPE) @@ -242,8 +242,8 @@ ], containing_type=None, options=None, - serialized_start=3313, - serialized_end=3389, + serialized_start=3530, + serialized_end=3606, ) _sym_db.RegisterEnumDescriptor(_STREAMINGRECOGNIZERESPONSE_SPEECHEVENTTYPE) @@ -432,63 +432,105 @@ is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='language_code', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.language_code', index=2, + name='audio_channel_count', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.audio_channel_count', index=2, + number=7, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='enable_separate_recognition_per_channel', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_separate_recognition_per_channel', index=3, + number=12, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='language_code', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.language_code', index=4, number=3, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='max_alternatives', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.max_alternatives', index=3, + name='alternative_language_codes', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.alternative_language_codes', index=5, + number=18, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='max_alternatives', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.max_alternatives', index=6, number=4, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='profanity_filter', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.profanity_filter', index=4, + name='profanity_filter', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.profanity_filter', index=7, number=5, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='speech_contexts', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.speech_contexts', index=5, + name='speech_contexts', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.speech_contexts', index=8, number=6, type=11, cpp_type=10, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='enable_word_time_offsets', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_word_time_offsets', index=6, + name='enable_word_time_offsets', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_word_time_offsets', index=9, number=8, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='enable_automatic_punctuation', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_automatic_punctuation', index=7, + name='enable_word_confidence', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_word_confidence', index=10, + number=15, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='enable_automatic_punctuation', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_automatic_punctuation', index=11, number=11, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='metadata', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.metadata', index=8, + name='enable_speaker_diarization', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.enable_speaker_diarization', index=12, + number=16, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='diarization_speaker_count', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.diarization_speaker_count', index=13, + number=17, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='metadata', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.metadata', index=14, number=9, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='model', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.model', index=9, + name='model', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.model', index=15, number=13, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='use_enhanced', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.use_enhanced', index=10, + name='use_enhanced', full_name='google.cloud.speech.v1p1beta1.RecognitionConfig.use_enhanced', index=16, number=14, type=8, cpp_type=7, label=1, has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, @@ -508,7 +550,7 @@ oneofs=[ ], serialized_start=898, - serialized_end=1493, + serialized_end=1710, ) @@ -598,8 +640,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1496, - serialized_end=2603, + serialized_start=1713, + serialized_end=2820, ) @@ -629,8 +671,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2605, - serialized_end=2637, + serialized_start=2822, + serialized_end=2854, ) @@ -670,8 +712,8 @@ name='audio_source', full_name='google.cloud.speech.v1p1beta1.RecognitionAudio.audio_source', index=0, containing_type=None, fields=[]), ], - serialized_start=2639, - serialized_end=2707, + serialized_start=2856, + serialized_end=2924, ) @@ -701,8 +743,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2709, - serialized_end=2801, + serialized_start=2926, + serialized_end=3018, ) @@ -732,8 +774,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2803, - serialized_end=2906, + serialized_start=3020, + serialized_end=3123, ) @@ -777,8 +819,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2909, - serialized_end=3067, + serialized_start=3126, + serialized_end=3284, ) @@ -823,8 +865,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3070, - serialized_end=3389, + serialized_start=3287, + serialized_end=3606, ) @@ -856,6 +898,20 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='channel_tag', full_name='google.cloud.speech.v1p1beta1.StreamingRecognitionResult.channel_tag', index=3, + number=5, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='language_code', full_name='google.cloud.speech.v1p1beta1.StreamingRecognitionResult.language_code', index=4, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -868,8 +924,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3392, - serialized_end=3540, + serialized_start=3609, + serialized_end=3801, ) @@ -887,6 +943,20 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='channel_tag', full_name='google.cloud.speech.v1p1beta1.SpeechRecognitionResult.channel_tag', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='language_code', full_name='google.cloud.speech.v1p1beta1.SpeechRecognitionResult.language_code', index=2, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -899,8 +969,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3542, - serialized_end=3650, + serialized_start=3804, + serialized_end=3956, ) @@ -944,8 +1014,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3652, - serialized_end=3778, + serialized_start=3958, + serialized_end=4084, ) @@ -977,6 +1047,20 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='confidence', full_name='google.cloud.speech.v1p1beta1.WordInfo.confidence', index=3, + number=4, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='speaker_tag', full_name='google.cloud.speech.v1p1beta1.WordInfo.speaker_tag', index=4, + number=5, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -989,8 +1073,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3780, - serialized_end=3896, + serialized_start=4087, + serialized_end=4244, ) _RECOGNIZEREQUEST.fields_by_name['config'].message_type = _RECOGNITIONCONFIG @@ -1187,12 +1271,44 @@ audio files and required for all other audio formats. For details, see [AudioEncoding][google.cloud.speech.v1p1beta1.Rec ognitionConfig.AudioEncoding]. + audio_channel_count: + *Optional* The number of channels in the input audio data. + ONLY set this for MULTI-CHANNEL recognition. Valid values for + LINEAR16 and FLAC are ``1``-``8``. Valid values for OGG\_OPUS + are '1'-'254'. Valid value for MULAW, AMR, AMR\_WB and + SPEEX\_WITH\_HEADER\_BYTE is only ``1``. If ``0`` or omitted, + defaults to one channel (mono). NOTE: We only recognize the + first channel by default. To perform independent recognition + on each channel set + enable\_separate\_recognition\_per\_channel to 'true'. + enable_separate_recognition_per_channel: + This needs to be set to ‘true’ explicitly and + audio\_channel\_count > 1 to get each channel recognized + separately. The recognition result will contain a channel\_tag + field to state which channel that result belongs to. If this + is not ‘true’, we will only recognize the first channel. NOTE: + The request is also billed cumulatively for all channels + recognized: (audio\_channel\_count times the audio length) language_code: *Required* The language of the supplied audio as a `BCP-47 `__ language tag. Example: "en-US". See `Language Support `__ for a list of the currently supported language codes. + alternative_language_codes: + *Optional* A list of up to 3 additional `BCP-47 + `__ language + tags, listing possible alternative languages of the supplied + audio. See `Language Support + `__ for a list + of the currently supported language codes. If alternative + languages are listed, recognition result will contain + recognition in the most likely language detected including the + main language\_code. The recognition result will include the + language tag of the language detected in the audio. NOTE: This + feature is only supported for Voice Command and Voice Search + use cases and performance may vary for other use cases (e.g., + phone call transcription). max_alternatives: *Optional* Maximum number of recognition hypotheses to be returned. Specifically, the maximum number of @@ -1215,6 +1331,11 @@ words and the start and end time offsets (timestamps) for those words. If ``false``, no word-level time offset information is returned. The default is ``false``. + enable_word_confidence: + *Optional* If ``true``, the top result includes a list of + words and the confidence for those words. If ``false``, no + word-level confidence information is returned. The default is + ``false``. enable_automatic_punctuation: *Optional* If 'true', adds punctuation to recognition result hypotheses. This feature is only available in select @@ -1224,6 +1345,19 @@ offered as an experimental service, complimentary to all users. In the future this may be exclusively available as a premium feature." + enable_speaker_diarization: + *Optional* If 'true', enables speaker detection for each + recognized word in the top alternative of the recognition + result using a speaker\_tag provided in the WordInfo. Note: + When this is true, we send all the words from the beginning of + the audio for the top alternative in every consecutive + responses. This is done in order to improve our speaker tags + as our models learn to identify the speakers in the + conversation over time. + diarization_speaker_count: + *Optional* If set, specifies the estimated number of speakers + in the conversation. If not set, defaults to '2'. Ignored + unless enable\_speaker\_diarization is set to true." metadata: *Optional* Metadata regarding this request. model: @@ -1534,6 +1668,16 @@ stable). This field is only provided for interim results (``is_final=false``). The default of 0.0 is a sentinel value indicating ``stability`` was not set. + channel_tag: + For multi-channel audio, this is the channel number + corresponding to the recognized result for the audio from that + channel. For audio\_channel\_count = N, its output values can + range from '1' to 'N'. + language_code: + Output only. The `BCP-47 `__ language tag of the language + in this result. This language code was detected to have the + most likelihood of being spoken in the audio. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1p1beta1.StreamingRecognitionResult) )) @@ -1553,6 +1697,16 @@ alternatives are ordered in terms of accuracy, with the top (first) alternative being the most probable, as ranked by the recognizer. + channel_tag: + For multi-channel audio, this is the channel number + corresponding to the recognized result for the audio from that + channel. For audio\_channel\_count = N, its output values can + range from '1' to 'N'. + language_code: + Output only. The `BCP-47 `__ language tag of the language + in this result. This language code was detected to have the + most likelihood of being spoken in the audio. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1p1beta1.SpeechRecognitionResult) )) @@ -1611,6 +1765,22 @@ word: Output only. The word corresponding to this set of information. + confidence: + Output only. The confidence estimate between 0.0 and 1.0. A + higher number indicates an estimated greater likelihood that + the recognized words are correct. This field is set only for + the top alternative of a non-streaming result or, of a + streaming result where ``is_final=true``. This field is not + guaranteed to be accurate and users should not rely on it to + be always provided. The default of 0.0 is a sentinel value + indicating ``confidence`` was not set. + speaker_tag: + Output only. A distinct integer value is assigned for every + speaker within the audio. This field specifies which one of + those speakers was detected to have spoken this word. Value + ranges from '1' to diarization\_speaker\_count. speaker\_tag + is set if enable\_speaker\_diarization = 'true' and only in + the top alternative. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1p1beta1.WordInfo) )) @@ -1626,8 +1796,8 @@ file=DESCRIPTOR, index=0, options=None, - serialized_start=3899, - serialized_end=4371, + serialized_start=4247, + serialized_end=4719, methods=[ _descriptor.MethodDescriptor( name='Recognize', diff --git a/speech/google/cloud/speech_v1p1beta1/types.py b/speech/google/cloud/speech_v1p1beta1/types.py index c4101981fba1..4b4cec915997 100644 --- a/speech/google/cloud/speech_v1p1beta1/types.py +++ b/speech/google/cloud/speech_v1p1beta1/types.py @@ -15,7 +15,10 @@ from __future__ import absolute_import import sys +from google.api_core.protobuf_helpers import get_messages + from google.api import http_pb2 +from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -24,10 +27,6 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 -from google.api_core.protobuf_helpers import get_messages -from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2 - - _shared_modules = [ http_pb2, operations_pb2, @@ -49,7 +48,6 @@ for name, message in get_messages(module).items(): setattr(sys.modules[__name__], name, message) names.append(name) - for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.speech_v1p1beta1.types' diff --git a/speech/synth.py b/speech/synth.py new file mode 100644 index 000000000000..bbbac8808019 --- /dev/null +++ b/speech/synth.py @@ -0,0 +1,86 @@ +# Copyright 2018 Google LLC +# +# 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. + +"""This script is used to synthesize generated parts of this library.""" + +import re + +import synthtool as s +from synthtool import gcp + +gapic = gcp.GAPICGenerator() + +versions = ['v1p1beta1', 'v1'] + + +for version in versions: + library = gapic.py_library('speech', version) + + s.move(library / f'google/cloud/speech_{version}/speech') + # Don't move over __init__.py, as we modify it to make the generated client + # use helpers.py. + s.move(library / f'google/cloud/speech_{version}/types.py') + s.move(library / f'google/cloud/speech_{version}/gapic') + s.move(library / f'google/cloud/speech_{version}/proto') + s.move(library / f'tests/unit/gapic/{version}') + s.move(library / f'docs/gapic/{version}') + + +# Use the highest version library to generate documentation index, README, and +# import alias. +s.move(library / 'google/cloud/speech.py') +s.move(library / 'docs/index.rst') +s.move(library / 'README.rst') + + +# Make the docs multiversion +s.replace( + 'docs/index.rst', + r' gapic/v1/api(.+?)\Z', + """\ + gapic/v1/api + gapic/v1/types + gapic/v1p1beta1/api + gapic/v1p1beta1/types + changelog +""", re.DOTALL | re.MULTILINE) + + +# The release stage is Beta, not Alpha. +s.replace( + ['README.rst', 'docs/index.rst'], + r'Google Cloud Speech API \(`Alpha`_\)', + 'Google Cloud Speech API (`Beta`_)') + + +# Fix bad reference to operations_v1 +s.replace( + '**/gapic/**/*_transport.py', + r' \= operations_v1\.', + ' = google.api_core.operations_v1.') + + +# Fix bad docstrings. +s.replace( + '**/gapic/*_client.py', + r'\\"(.+?)-\*\\"', + r'"\1-\\*"') + + +# Fix tests to use the direct gapic client instead of the wrapped helper +# client. +s.replace( + 'tests/unit/**/test*client*.py', + r'from google\.cloud import speech_(.+?)$', + r'from google.cloud.speech_\1.gapic import speech_client as speech_\1') diff --git a/speech/tests/unit/gapic/v1/test_helpers.py b/speech/tests/unit/gapic/v1/test_helpers.py deleted file mode 100644 index 0588e7d8e9b7..000000000000 --- a/speech/tests/unit/gapic/v1/test_helpers.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2017, Google LLC All rights reserved. -# -# 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. - -from __future__ import absolute_import -from types import GeneratorType -import unittest - -import mock - - -class TestSpeechClient(unittest.TestCase): - - @staticmethod - def _make_one(): - import google.auth.credentials - from google.cloud.speech_v1 import SpeechClient - - credentials = mock.Mock(spec=google.auth.credentials.Credentials) - return SpeechClient(credentials=credentials) - - def test_inherited_method(self): - from google.cloud.speech_v1 import types - - client = self._make_one() - - config = types.RecognitionConfig(encoding='FLAC') - audio = types.RecognitionAudio(uri='http://foo.com/bar.wav') - patch = mock.patch.object(client, '_recognize', autospec=True) - with patch as recognize: - client.recognize(config, audio) - - # Assert that the underlying GAPIC method was called as expected. - assert recognize.call_count == 1 - _, args, _ = recognize.mock_calls[0] - assert args[0] == types.RecognizeRequest( - config=config, - audio=audio, - ) - - def test_streaming_recognize(self): - from google.cloud.speech_v1 import types - - client = self._make_one() - - config = types.StreamingRecognitionConfig() - requests = [types.StreamingRecognizeRequest(audio_content=b'...')] - patch = mock.patch.object( - client, '_streaming_recognize', autospec=True) - with patch as sr: - client.streaming_recognize(config, requests) - - # Assert that we called streaming recognize with an iterable - # that evalutes to the correct format. - _, args, _ = sr.mock_calls[0] - api_requests = args[0] - assert isinstance(api_requests, GeneratorType) - assert list(api_requests) == [ - types.StreamingRecognizeRequest(streaming_config=config), - requests[0], - ] diff --git a/speech/tests/unit/gapic/v1/test_speech_client_v1.py b/speech/tests/unit/gapic/v1/test_speech_client_v1.py index 332338f941d2..f129d4f8b0b9 100644 --- a/speech/tests/unit/gapic/v1/test_speech_client_v1.py +++ b/speech/tests/unit/gapic/v1/test_speech_client_v1.py @@ -17,7 +17,7 @@ from google.rpc import status_pb2 -from google.cloud import speech_v1 +from google.cloud.speech_v1.gapic import speech_client as speech_v1 from google.cloud.speech_v1 import enums from google.cloud.speech_v1.proto import cloud_speech_pb2 from google.longrunning import operations_pb2 @@ -197,7 +197,7 @@ def test_streaming_recognize(self): request = cloud_speech_pb2.StreamingRecognizeRequest(**request) requests = [request] - response = client._streaming_recognize(requests) + response = client.streaming_recognize(requests) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] @@ -220,4 +220,4 @@ def test_streaming_recognize_exception(self): requests = [request] with pytest.raises(CustomException): - client._streaming_recognize(requests) + client.streaming_recognize(requests) diff --git a/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py b/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py index fede67eeec31..16e2420f6eaa 100644 --- a/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py +++ b/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py @@ -17,7 +17,7 @@ from google.rpc import status_pb2 -from google.cloud import speech_v1p1beta1 +from google.cloud.speech_v1p1beta1.gapic import speech_client as speech_v1p1beta1 from google.cloud.speech_v1p1beta1 import enums from google.cloud.speech_v1p1beta1.proto import cloud_speech_pb2 from google.longrunning import operations_pb2 @@ -197,7 +197,7 @@ def test_streaming_recognize(self): request = cloud_speech_pb2.StreamingRecognizeRequest(**request) requests = [request] - response = client._streaming_recognize(requests) + response = client.streaming_recognize(requests) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] @@ -220,4 +220,4 @@ def test_streaming_recognize_exception(self): requests = [request] with pytest.raises(CustomException): - client._streaming_recognize(requests) + client.streaming_recognize(requests) diff --git a/speech/tests/unit/test_helpers.py b/speech/tests/unit/test_helpers.py new file mode 100644 index 000000000000..a8199ec8ce5f --- /dev/null +++ b/speech/tests/unit/test_helpers.py @@ -0,0 +1,53 @@ +# Copyright 2017, Google LLC All rights reserved. +# +# 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. + +from __future__ import absolute_import +from types import GeneratorType + +import mock + +import google.auth.credentials +from google.cloud.speech_v1 import SpeechClient +from google.cloud.speech_v1 import types + + +def make_speech_client(): + credentials = mock.Mock(spec=google.auth.credentials.Credentials) + return SpeechClient(credentials=credentials) + + +def test_streaming_recognize(): + client = make_speech_client() + + config = types.StreamingRecognitionConfig() + requests = [types.StreamingRecognizeRequest(audio_content=b'...')] + super_patch = mock.patch( + 'google.cloud.speech_v1.speech_client.SpeechClient.' + 'streaming_recognize', + autospec=True) + + with super_patch as streaming_recognize: + client.streaming_recognize(config, requests) + + # Assert that we called streaming recognize with an iterable + # that evaluates to the correct format. + _, args, kwargs = streaming_recognize.mock_calls[0] + api_requests = args[1] + assert isinstance(api_requests, GeneratorType) + assert list(api_requests) == [ + types.StreamingRecognizeRequest(streaming_config=config), + requests[0], + ] + assert 'retry' in kwargs + assert 'timeout' in kwargs From 975d9c0fa57163489095c05edd06893cfc7a014c Mon Sep 17 00:00:00 2001 From: Thea Flowers Date: Mon, 9 Jul 2018 14:40:46 -0700 Subject: [PATCH 2/2] Fix file encoding --- speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py | 1 + .../cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py | 1 + speech/synth.py | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py index e9a3eb47aee6..b6da8ec2f3c7 100644 --- a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py +++ b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/speech_v1/proto/cloud_speech.proto diff --git a/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py b/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py index 3af7a03275b8..abcde8dd3b04 100644 --- a/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py +++ b/speech/google/cloud/speech_v1p1beta1/proto/cloud_speech_pb2.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/speech_v1p1beta1/proto/cloud_speech.proto diff --git a/speech/synth.py b/speech/synth.py index bbbac8808019..8322b9013b6e 100644 --- a/speech/synth.py +++ b/speech/synth.py @@ -27,7 +27,6 @@ for version in versions: library = gapic.py_library('speech', version) - s.move(library / f'google/cloud/speech_{version}/speech') # Don't move over __init__.py, as we modify it to make the generated client # use helpers.py. s.move(library / f'google/cloud/speech_{version}/types.py') @@ -78,6 +77,14 @@ r'"\1-\\*"') +# Issues exist where python files should define the source encoding +# https://github.com/googleapis/gapic-generator/issues/2097 +s.replace( + '**/proto/*_pb2.py', + r"(^.*$\n)*", + r"# -*- coding: utf-8 -*-\n\g<0>") + + # Fix tests to use the direct gapic client instead of the wrapped helper # client. s.replace(