From 6a48f4f672d7fd1d20d656acea8b8a4ca41c396e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 18:13:33 -0500 Subject: [PATCH] feat: Added new fields to facilitate debugging (#465) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update to gapic-generator-python 1.5.0 feat: add support for `google.cloud..__version__` PiperOrigin-RevId: 484665853 Source-Link: https://github.com/googleapis/googleapis/commit/8eb249a19db926c2fbc4ecf1dc09c0e521a88b22 Source-Link: https://github.com/googleapis/googleapis-gen/commit/c8aa327b5f478865fc3fd91e3c2768e54e26ad44 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzhhYTMyN2I1ZjQ3ODg2NWZjM2ZkOTFlM2MyNzY4ZTU0ZTI2YWQ0NCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update version in gapic_version.py * chore: Update to gapic-generator-python 1.6.0 feat(python): Add typing to proto.Message based class attributes feat(python): Snippetgen handling of repeated enum field PiperOrigin-RevId: 487326846 Source-Link: https://github.com/googleapis/googleapis/commit/da380c77bb87ba0f752baf07605dd1db30e1f7e1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/61ef5762ee6731a0cbbfea22fd0eecee51ab1c8e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjFlZjU3NjJlZTY3MzFhMGNiYmZlYTIyZmQwZWVjZWU1MWFiMWM4ZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: new APIs added to reflect updates to the filestore service - Add ENTERPRISE Tier - Add snapshot APIs: RevertInstance, ListSnapshots, CreateSnapshot, DeleteSnapshot, UpdateSnapshot - Add multi-share APIs: ListShares, GetShare, CreateShare, DeleteShare, UpdateShare - Add ConnectMode to NetworkConfig (for Private Service Access support) - New status codes (SUSPENDED/SUSPENDING, REVERTING/RESUMING) - Add SuspensionReason (for KMS related suspension) - Add new fields to Instance information: max_capacity_gb, capacity_step_size_gb, max_share_count, capacity_gb, multi_share_enabled PiperOrigin-RevId: 487492758 Source-Link: https://github.com/googleapis/googleapis/commit/5be5981f50322cf0c7388595e0f31ac5d0693469 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ab0e217f560cc2c1afc11441c2eab6b6950efd2b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWIwZTIxN2Y1NjBjYzJjMWFmYzExNDQxYzJlYWI2YjY5NTBlZmQyYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Update gapic-generator-python to v1.6.1 PiperOrigin-RevId: 488036204 Source-Link: https://github.com/googleapis/googleapis/commit/08f275f5c1c0d99056e1cb68376323414459ee19 Source-Link: https://github.com/googleapis/googleapis-gen/commit/555c0945e60649e38739ae64bc45719cdf72178f Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTU1YzA5NDVlNjA2NDllMzg3MzlhZTY0YmM0NTcxOWNkZjcyMTc4ZiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Added new fields to facilitate debugging * Added new field to Speech response proto, to give more information to indicate whether, or not, Biasing was applied (eg. did Biasing application timed out). * Added request_id to Speech response protos. PiperOrigin-RevId: 492276727 Source-Link: https://github.com/googleapis/googleapis/commit/4c253358b1d4add3bf74707d5f58d44e044c5da8 Source-Link: https://github.com/googleapis/googleapis-gen/commit/f15b9aca7ac2bd40b20e6715188732d08fc7fe21 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE1YjlhY2E3YWMyYmQ0MGIyMGU2NzE1MTg4NzMyZDA4ZmM3ZmUyMSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: use templated setup.py and owlbot.py * fix(deps): Require google-api-core >=1.34.0, >=2.11.0 fix: Drop usage of pkg_resources fix: Fix timeout default values docs(samples): Snippetgen should call await on the operation coroutine before calling result PiperOrigin-RevId: 493260409 Source-Link: https://github.com/googleapis/googleapis/commit/fea43879f83a8d0dacc9353b3f75f8f46d37162f Source-Link: https://github.com/googleapis/googleapis-gen/commit/387b7344c7529ee44be84e613b19a820508c612b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzg3YjczNDRjNzUyOWVlNDRiZTg0ZTYxM2IxOWE4MjA1MDhjNjEyYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Added new fields to facilitate debugging * Added new field to Speech response proto, to give more information to indicate whether, or not, Biasing was applied (eg. did Biasing application timed out). * Added request_id to Speech response protos. PiperOrigin-RevId: 493311906 Source-Link: https://github.com/googleapis/googleapis/commit/c9b244b4f64f3841be796762e6f2c5f219c443f8 Source-Link: https://github.com/googleapis/googleapis-gen/commit/d63ac840dec854ee7acab7b52b15deaf819eae07 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDYzYWM4NDBkZWM4NTRlZTdhY2FiN2I1MmIxNWRlYWY4MTllYWUwNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add gapic_version.py * fix build Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .../google-cloud-python-speech/.coveragerc | 5 - .../.release-please-manifest.json | 4 + .../docs/speech_v1/types.rst | 1 - .../docs/speech_v1p1beta1/types.rst | 1 - .../docs/speech_v2/types.rst | 1 - .../google/cloud/speech/__init__.py | 6 + .../google/cloud/speech/gapic_version.py | 16 + .../google/cloud/speech_v1/__init__.py | 6 + .../google/cloud/speech_v1/gapic_version.py | 16 + .../services/adaptation/async_client.py | 251 +++++++--- .../speech_v1/services/adaptation/client.py | 237 +++++++-- .../services/adaptation/transports/base.py | 38 +- .../services/adaptation/transports/grpc.py | 57 ++- .../adaptation/transports/grpc_asyncio.py | 53 +- .../speech_v1/services/speech/async_client.py | 157 +++++- .../cloud/speech_v1/services/speech/client.py | 155 +++++- .../services/speech/transports/base.py | 38 +- .../services/speech/transports/grpc.py | 57 ++- .../speech/transports/grpc_asyncio.py | 53 +- .../google/cloud/speech_v1/types/__init__.py | 2 + .../cloud/speech_v1/types/cloud_speech.py | 256 ++++++---- .../types/cloud_speech_adaptation.py | 54 +- .../google/cloud/speech_v1/types/resource.py | 36 +- .../google/cloud/speech_v1p1beta1/__init__.py | 6 + .../cloud/speech_v1p1beta1/gapic_version.py | 16 + .../services/adaptation/async_client.py | 142 +++--- .../services/adaptation/client.py | 128 +++-- .../services/adaptation/transports/base.py | 16 +- .../services/adaptation/transports/grpc.py | 20 +- .../adaptation/transports/grpc_asyncio.py | 16 +- .../services/speech/async_client.py | 48 +- .../services/speech/client.py | 46 +- .../services/speech/transports/base.py | 16 +- .../services/speech/transports/grpc.py | 20 +- .../speech/transports/grpc_asyncio.py | 16 +- .../cloud/speech_v1p1beta1/types/__init__.py | 2 + .../speech_v1p1beta1/types/cloud_speech.py | 266 ++++++---- .../types/cloud_speech_adaptation.py | 54 +- .../cloud/speech_v1p1beta1/types/resource.py | 46 +- .../google/cloud/speech_v2/__init__.py | 4 + .../google/cloud/speech_v2/gapic_version.py | 16 + .../speech_v2/services/speech/async_client.py | 282 +++++------ .../cloud/speech_v2/services/speech/client.py | 216 ++++---- .../services/speech/transports/base.py | 16 +- .../services/speech/transports/grpc.py | 20 +- .../speech/transports/grpc_asyncio.py | 16 +- .../cloud/speech_v2/types/cloud_speech.py | 474 +++++++++--------- packages/google-cloud-python-speech/owlbot.py | 49 +- .../release-please-config.json | 37 ++ ...ppet_metadata_google.cloud.speech.v1.json} | 3 +- ...tadata_google.cloud.speech.v1p1beta1.json} | 3 +- ...ppet_metadata_google.cloud.speech.v2.json} | 7 +- ...ted_speech_long_running_recognize_async.py | 2 +- ...ted_speech_long_running_recognize_async.py | 2 +- ..._generated_speech_batch_recognize_async.py | 2 +- ...erated_speech_create_custom_class_async.py | 2 +- ...enerated_speech_create_phrase_set_async.py | 2 +- ...enerated_speech_create_recognizer_async.py | 2 +- ...erated_speech_delete_custom_class_async.py | 2 +- ...enerated_speech_delete_phrase_set_async.py | 2 +- ...enerated_speech_delete_recognizer_async.py | 2 +- ...ated_speech_undelete_custom_class_async.py | 2 +- ...erated_speech_undelete_phrase_set_async.py | 2 +- ...erated_speech_undelete_recognizer_async.py | 2 +- ...erated_speech_update_custom_class_async.py | 2 +- ...enerated_speech_update_phrase_set_async.py | 2 +- ...enerated_speech_update_recognizer_async.py | 2 +- .../samples/microphone/noxfile.py | 15 +- .../adaptation_v2_custom_class_reference.py | 14 +- ...aptation_v2_custom_class_reference_test.py | 10 +- .../adaptation_v2_inline_custom_class.py | 4 +- .../adaptation_v2_inline_phrase_set.py | 2 + .../adaptation_v2_phrase_set_reference.py | 9 +- .../samples/snippets/beta_snippets.py | 36 +- .../samples/snippets/create_recognizer.py | 2 + .../samples/snippets/noxfile.py | 15 +- .../samples/snippets/profanity_filter.py | 2 +- .../samples/snippets/quickstart_v2.py | 2 + .../snippets/speech_adaptation_beta.py | 2 +- .../snippets/speech_quickstart_beta.py | 2 +- .../snippets/speech_to_storage_beta.py | 2 +- .../samples/snippets/transcribe.py | 4 +- .../samples/snippets/transcribe_async_file.py | 2 +- .../samples/snippets/transcribe_async_gcs.py | 4 +- .../samples/snippets/transcribe_file_v2.py | 2 + .../samples/snippets/transcribe_gcs_v2.py | 2 + .../snippets/transcribe_model_selection.py | 4 +- .../snippets/transcribe_multichannel.py | 8 +- .../samples/snippets/transcribe_streaming.py | 2 +- .../snippets/transcribe_streaming_v2.py | 2 + ...nscribe_streaming_voice_activity_events.py | 2 + ...cribe_streaming_voice_activity_timeouts.py | 2 + packages/google-cloud-python-speech/setup.py | 49 +- .../testing/constraints-3.10.txt | 6 + .../testing/constraints-3.11.txt | 6 + .../testing/constraints-3.7.txt | 10 +- .../testing/constraints-3.8.txt | 6 + .../testing/constraints-3.9.txt | 6 + .../unit/gapic/speech_v1/test_adaptation.py | 293 +++++++++++ .../tests/unit/gapic/speech_v1/test_speech.py | 302 ++++++++++- .../gapic/speech_v1p1beta1/test_speech.py | 10 +- 101 files changed, 3018 insertions(+), 1352 deletions(-) create mode 100644 packages/google-cloud-python-speech/.release-please-manifest.json create mode 100644 packages/google-cloud-python-speech/google/cloud/speech/gapic_version.py create mode 100644 packages/google-cloud-python-speech/google/cloud/speech_v1/gapic_version.py create mode 100644 packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/gapic_version.py create mode 100644 packages/google-cloud-python-speech/google/cloud/speech_v2/gapic_version.py create mode 100644 packages/google-cloud-python-speech/release-please-config.json rename packages/google-cloud-python-speech/samples/generated_samples/{snippet_metadata_speech_v1.json => snippet_metadata_google.cloud.speech.v1.json} (99%) rename packages/google-cloud-python-speech/samples/generated_samples/{snippet_metadata_speech_v1p1beta1.json => snippet_metadata_google.cloud.speech.v1p1beta1.json} (99%) rename packages/google-cloud-python-speech/samples/generated_samples/{snippet_metadata_speech_v2.json => snippet_metadata_google.cloud.speech.v2.json} (99%) diff --git a/packages/google-cloud-python-speech/.coveragerc b/packages/google-cloud-python-speech/.coveragerc index f539ecf832d9..360a9a6f1e6a 100644 --- a/packages/google-cloud-python-speech/.coveragerc +++ b/packages/google-cloud-python-speech/.coveragerc @@ -10,8 +10,3 @@ exclude_lines = pragma: NO COVER # Ignore debug-only repr def __repr__ - # Ignore pkg_resources exceptions. - # This is added at the module level as a safeguard for if someone - # generates the code and tries to run it without pip installing. This - # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound diff --git a/packages/google-cloud-python-speech/.release-please-manifest.json b/packages/google-cloud-python-speech/.release-please-manifest.json new file mode 100644 index 000000000000..156b3a436547 --- /dev/null +++ b/packages/google-cloud-python-speech/.release-please-manifest.json @@ -0,0 +1,4 @@ +{ + ".": "2.16.2" +} + \ No newline at end of file diff --git a/packages/google-cloud-python-speech/docs/speech_v1/types.rst b/packages/google-cloud-python-speech/docs/speech_v1/types.rst index 1ca37b89bf0c..1f28fdd0aa78 100644 --- a/packages/google-cloud-python-speech/docs/speech_v1/types.rst +++ b/packages/google-cloud-python-speech/docs/speech_v1/types.rst @@ -3,5 +3,4 @@ Types for Google Cloud Speech v1 API .. automodule:: google.cloud.speech_v1.types :members: - :undoc-members: :show-inheritance: diff --git a/packages/google-cloud-python-speech/docs/speech_v1p1beta1/types.rst b/packages/google-cloud-python-speech/docs/speech_v1p1beta1/types.rst index 004a3819ebb2..96ebe607004a 100644 --- a/packages/google-cloud-python-speech/docs/speech_v1p1beta1/types.rst +++ b/packages/google-cloud-python-speech/docs/speech_v1p1beta1/types.rst @@ -3,5 +3,4 @@ Types for Google Cloud Speech v1p1beta1 API .. automodule:: google.cloud.speech_v1p1beta1.types :members: - :undoc-members: :show-inheritance: diff --git a/packages/google-cloud-python-speech/docs/speech_v2/types.rst b/packages/google-cloud-python-speech/docs/speech_v2/types.rst index 0b0ee74b7345..50b0560158fe 100644 --- a/packages/google-cloud-python-speech/docs/speech_v2/types.rst +++ b/packages/google-cloud-python-speech/docs/speech_v2/types.rst @@ -3,5 +3,4 @@ Types for Google Cloud Speech v2 API .. automodule:: google.cloud.speech_v2.types :members: - :undoc-members: :show-inheritance: diff --git a/packages/google-cloud-python-speech/google/cloud/speech/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech/__init__.py index 53015f4f37cd..f90dddcc2da3 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech/__init__.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.speech import gapic_version as package_version + +__version__ = package_version.__version__ + from google.cloud.speech_v1.services.adaptation.client import AdaptationClient from google.cloud.speech_v1.services.adaptation.async_client import ( @@ -30,6 +34,7 @@ from google.cloud.speech_v1.types.cloud_speech import RecognizeRequest from google.cloud.speech_v1.types.cloud_speech import RecognizeResponse from google.cloud.speech_v1.types.cloud_speech import SpeakerDiarizationConfig +from google.cloud.speech_v1.types.cloud_speech import SpeechAdaptationInfo from google.cloud.speech_v1.types.cloud_speech import SpeechContext from google.cloud.speech_v1.types.cloud_speech import SpeechRecognitionAlternative from google.cloud.speech_v1.types.cloud_speech import SpeechRecognitionResult @@ -79,6 +84,7 @@ "RecognizeRequest", "RecognizeResponse", "SpeakerDiarizationConfig", + "SpeechAdaptationInfo", "SpeechContext", "SpeechRecognitionAlternative", "SpeechRecognitionResult", diff --git a/packages/google-cloud-python-speech/google/cloud/speech/gapic_version.py b/packages/google-cloud-python-speech/google/cloud/speech/gapic_version.py new file mode 100644 index 000000000000..e1ac79787eb8 --- /dev/null +++ b/packages/google-cloud-python-speech/google/cloud/speech/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +__version__ = "2.16.2" # {x-release-please-version} diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/__init__.py index 1f859aeed3d6..ad5e60db2696 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/__init__.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.speech_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + from .services.adaptation import AdaptationClient from .services.adaptation import AdaptationAsyncClient @@ -28,6 +32,7 @@ from .types.cloud_speech import RecognizeRequest from .types.cloud_speech import RecognizeResponse from .types.cloud_speech import SpeakerDiarizationConfig +from .types.cloud_speech import SpeechAdaptationInfo from .types.cloud_speech import SpeechContext from .types.cloud_speech import SpeechRecognitionAlternative from .types.cloud_speech import SpeechRecognitionResult @@ -86,6 +91,7 @@ class SpeechClient(SpeechHelpers, SpeechClient): "RecognizeResponse", "SpeakerDiarizationConfig", "SpeechAdaptation", + "SpeechAdaptationInfo", "SpeechClient", "SpeechContext", "SpeechRecognitionAlternative", diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/gapic_version.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/gapic_version.py new file mode 100644 index 000000000000..e1ac79787eb8 --- /dev/null +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +__version__ = "2.16.2" # {x-release-please-version} diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/async_client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/async_client.py index dd95e360970a..8b8345c5b780 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/async_client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/async_client.py @@ -16,8 +16,19 @@ from collections import OrderedDict import functools import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) + +from google.cloud.speech_v1 import gapic_version as package_version from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions @@ -34,6 +45,7 @@ from google.cloud.speech_v1.services.adaptation import pagers from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import AdaptationTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AdaptationGrpcAsyncIOTransport @@ -156,9 +168,9 @@ def transport(self) -> AdaptationTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, AdaptationTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the adaptation client. @@ -202,13 +214,15 @@ def __init__( async def create_phrase_set( self, - request: Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] + ] = None, *, - parent: str = None, - phrase_set: resource.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[resource.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Create a set of phrase hints. Each item in the set @@ -244,7 +258,7 @@ async def sample_create_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1.types.CreatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.CreatePhraseSetRequest, dict]]): The request object. Message sent by the client for the `CreatePhraseSet` method. parent (:class:`str`): @@ -343,11 +357,13 @@ async def sample_create_phrase_set(): async def get_phrase_set( self, - request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Get a phrase set. @@ -379,7 +395,7 @@ async def sample_get_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1.types.GetPhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.GetPhraseSetRequest, dict]]): The request object. Message sent by the client for the `GetPhraseSet` method. name (:class:`str`): @@ -456,11 +472,13 @@ async def sample_get_phrase_set(): async def list_phrase_set( self, - request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetAsyncPager: r"""List phrase sets. @@ -493,7 +511,7 @@ async def sample_list_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1.types.ListPhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.ListPhraseSetRequest, dict]]): The request object. Message sent by the client for the `ListPhraseSet` method. parent (:class:`str`): @@ -581,12 +599,14 @@ async def sample_list_phrase_set(): async def update_phrase_set( self, - request: Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] + ] = None, *, - phrase_set: resource.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[resource.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Update a phrase set. @@ -617,7 +637,7 @@ async def sample_update_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1.types.UpdatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.UpdatePhraseSetRequest, dict]]): The request object. Message sent by the client for the `UpdatePhraseSet` method. phrase_set (:class:`google.cloud.speech_v1.types.PhraseSet`): @@ -705,11 +725,13 @@ async def sample_update_phrase_set(): async def delete_phrase_set( self, - request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a phrase set. @@ -738,7 +760,7 @@ async def sample_delete_phrase_set(): await client.delete_phrase_set(request=request) Args: - request (Union[google.cloud.speech_v1.types.DeletePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.DeletePhraseSetRequest, dict]]): The request object. Message sent by the client for the `DeletePhraseSet` method. name (:class:`str`): @@ -796,13 +818,15 @@ async def sample_delete_phrase_set(): async def create_custom_class( self, - request: Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] + ] = None, *, - parent: str = None, - custom_class: resource.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[resource.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Create a custom class. @@ -835,7 +859,7 @@ async def sample_create_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1.types.CreateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.CreateCustomClassRequest, dict]]): The request object. Message sent by the client for the `CreateCustomClass` method. parent (:class:`str`): @@ -938,11 +962,13 @@ async def sample_create_custom_class(): async def get_custom_class( self, - request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Get a custom class. @@ -974,7 +1000,7 @@ async def sample_get_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1.types.GetCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.GetCustomClassRequest, dict]]): The request object. Message sent by the client for the `GetCustomClass` method. name (:class:`str`): @@ -1047,11 +1073,13 @@ async def sample_get_custom_class(): async def list_custom_classes( self, - request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesAsyncPager: r"""List custom classes. @@ -1084,7 +1112,7 @@ async def sample_list_custom_classes(): print(response) Args: - request (Union[google.cloud.speech_v1.types.ListCustomClassesRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.ListCustomClassesRequest, dict]]): The request object. Message sent by the client for the `ListCustomClasses` method. parent (:class:`str`): @@ -1172,12 +1200,14 @@ async def sample_list_custom_classes(): async def update_custom_class( self, - request: Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] + ] = None, *, - custom_class: resource.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[resource.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Update a custom class. @@ -1208,7 +1238,7 @@ async def sample_update_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1.types.UpdateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.UpdateCustomClassRequest, dict]]): The request object. Message sent by the client for the `UpdateCustomClass` method. custom_class (:class:`google.cloud.speech_v1.types.CustomClass`): @@ -1300,11 +1330,13 @@ async def sample_update_custom_class(): async def delete_custom_class( self, - request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a custom class. @@ -1333,7 +1365,7 @@ async def sample_delete_custom_class(): await client.delete_custom_class(request=request) Args: - request (Union[google.cloud.speech_v1.types.DeleteCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.DeleteCustomClassRequest, dict]]): The request object. Message sent by the client for the `DeleteCustomClass` method. name (:class:`str`): @@ -1398,6 +1430,114 @@ async def sample_delete_custom_class(): metadata=metadata, ) + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def __aenter__(self): return self @@ -1405,14 +1545,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("AdaptationAsyncClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/client.py index 93edbcf3d000..e4dc62b644a8 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/client.py @@ -16,8 +16,20 @@ from collections import OrderedDict import os import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) + +from google.cloud.speech_v1 import gapic_version as package_version from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -37,6 +49,7 @@ from google.cloud.speech_v1.services.adaptation import pagers from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import AdaptationTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AdaptationGrpcTransport @@ -57,7 +70,7 @@ class AdaptationClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[AdaptationTransport]: """Returns an appropriate transport class. @@ -354,8 +367,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, AdaptationTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, AdaptationTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the adaptation client. @@ -369,7 +382,7 @@ def __init__( transport (Union[str, AdaptationTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -399,6 +412,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -451,13 +465,15 @@ def __init__( def create_phrase_set( self, - request: Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] + ] = None, *, - parent: str = None, - phrase_set: resource.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[resource.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Create a set of phrase hints. Each item in the set @@ -592,11 +608,13 @@ def sample_create_phrase_set(): def get_phrase_set( self, - request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Get a phrase set. @@ -705,11 +723,13 @@ def sample_get_phrase_set(): def list_phrase_set( self, - request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetPager: r"""List phrase sets. @@ -830,12 +850,14 @@ def sample_list_phrase_set(): def update_phrase_set( self, - request: Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] + ] = None, *, - phrase_set: resource.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[resource.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Update a phrase set. @@ -954,11 +976,13 @@ def sample_update_phrase_set(): def delete_phrase_set( self, - request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a phrase set. @@ -1045,13 +1069,15 @@ def sample_delete_phrase_set(): def create_custom_class( self, - request: Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] + ] = None, *, - parent: str = None, - custom_class: resource.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[resource.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Create a custom class. @@ -1187,11 +1213,13 @@ def sample_create_custom_class(): def get_custom_class( self, - request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Get a custom class. @@ -1296,11 +1324,13 @@ def sample_get_custom_class(): def list_custom_classes( self, - request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesPager: r"""List custom classes. @@ -1421,12 +1451,14 @@ def sample_list_custom_classes(): def update_custom_class( self, - request: Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] + ] = None, *, - custom_class: resource.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[resource.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Update a custom class. @@ -1549,11 +1581,13 @@ def sample_update_custom_class(): def delete_custom_class( self, - request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a custom class. @@ -1660,15 +1694,118 @@ def __exit__(self, type, value, traceback): """ self.transport.close() + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("AdaptationClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/base.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/base.py index bd4399d0330d..328b05214bbd 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/base.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/base.py @@ -15,7 +15,8 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources + +from google.cloud.speech_v1 import gapic_version as package_version import google.auth # type: ignore import google.api_core @@ -27,16 +28,12 @@ from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class AdaptationTransport(abc.ABC): @@ -50,7 +47,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -286,6 +283,27 @@ def delete_custom_class( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc.py index 8fa5386ff99b..12acf610059c 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc.py @@ -26,6 +26,7 @@ from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from .base import AdaptationTransport, DEFAULT_CLIENT_INFO @@ -49,14 +50,14 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -183,8 +184,8 @@ def __init__( def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, @@ -509,6 +510,42 @@ def delete_custom_class( def close(self): self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + @property def kind(self) -> str: return "grpc" diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc_asyncio.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc_asyncio.py index 3cc316eebc74..f27c5bf0f585 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc_asyncio.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/adaptation/transports/grpc_asyncio.py @@ -26,6 +26,7 @@ from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from .base import AdaptationTransport, DEFAULT_CLIENT_INFO from .grpc import AdaptationGrpcTransport @@ -51,7 +52,7 @@ class AdaptationGrpcAsyncIOTransport(AdaptationTransport): def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -94,15 +95,15 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, @@ -524,5 +525,41 @@ def delete_custom_class( def close(self): return self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + __all__ = ("AdaptationGrpcAsyncIOTransport",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/async_client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/async_client.py index 8acf92469fdd..1594b3b07ed2 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/async_client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/async_client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, AsyncIterable, Awaitable, @@ -28,7 +30,8 @@ Type, Union, ) -import pkg_resources + +from google.cloud.speech_v1 import gapic_version as package_version from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions @@ -45,6 +48,7 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1.types import cloud_speech +from google.longrunning import operations_pb2 from google.protobuf import duration_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from .transports.base import SpeechTransport, DEFAULT_CLIENT_INFO @@ -164,9 +168,9 @@ def transport(self) -> SpeechTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, SpeechTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -210,12 +214,12 @@ def __init__( async def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous speech recognition: receive @@ -255,7 +259,7 @@ async def sample_recognize(): print(response) Args: - request (Union[google.cloud.speech_v1.types.RecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.RecognizeRequest, dict]]): The request object. The top-level message sent by the client for the `Recognize` method. config (:class:`google.cloud.speech_v1.types.RecognitionConfig`): @@ -336,12 +340,12 @@ async def sample_recognize(): async def long_running_recognize( self, - request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.LongRunningRecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Performs asynchronous speech recognition: receive results via @@ -383,13 +387,13 @@ async def sample_long_running_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v1.types.LongRunningRecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v1.types.LongRunningRecognizeRequest, dict]]): The request object. The top-level message sent by the client for the `LongRunningRecognize` method. config (:class:`google.cloud.speech_v1.types.RecognitionConfig`): @@ -473,10 +477,12 @@ async def sample_long_running_recognize(): def streaming_recognize( self, - requests: AsyncIterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[ + AsyncIterator[cloud_speech.StreamingRecognizeRequest] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]: r"""Performs bidirectional streaming speech recognition: @@ -632,6 +638,114 @@ def request_generator(): # Done; return the response. return response + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def __aenter__(self): return self @@ -639,14 +753,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechAsyncClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/client.py index 5fea47b06920..d630bd9c79dd 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, Iterable, Iterator, @@ -26,8 +28,10 @@ Tuple, Type, Union, + cast, ) -import pkg_resources + +from google.cloud.speech_v1 import gapic_version as package_version from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -47,6 +51,7 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1.types import cloud_speech +from google.longrunning import operations_pb2 from google.protobuf import duration_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from .transports.base import SpeechTransport, DEFAULT_CLIENT_INFO @@ -68,7 +73,7 @@ class SpeechClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[SpeechTransport]: """Returns an appropriate transport class. @@ -365,8 +370,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, SpeechTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, SpeechTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -380,7 +385,7 @@ def __init__( transport (Union[str, SpeechTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -410,6 +415,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -462,12 +468,12 @@ def __init__( def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous speech recognition: receive @@ -578,12 +584,12 @@ def sample_recognize(): def long_running_recognize( self, - request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.LongRunningRecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Performs asynchronous speech recognition: receive results via @@ -715,10 +721,10 @@ def sample_long_running_recognize(): def streaming_recognize( self, - requests: Iterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[Iterator[cloud_speech.StreamingRecognizeRequest]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[cloud_speech.StreamingRecognizeResponse]: r"""Performs bidirectional streaming speech recognition: @@ -873,15 +879,118 @@ def __exit__(self, type, value, traceback): """ self.transport.close() + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/base.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/base.py index 1b0d7c6f4b19..9d7797221757 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/base.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/base.py @@ -15,7 +15,8 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources + +from google.cloud.speech_v1 import gapic_version as package_version import google.auth # type: ignore import google.api_core @@ -27,16 +28,12 @@ from google.oauth2 import service_account # type: ignore from google.cloud.speech_v1.types import cloud_speech +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class SpeechTransport(abc.ABC): @@ -50,7 +47,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -212,6 +209,27 @@ def streaming_recognize( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc.py index 5e51990b1711..c61906be36ba 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc.py @@ -26,6 +26,7 @@ import grpc # type: ignore from google.cloud.speech_v1.types import cloud_speech +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpeechTransport, DEFAULT_CLIENT_INFO @@ -49,14 +50,14 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -184,8 +185,8 @@ def __init__( def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, @@ -338,6 +339,42 @@ def streaming_recognize( def close(self): self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + @property def kind(self) -> str: return "grpc" diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py index 820afcff12c3..f86f2bdc90fa 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py @@ -26,6 +26,7 @@ from grpc.experimental import aio # type: ignore from google.cloud.speech_v1.types import cloud_speech +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpeechTransport, DEFAULT_CLIENT_INFO from .grpc import SpeechGrpcTransport @@ -51,7 +52,7 @@ class SpeechGrpcAsyncIOTransport(SpeechTransport): def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -94,15 +95,15 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, @@ -347,5 +348,41 @@ def streaming_recognize( def close(self): return self.grpc_channel.close() + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + __all__ = ("SpeechGrpcAsyncIOTransport",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/__init__.py index 3f46f2e1590d..e5079288eb5b 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/__init__.py @@ -23,6 +23,7 @@ RecognizeRequest, RecognizeResponse, SpeakerDiarizationConfig, + SpeechAdaptationInfo, SpeechContext, SpeechRecognitionAlternative, SpeechRecognitionResult, @@ -63,6 +64,7 @@ "RecognizeRequest", "RecognizeResponse", "SpeakerDiarizationConfig", + "SpeechAdaptationInfo", "SpeechContext", "SpeechRecognitionAlternative", "SpeechRecognitionResult", diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech.py index 9047143c216d..9ee86321b037 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore from google.cloud.speech_v1.types import resource @@ -43,6 +45,7 @@ "SpeechRecognitionResult", "SpeechRecognitionAlternative", "WordInfo", + "SpeechAdaptationInfo", }, ) @@ -60,12 +63,12 @@ class RecognizeRequest(proto.Message): Required. The audio data to be recognized. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - audio = proto.Field( + audio: "RecognitionAudio" = proto.Field( proto.MESSAGE, number=2, message="RecognitionAudio", @@ -88,17 +91,17 @@ class LongRunningRecognizeRequest(proto.Message): for the recognition results. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - audio = proto.Field( + audio: "RecognitionAudio" = proto.Field( proto.MESSAGE, number=2, message="RecognitionAudio", ) - output_config = proto.Field( + output_config: "TranscriptOutputConfig" = proto.Field( proto.MESSAGE, number=4, message="TranscriptOutputConfig", @@ -122,7 +125,7 @@ class TranscriptOutputConfig(proto.Message): This field is a member of `oneof`_ ``output_type``. """ - gcs_uri = proto.Field( + gcs_uri: str = proto.Field( proto.STRING, number=1, oneof="output_type", @@ -167,13 +170,13 @@ class StreamingRecognizeRequest(proto.Message): This field is a member of `oneof`_ ``streaming_request``. """ - streaming_config = proto.Field( + streaming_config: "StreamingRecognitionConfig" = proto.Field( proto.MESSAGE, number=1, oneof="streaming_request", message="StreamingRecognitionConfig", ) - audio_content = proto.Field( + audio_content: bytes = proto.Field( proto.BYTES, number=2, oneof="streaming_request", @@ -222,16 +225,16 @@ class StreamingRecognitionConfig(proto.Message): omitted, only ``is_final=true`` result(s) are returned. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - single_utterance = proto.Field( + single_utterance: bool = proto.Field( proto.BOOL, number=2, ) - interim_results = proto.Field( + interim_results: bool = proto.Field( proto.BOOL, number=3, ) @@ -261,12 +264,11 @@ class RecognitionConfig(proto.Message): audio_channel_count (int): 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 + LINEAR16, OGG_OPUS and FLAC are ``1``-``8``. 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 (bool): This needs to be set to ``true`` explicitly and @@ -283,7 +285,7 @@ class RecognitionConfig(proto.Message): language tag. Example: "en-US". See `Language Support `__ for a list of the currently supported language codes. - alternative_language_codes (Sequence[str]): + alternative_language_codes (MutableSequence[str]): A list of up to 3 additional `BCP-47 `__ language tags, listing possible alternative languages of the @@ -316,7 +318,7 @@ class RecognitionConfig(proto.Message): adaptation `__ documentation. When speech adaptation is set it supersedes the ``speech_contexts`` field. - speech_contexts (Sequence[google.cloud.speech_v1.types.SpeechContext]): + speech_contexts (MutableSequence[google.cloud.speech_v1.types.SpeechContext]): Array of [SpeechContext][google.cloud.speech.v1.SpeechContext]. A means to provide context to assist the speech recognition. @@ -475,86 +477,86 @@ class AudioEncoding(proto.Enum): SPEEX_WITH_HEADER_BYTE = 7 WEBM_OPUS = 9 - encoding = proto.Field( + encoding: AudioEncoding = proto.Field( proto.ENUM, number=1, enum=AudioEncoding, ) - sample_rate_hertz = proto.Field( + sample_rate_hertz: int = proto.Field( proto.INT32, number=2, ) - audio_channel_count = proto.Field( + audio_channel_count: int = proto.Field( proto.INT32, number=7, ) - enable_separate_recognition_per_channel = proto.Field( + enable_separate_recognition_per_channel: bool = proto.Field( proto.BOOL, number=12, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=3, ) - alternative_language_codes = proto.RepeatedField( + alternative_language_codes: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=18, ) - max_alternatives = proto.Field( + max_alternatives: int = proto.Field( proto.INT32, number=4, ) - profanity_filter = proto.Field( + profanity_filter: bool = proto.Field( proto.BOOL, number=5, ) - adaptation = proto.Field( + adaptation: resource.SpeechAdaptation = proto.Field( proto.MESSAGE, number=20, message=resource.SpeechAdaptation, ) - speech_contexts = proto.RepeatedField( + speech_contexts: MutableSequence["SpeechContext"] = proto.RepeatedField( proto.MESSAGE, number=6, message="SpeechContext", ) - enable_word_time_offsets = proto.Field( + enable_word_time_offsets: bool = proto.Field( proto.BOOL, number=8, ) - enable_word_confidence = proto.Field( + enable_word_confidence: bool = proto.Field( proto.BOOL, number=15, ) - enable_automatic_punctuation = proto.Field( + enable_automatic_punctuation: bool = proto.Field( proto.BOOL, number=11, ) - enable_spoken_punctuation = proto.Field( + enable_spoken_punctuation: wrappers_pb2.BoolValue = proto.Field( proto.MESSAGE, number=22, message=wrappers_pb2.BoolValue, ) - enable_spoken_emojis = proto.Field( + enable_spoken_emojis: wrappers_pb2.BoolValue = proto.Field( proto.MESSAGE, number=23, message=wrappers_pb2.BoolValue, ) - diarization_config = proto.Field( + diarization_config: "SpeakerDiarizationConfig" = proto.Field( proto.MESSAGE, number=19, message="SpeakerDiarizationConfig", ) - metadata = proto.Field( + metadata: "RecognitionMetadata" = proto.Field( proto.MESSAGE, number=9, message="RecognitionMetadata", ) - model = proto.Field( + model: str = proto.Field( proto.STRING, number=13, ) - use_enhanced = proto.Field( + use_enhanced: bool = proto.Field( proto.BOOL, number=14, ) @@ -584,19 +586,19 @@ class SpeakerDiarizationConfig(proto.Message): Output only. Unused. """ - enable_speaker_diarization = proto.Field( + enable_speaker_diarization: bool = proto.Field( proto.BOOL, number=1, ) - min_speaker_count = proto.Field( + min_speaker_count: int = proto.Field( proto.INT32, number=2, ) - max_speaker_count = proto.Field( + max_speaker_count: int = proto.Field( proto.INT32, number=3, ) - speaker_tag = proto.Field( + speaker_tag: int = proto.Field( proto.INT32, number=5, ) @@ -680,39 +682,39 @@ class RecordingDeviceType(proto.Enum): OTHER_OUTDOOR_DEVICE = 5 OTHER_INDOOR_DEVICE = 6 - interaction_type = proto.Field( + interaction_type: InteractionType = proto.Field( proto.ENUM, number=1, enum=InteractionType, ) - industry_naics_code_of_audio = proto.Field( + industry_naics_code_of_audio: int = proto.Field( proto.UINT32, number=3, ) - microphone_distance = proto.Field( + microphone_distance: MicrophoneDistance = proto.Field( proto.ENUM, number=4, enum=MicrophoneDistance, ) - original_media_type = proto.Field( + original_media_type: OriginalMediaType = proto.Field( proto.ENUM, number=5, enum=OriginalMediaType, ) - recording_device_type = proto.Field( + recording_device_type: RecordingDeviceType = proto.Field( proto.ENUM, number=6, enum=RecordingDeviceType, ) - recording_device_name = proto.Field( + recording_device_name: str = proto.Field( proto.STRING, number=7, ) - original_mime_type = proto.Field( + original_mime_type: str = proto.Field( proto.STRING, number=8, ) - audio_topic = proto.Field( + audio_topic: str = proto.Field( proto.STRING, number=10, ) @@ -723,7 +725,7 @@ class SpeechContext(proto.Message): words and phrases in the results. Attributes: - phrases (Sequence[str]): + phrases (MutableSequence[str]): A list of strings containing words and phrases "hints" so that the speech recognition is more likely to recognize them. This can be used to improve the accuracy for specific @@ -752,11 +754,11 @@ class SpeechContext(proto.Message): optimal value for your use case. """ - phrases = proto.RepeatedField( + phrases: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=1, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=4, ) @@ -799,12 +801,12 @@ class RecognitionAudio(proto.Message): This field is a member of `oneof`_ ``audio_source``. """ - content = proto.Field( + content: bytes = proto.Field( proto.BYTES, number=1, oneof="audio_source", ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=2, oneof="audio_source", @@ -817,24 +819,39 @@ class RecognizeResponse(proto.Message): ``SpeechRecognitionResult`` messages. Attributes: - results (Sequence[google.cloud.speech_v1.types.SpeechRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1.types.SpeechRecognitionResult]): Sequential list of transcription results corresponding to sequential portions of audio. total_billed_time (google.protobuf.duration_pb2.Duration): When available, billed audio seconds for the corresponding request. + speech_adaptation_info (google.cloud.speech_v1.types.SpeechAdaptationInfo): + Provides information on adaptation behavior + in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ - results = proto.RepeatedField( + results: MutableSequence["SpeechRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="SpeechRecognitionResult", ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=3, message=duration_pb2.Duration, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=7, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=8, + ) class LongRunningRecognizeResponse(proto.Message): @@ -846,7 +863,7 @@ class LongRunningRecognizeResponse(proto.Message): service. Attributes: - results (Sequence[google.cloud.speech_v1.types.SpeechRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1.types.SpeechRecognitionResult]): Sequential list of transcription results corresponding to sequential portions of audio. total_billed_time (google.protobuf.duration_pb2.Duration): @@ -858,28 +875,43 @@ class LongRunningRecognizeResponse(proto.Message): output_error (google.rpc.status_pb2.Status): If the transcript output fails this field contains the relevant error. + speech_adaptation_info (google.cloud.speech_v1.types.SpeechAdaptationInfo): + Provides information on speech adaptation + behavior in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ - results = proto.RepeatedField( + results: MutableSequence["SpeechRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="SpeechRecognitionResult", ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=3, message=duration_pb2.Duration, ) - output_config = proto.Field( + output_config: "TranscriptOutputConfig" = proto.Field( proto.MESSAGE, number=6, message="TranscriptOutputConfig", ) - output_error = proto.Field( + output_error: status_pb2.Status = proto.Field( proto.MESSAGE, number=7, message=status_pb2.Status, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=8, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=9, + ) class LongRunningRecognizeMetadata(proto.Message): @@ -903,21 +935,21 @@ class LongRunningRecognizeMetadata(proto.Message): content. """ - progress_percent = proto.Field( + progress_percent: int = proto.Field( proto.INT32, number=1, ) - start_time = proto.Field( + start_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) - last_update_time = proto.Field( + last_update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=4, ) @@ -981,7 +1013,7 @@ class StreamingRecognizeResponse(proto.Message): error (google.rpc.status_pb2.Status): If set, returns a [google.rpc.Status][google.rpc.Status] message that specifies the error for the operation. - results (Sequence[google.cloud.speech_v1.types.StreamingRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1.types.StreamingRecognitionResult]): This repeated list contains zero or more results that correspond to consecutive portions of the audio currently being processed. It contains zero or one ``is_final=true`` @@ -993,6 +1025,12 @@ class StreamingRecognizeResponse(proto.Message): When available, billed audio seconds for the stream. Set only if this is the last response in the stream. + speech_adaptation_info (google.cloud.speech_v1.types.SpeechAdaptationInfo): + Provides information on adaptation behavior + in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ class SpeechEventType(proto.Enum): @@ -1000,26 +1038,35 @@ class SpeechEventType(proto.Enum): SPEECH_EVENT_UNSPECIFIED = 0 END_OF_SINGLE_UTTERANCE = 1 - error = proto.Field( + error: status_pb2.Status = proto.Field( proto.MESSAGE, number=1, message=status_pb2.Status, ) - results = proto.RepeatedField( + results: MutableSequence["StreamingRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="StreamingRecognitionResult", ) - speech_event_type = proto.Field( + speech_event_type: SpeechEventType = proto.Field( proto.ENUM, number=4, enum=SpeechEventType, ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=5, message=duration_pb2.Duration, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=9, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=10, + ) class StreamingRecognitionResult(proto.Message): @@ -1027,7 +1074,7 @@ class StreamingRecognitionResult(proto.Message): portion of the audio that is currently being processed. Attributes: - alternatives (Sequence[google.cloud.speech_v1.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v1.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses (up to the maximum specified in ``max_alternatives``). These alternatives are ordered in terms of accuracy, with the top @@ -1063,29 +1110,29 @@ class StreamingRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - is_final = proto.Field( + is_final: bool = proto.Field( proto.BOOL, number=2, ) - stability = proto.Field( + stability: float = proto.Field( proto.FLOAT, number=3, ) - result_end_time = proto.Field( + result_end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=5, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=6, ) @@ -1096,7 +1143,7 @@ class SpeechRecognitionResult(proto.Message): audio. Attributes: - alternatives (Sequence[google.cloud.speech_v1.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v1.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses (up to the maximum specified in ``max_alternatives``). These alternatives are ordered in terms of accuracy, with the top @@ -1118,21 +1165,21 @@ class SpeechRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=2, ) - result_end_time = proto.Field( + result_end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=5, ) @@ -1158,21 +1205,21 @@ class SpeechRecognitionAlternative(proto.Message): 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. - words (Sequence[google.cloud.speech_v1.types.WordInfo]): + words (MutableSequence[google.cloud.speech_v1.types.WordInfo]): A list of word-specific information for each recognized word. Note: When ``enable_speaker_diarization`` is true, you will see all the words from the beginning of the audio. """ - transcript = proto.Field( + transcript: str = proto.Field( proto.STRING, number=1, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=2, ) - words = proto.RepeatedField( + words: MutableSequence["WordInfo"] = proto.RepeatedField( proto.MESSAGE, number=3, message="WordInfo", @@ -1216,28 +1263,51 @@ class WordInfo(proto.Message): top alternative. """ - start_time = proto.Field( + start_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=1, message=duration_pb2.Duration, ) - end_time = proto.Field( + end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=2, message=duration_pb2.Duration, ) - word = proto.Field( + word: str = proto.Field( proto.STRING, number=3, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=4, ) - speaker_tag = proto.Field( + speaker_tag: int = proto.Field( proto.INT32, number=5, ) +class SpeechAdaptationInfo(proto.Message): + r"""Information on speech adaptation use in results + + Attributes: + adaptation_timeout (bool): + Whether there was a timeout when applying + speech adaptation. If true, adaptation had no + effect in the response transcript. + timeout_message (str): + If set, returns a message specifying which + part of the speech adaptation request timed out. + """ + + adaptation_timeout: bool = proto.Field( + proto.BOOL, + number=1, + ) + timeout_message: str = proto.Field( + proto.STRING, + number=4, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech_adaptation.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech_adaptation.py index b854dc1a054f..d2d9a6308cb9 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech_adaptation.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/cloud_speech_adaptation.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore from google.cloud.speech_v1.types import resource @@ -66,15 +68,15 @@ class CreatePhraseSetRequest(proto.Message): Required. The phrase set to create. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - phrase_set_id = proto.Field( + phrase_set_id: str = proto.Field( proto.STRING, number=2, ) - phrase_set = proto.Field( + phrase_set: resource.PhraseSet = proto.Field( proto.MESSAGE, number=3, message=resource.PhraseSet, @@ -103,12 +105,12 @@ class UpdatePhraseSetRequest(proto.Message): The list of fields to be updated. """ - phrase_set = proto.Field( + phrase_set: resource.PhraseSet = proto.Field( proto.MESSAGE, number=1, message=resource.PhraseSet, ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, @@ -132,7 +134,7 @@ class GetPhraseSetRequest(proto.Message): with matching ``us`` or ``eu`` location value. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -169,15 +171,15 @@ class ListPhraseSetRequest(proto.Message): token. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -187,7 +189,7 @@ class ListPhraseSetResponse(proto.Message): r"""Message returned to the client by the ``ListPhraseSet`` method. Attributes: - phrase_sets (Sequence[google.cloud.speech_v1.types.PhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v1.types.PhraseSet]): The phrase set. next_page_token (str): A token, which can be sent as ``page_token`` to retrieve the @@ -199,12 +201,12 @@ class ListPhraseSetResponse(proto.Message): def raw_page(self): return self - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence[resource.PhraseSet] = proto.RepeatedField( proto.MESSAGE, number=1, message=resource.PhraseSet, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -220,7 +222,7 @@ class DeletePhraseSetRequest(proto.Message): ``projects/{project}/locations/{location}/phraseSets/{phrase_set}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -254,15 +256,15 @@ class CreateCustomClassRequest(proto.Message): Required. The custom class to create. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - custom_class_id = proto.Field( + custom_class_id: str = proto.Field( proto.STRING, number=2, ) - custom_class = proto.Field( + custom_class: resource.CustomClass = proto.Field( proto.MESSAGE, number=3, message=resource.CustomClass, @@ -291,12 +293,12 @@ class UpdateCustomClassRequest(proto.Message): The list of fields to be updated. """ - custom_class = proto.Field( + custom_class: resource.CustomClass = proto.Field( proto.MESSAGE, number=1, message=resource.CustomClass, ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, @@ -313,7 +315,7 @@ class GetCustomClassRequest(proto.Message): ``projects/{project}/locations/{location}/customClasses/{custom_class}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -350,15 +352,15 @@ class ListCustomClassesRequest(proto.Message): page token. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -368,7 +370,7 @@ class ListCustomClassesResponse(proto.Message): r"""Message returned to the client by the ``ListCustomClasses`` method. Attributes: - custom_classes (Sequence[google.cloud.speech_v1.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v1.types.CustomClass]): The custom classes. next_page_token (str): A token, which can be sent as ``page_token`` to retrieve the @@ -380,12 +382,12 @@ class ListCustomClassesResponse(proto.Message): def raw_page(self): return self - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence[resource.CustomClass] = proto.RepeatedField( proto.MESSAGE, number=1, message=resource.CustomClass, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -408,7 +410,7 @@ class DeleteCustomClassRequest(proto.Message): with matching ``us`` or ``eu`` location value. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/resource.py b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/resource.py index 7f208b90dc53..5a2bed82b248 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1/types/resource.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1/types/resource.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore @@ -38,7 +40,7 @@ class CustomClass(proto.Message): custom_class_id (str): If this custom class is a resource, the custom_class_id is the resource id of the CustomClass. Case sensitive. - items (Sequence[google.cloud.speech_v1.types.CustomClass.ClassItem]): + items (MutableSequence[google.cloud.speech_v1.types.CustomClass.ClassItem]): A collection of class items. """ @@ -50,20 +52,20 @@ class ClassItem(proto.Message): The class item's value. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - custom_class_id = proto.Field( + custom_class_id: str = proto.Field( proto.STRING, number=2, ) - items = proto.RepeatedField( + items: MutableSequence[ClassItem] = proto.RepeatedField( proto.MESSAGE, number=3, message=ClassItem, @@ -77,7 +79,7 @@ class PhraseSet(proto.Message): Attributes: name (str): The resource name of the phrase set. - phrases (Sequence[google.cloud.speech_v1.types.PhraseSet.Phrase]): + phrases (MutableSequence[google.cloud.speech_v1.types.PhraseSet.Phrase]): A list of word and phrases. boost (float): Hint Boost. Positive value will increase the probability @@ -141,25 +143,25 @@ class Phrase(proto.Message): of 0. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=2, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - phrases = proto.RepeatedField( + phrases: MutableSequence[Phrase] = proto.RepeatedField( proto.MESSAGE, number=2, message=Phrase, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=4, ) @@ -169,14 +171,14 @@ class SpeechAdaptation(proto.Message): r"""Speech adaptation configuration. Attributes: - phrase_sets (Sequence[google.cloud.speech_v1.types.PhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v1.types.PhraseSet]): A collection of phrase sets. To specify the hints inline, leave the phrase set's ``name`` blank and fill in the rest of its fields. Any phrase set can use any custom class. - phrase_set_references (Sequence[str]): + phrase_set_references (MutableSequence[str]): A collection of phrase set resource names to use. - custom_classes (Sequence[google.cloud.speech_v1.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v1.types.CustomClass]): A collection of custom classes. To specify the classes inline, leave the class' ``name`` blank and fill in the rest of its fields, giving it a unique ``custom_class_id``. Refer @@ -184,16 +186,16 @@ class SpeechAdaptation(proto.Message): ``custom_class_id``. """ - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence["PhraseSet"] = proto.RepeatedField( proto.MESSAGE, number=1, message="PhraseSet", ) - phrase_set_references = proto.RepeatedField( + phrase_set_references: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=2, ) - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence["CustomClass"] = proto.RepeatedField( proto.MESSAGE, number=3, message="CustomClass", diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py index b30221262561..9af6f9c5ad05 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.speech_v1p1beta1 import gapic_version as package_version + +__version__ = package_version.__version__ + from .services.adaptation import AdaptationClient from .services.adaptation import AdaptationAsyncClient @@ -28,6 +32,7 @@ from .types.cloud_speech import RecognizeRequest from .types.cloud_speech import RecognizeResponse from .types.cloud_speech import SpeakerDiarizationConfig +from .types.cloud_speech import SpeechAdaptationInfo from .types.cloud_speech import SpeechContext from .types.cloud_speech import SpeechRecognitionAlternative from .types.cloud_speech import SpeechRecognitionResult @@ -87,6 +92,7 @@ class SpeechClient(SpeechHelpers, SpeechClient): "RecognizeResponse", "SpeakerDiarizationConfig", "SpeechAdaptation", + "SpeechAdaptationInfo", "SpeechClient", "SpeechContext", "SpeechRecognitionAlternative", diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/gapic_version.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/gapic_version.py new file mode 100644 index 000000000000..e1ac79787eb8 --- /dev/null +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +__version__ = "2.16.2" # {x-release-please-version} diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py index ecbc2a1dfccd..1fdf0ae5b691 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py @@ -16,8 +16,19 @@ from collections import OrderedDict import functools import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions @@ -156,9 +167,9 @@ def transport(self) -> AdaptationTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, AdaptationTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the adaptation client. @@ -202,13 +213,15 @@ def __init__( async def create_phrase_set( self, - request: Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] + ] = None, *, - parent: str = None, - phrase_set: resource.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[resource.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Create a set of phrase hints. Each item in the set @@ -244,7 +257,7 @@ async def sample_create_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.CreatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.CreatePhraseSetRequest, dict]]): The request object. Message sent by the client for the `CreatePhraseSet` method. parent (:class:`str`): @@ -343,11 +356,13 @@ async def sample_create_phrase_set(): async def get_phrase_set( self, - request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Get a phrase set. @@ -379,7 +394,7 @@ async def sample_get_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.GetPhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.GetPhraseSetRequest, dict]]): The request object. Message sent by the client for the `GetPhraseSet` method. name (:class:`str`): @@ -456,11 +471,13 @@ async def sample_get_phrase_set(): async def list_phrase_set( self, - request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetAsyncPager: r"""List phrase sets. @@ -493,7 +510,7 @@ async def sample_list_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.ListPhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.ListPhraseSetRequest, dict]]): The request object. Message sent by the client for the `ListPhraseSet` method. parent (:class:`str`): @@ -581,12 +598,14 @@ async def sample_list_phrase_set(): async def update_phrase_set( self, - request: Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] + ] = None, *, - phrase_set: resource.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[resource.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Update a phrase set. @@ -617,7 +636,7 @@ async def sample_update_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.UpdatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.UpdatePhraseSetRequest, dict]]): The request object. Message sent by the client for the `UpdatePhraseSet` method. phrase_set (:class:`google.cloud.speech_v1p1beta1.types.PhraseSet`): @@ -705,11 +724,13 @@ async def sample_update_phrase_set(): async def delete_phrase_set( self, - request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a phrase set. @@ -738,7 +759,7 @@ async def sample_delete_phrase_set(): await client.delete_phrase_set(request=request) Args: - request (Union[google.cloud.speech_v1p1beta1.types.DeletePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.DeletePhraseSetRequest, dict]]): The request object. Message sent by the client for the `DeletePhraseSet` method. name (:class:`str`): @@ -796,13 +817,15 @@ async def sample_delete_phrase_set(): async def create_custom_class( self, - request: Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] + ] = None, *, - parent: str = None, - custom_class: resource.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[resource.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Create a custom class. @@ -835,7 +858,7 @@ async def sample_create_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.CreateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.CreateCustomClassRequest, dict]]): The request object. Message sent by the client for the `CreateCustomClass` method. parent (:class:`str`): @@ -938,11 +961,13 @@ async def sample_create_custom_class(): async def get_custom_class( self, - request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Get a custom class. @@ -974,7 +999,7 @@ async def sample_get_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.GetCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.GetCustomClassRequest, dict]]): The request object. Message sent by the client for the `GetCustomClass` method. name (:class:`str`): @@ -1047,11 +1072,13 @@ async def sample_get_custom_class(): async def list_custom_classes( self, - request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesAsyncPager: r"""List custom classes. @@ -1084,7 +1111,7 @@ async def sample_list_custom_classes(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.ListCustomClassesRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.ListCustomClassesRequest, dict]]): The request object. Message sent by the client for the `ListCustomClasses` method. parent (:class:`str`): @@ -1172,12 +1199,14 @@ async def sample_list_custom_classes(): async def update_custom_class( self, - request: Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] + ] = None, *, - custom_class: resource.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[resource.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Update a custom class. @@ -1208,7 +1237,7 @@ async def sample_update_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.UpdateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.UpdateCustomClassRequest, dict]]): The request object. Message sent by the client for the `UpdateCustomClass` method. custom_class (:class:`google.cloud.speech_v1p1beta1.types.CustomClass`): @@ -1300,11 +1329,13 @@ async def sample_update_custom_class(): async def delete_custom_class( self, - request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a custom class. @@ -1333,7 +1364,7 @@ async def sample_delete_custom_class(): await client.delete_custom_class(request=request) Args: - request (Union[google.cloud.speech_v1p1beta1.types.DeleteCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.DeleteCustomClassRequest, dict]]): The request object. Message sent by the client for the `DeleteCustomClass` method. name (:class:`str`): @@ -1405,14 +1436,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("AdaptationAsyncClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py index cc96dd2ad583..cac351e3f6fc 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py @@ -16,8 +16,20 @@ from collections import OrderedDict import os import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union -import pkg_resources +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -57,7 +69,7 @@ class AdaptationClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[AdaptationTransport]: """Returns an appropriate transport class. @@ -354,8 +366,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, AdaptationTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, AdaptationTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the adaptation client. @@ -369,7 +381,7 @@ def __init__( transport (Union[str, AdaptationTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -399,6 +411,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -451,13 +464,15 @@ def __init__( def create_phrase_set( self, - request: Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] + ] = None, *, - parent: str = None, - phrase_set: resource.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[resource.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Create a set of phrase hints. Each item in the set @@ -592,11 +607,13 @@ def sample_create_phrase_set(): def get_phrase_set( self, - request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Get a phrase set. @@ -705,11 +722,13 @@ def sample_get_phrase_set(): def list_phrase_set( self, - request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetPager: r"""List phrase sets. @@ -830,12 +849,14 @@ def sample_list_phrase_set(): def update_phrase_set( self, - request: Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] + ] = None, *, - phrase_set: resource.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[resource.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Update a phrase set. @@ -954,11 +975,13 @@ def sample_update_phrase_set(): def delete_phrase_set( self, - request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a phrase set. @@ -1045,13 +1068,15 @@ def sample_delete_phrase_set(): def create_custom_class( self, - request: Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] + ] = None, *, - parent: str = None, - custom_class: resource.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[resource.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Create a custom class. @@ -1187,11 +1212,13 @@ def sample_create_custom_class(): def get_custom_class( self, - request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.GetCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Get a custom class. @@ -1296,11 +1323,13 @@ def sample_get_custom_class(): def list_custom_classes( self, - request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] + ] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesPager: r"""List custom classes. @@ -1421,12 +1450,14 @@ def sample_list_custom_classes(): def update_custom_class( self, - request: Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] + ] = None, *, - custom_class: resource.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[resource.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Update a custom class. @@ -1549,11 +1580,13 @@ def sample_update_custom_class(): def delete_custom_class( self, - request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, + request: Optional[ + Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a custom class. @@ -1661,14 +1694,9 @@ def __exit__(self, type, value, traceback): self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("AdaptationClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py index 6ae73125328a..861402a36f81 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py @@ -15,7 +15,8 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version import google.auth # type: ignore import google.api_core @@ -29,14 +30,9 @@ from google.cloud.speech_v1p1beta1.types import resource from google.protobuf import empty_pb2 # type: ignore -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class AdaptationTransport(abc.ABC): @@ -50,7 +46,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc.py index 02a30dce0a72..7e10be5c99c9 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc.py @@ -49,14 +49,14 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -183,8 +183,8 @@ def __init__( def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py index cd1a0eb40ff9..d620d6379491 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py @@ -51,7 +51,7 @@ class AdaptationGrpcAsyncIOTransport(AdaptationTransport): def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -94,15 +94,15 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py index 47e99dfa2bd4..7d0bca58e2e2 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, AsyncIterable, Awaitable, @@ -28,7 +30,8 @@ Type, Union, ) -import pkg_resources + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions @@ -164,9 +167,9 @@ def transport(self) -> SpeechTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, SpeechTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -210,12 +213,12 @@ def __init__( async def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous speech recognition: receive @@ -255,7 +258,7 @@ async def sample_recognize(): print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.RecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.RecognizeRequest, dict]]): The request object. The top-level message sent by the client for the `Recognize` method. config (:class:`google.cloud.speech_v1p1beta1.types.RecognitionConfig`): @@ -336,12 +339,12 @@ async def sample_recognize(): async def long_running_recognize( self, - request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.LongRunningRecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Performs asynchronous speech recognition: receive results via @@ -383,13 +386,13 @@ async def sample_long_running_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v1p1beta1.types.LongRunningRecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v1p1beta1.types.LongRunningRecognizeRequest, dict]]): The request object. The top-level message sent by the client for the `LongRunningRecognize` method. config (:class:`google.cloud.speech_v1p1beta1.types.RecognitionConfig`): @@ -473,10 +476,12 @@ async def sample_long_running_recognize(): def streaming_recognize( self, - requests: AsyncIterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[ + AsyncIterator[cloud_speech.StreamingRecognizeRequest] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]: r"""Performs bidirectional streaming speech recognition: @@ -639,14 +644,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechAsyncClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/client.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/client.py index e24f61ae2544..0d853e601436 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, Iterable, Iterator, @@ -26,8 +28,10 @@ Tuple, Type, Union, + cast, ) -import pkg_resources + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -68,7 +72,7 @@ class SpeechClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[SpeechTransport]: """Returns an appropriate transport class. @@ -365,8 +369,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, SpeechTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, SpeechTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -380,7 +384,7 @@ def __init__( transport (Union[str, SpeechTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -410,6 +414,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -462,12 +467,12 @@ def __init__( def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous speech recognition: receive @@ -578,12 +583,12 @@ def sample_recognize(): def long_running_recognize( self, - request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.LongRunningRecognizeRequest, dict]] = None, *, - config: cloud_speech.RecognitionConfig = None, - audio: cloud_speech.RecognitionAudio = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + audio: Optional[cloud_speech.RecognitionAudio] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Performs asynchronous speech recognition: receive results via @@ -715,10 +720,10 @@ def sample_long_running_recognize(): def streaming_recognize( self, - requests: Iterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[Iterator[cloud_speech.StreamingRecognizeRequest]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[cloud_speech.StreamingRecognizeResponse]: r"""Performs bidirectional streaming speech recognition: @@ -874,14 +879,9 @@ def __exit__(self, type, value, traceback): self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py index 426c9af5c85f..346b3aeee489 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py @@ -15,7 +15,8 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources + +from google.cloud.speech_v1p1beta1 import gapic_version as package_version import google.auth # type: ignore import google.api_core @@ -29,14 +30,9 @@ from google.cloud.speech_v1p1beta1.types import cloud_speech from google.longrunning import operations_pb2 # type: ignore -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class SpeechTransport(abc.ABC): @@ -50,7 +46,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py index 76792d71d756..58cdff4263f3 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py @@ -49,14 +49,14 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -184,8 +184,8 @@ def __init__( def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py index 0a6466198cd4..e1cf92fe923b 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py @@ -51,7 +51,7 @@ class SpeechGrpcAsyncIOTransport(SpeechTransport): def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -94,15 +94,15 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/__init__.py index a33a9effeb6c..f23bf461f525 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/__init__.py @@ -23,6 +23,7 @@ RecognizeRequest, RecognizeResponse, SpeakerDiarizationConfig, + SpeechAdaptationInfo, SpeechContext, SpeechRecognitionAlternative, SpeechRecognitionResult, @@ -64,6 +65,7 @@ "RecognizeRequest", "RecognizeResponse", "SpeakerDiarizationConfig", + "SpeechAdaptationInfo", "SpeechContext", "SpeechRecognitionAlternative", "SpeechRecognitionResult", diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py index 21af413e46d4..a083e55a3757 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore from google.cloud.speech_v1p1beta1.types import resource @@ -43,6 +45,7 @@ "SpeechRecognitionResult", "SpeechRecognitionAlternative", "WordInfo", + "SpeechAdaptationInfo", }, ) @@ -60,12 +63,12 @@ class RecognizeRequest(proto.Message): Required. The audio data to be recognized. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - audio = proto.Field( + audio: "RecognitionAudio" = proto.Field( proto.MESSAGE, number=2, message="RecognitionAudio", @@ -88,17 +91,17 @@ class LongRunningRecognizeRequest(proto.Message): for the recognition results. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - audio = proto.Field( + audio: "RecognitionAudio" = proto.Field( proto.MESSAGE, number=2, message="RecognitionAudio", ) - output_config = proto.Field( + output_config: "TranscriptOutputConfig" = proto.Field( proto.MESSAGE, number=4, message="TranscriptOutputConfig", @@ -122,7 +125,7 @@ class TranscriptOutputConfig(proto.Message): This field is a member of `oneof`_ ``output_type``. """ - gcs_uri = proto.Field( + gcs_uri: str = proto.Field( proto.STRING, number=1, oneof="output_type", @@ -167,13 +170,13 @@ class StreamingRecognizeRequest(proto.Message): This field is a member of `oneof`_ ``streaming_request``. """ - streaming_config = proto.Field( + streaming_config: "StreamingRecognitionConfig" = proto.Field( proto.MESSAGE, number=1, oneof="streaming_request", message="StreamingRecognitionConfig", ) - audio_content = proto.Field( + audio_content: bytes = proto.Field( proto.BYTES, number=2, oneof="streaming_request", @@ -222,16 +225,16 @@ class StreamingRecognitionConfig(proto.Message): omitted, only ``is_final=true`` result(s) are returned. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - single_utterance = proto.Field( + single_utterance: bool = proto.Field( proto.BOOL, number=2, ) - interim_results = proto.Field( + interim_results: bool = proto.Field( proto.BOOL, number=3, ) @@ -261,12 +264,11 @@ class RecognitionConfig(proto.Message): audio_channel_count (int): 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 + LINEAR16, OGG_OPUS and FLAC are ``1``-``8``. 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 (bool): This needs to be set to ``true`` explicitly and @@ -283,7 +285,7 @@ class RecognitionConfig(proto.Message): language tag. Example: "en-US". See `Language Support `__ for a list of the currently supported language codes. - alternative_language_codes (Sequence[str]): + alternative_language_codes (MutableSequence[str]): A list of up to 3 additional `BCP-47 `__ language tags, listing possible alternative languages of the @@ -323,7 +325,7 @@ class RecognitionConfig(proto.Message): StreamingRecognize, this normalization only applies to stable partial transcripts (stability > 0.8) and final transcripts. - speech_contexts (Sequence[google.cloud.speech_v1p1beta1.types.SpeechContext]): + speech_contexts (MutableSequence[google.cloud.speech_v1p1beta1.types.SpeechContext]): Array of [SpeechContext][google.cloud.speech.v1p1beta1.SpeechContext]. A means to provide context to assist the speech recognition. @@ -493,99 +495,99 @@ class AudioEncoding(proto.Enum): MP3 = 8 WEBM_OPUS = 9 - encoding = proto.Field( + encoding: AudioEncoding = proto.Field( proto.ENUM, number=1, enum=AudioEncoding, ) - sample_rate_hertz = proto.Field( + sample_rate_hertz: int = proto.Field( proto.INT32, number=2, ) - audio_channel_count = proto.Field( + audio_channel_count: int = proto.Field( proto.INT32, number=7, ) - enable_separate_recognition_per_channel = proto.Field( + enable_separate_recognition_per_channel: bool = proto.Field( proto.BOOL, number=12, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=3, ) - alternative_language_codes = proto.RepeatedField( + alternative_language_codes: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=18, ) - max_alternatives = proto.Field( + max_alternatives: int = proto.Field( proto.INT32, number=4, ) - profanity_filter = proto.Field( + profanity_filter: bool = proto.Field( proto.BOOL, number=5, ) - adaptation = proto.Field( + adaptation: resource.SpeechAdaptation = proto.Field( proto.MESSAGE, number=20, message=resource.SpeechAdaptation, ) - transcript_normalization = proto.Field( + transcript_normalization: resource.TranscriptNormalization = proto.Field( proto.MESSAGE, number=24, message=resource.TranscriptNormalization, ) - speech_contexts = proto.RepeatedField( + speech_contexts: MutableSequence["SpeechContext"] = proto.RepeatedField( proto.MESSAGE, number=6, message="SpeechContext", ) - enable_word_time_offsets = proto.Field( + enable_word_time_offsets: bool = proto.Field( proto.BOOL, number=8, ) - enable_word_confidence = proto.Field( + enable_word_confidence: bool = proto.Field( proto.BOOL, number=15, ) - enable_automatic_punctuation = proto.Field( + enable_automatic_punctuation: bool = proto.Field( proto.BOOL, number=11, ) - enable_spoken_punctuation = proto.Field( + enable_spoken_punctuation: wrappers_pb2.BoolValue = proto.Field( proto.MESSAGE, number=22, message=wrappers_pb2.BoolValue, ) - enable_spoken_emojis = proto.Field( + enable_spoken_emojis: wrappers_pb2.BoolValue = proto.Field( proto.MESSAGE, number=23, message=wrappers_pb2.BoolValue, ) - enable_speaker_diarization = proto.Field( + enable_speaker_diarization: bool = proto.Field( proto.BOOL, number=16, ) - diarization_speaker_count = proto.Field( + diarization_speaker_count: int = proto.Field( proto.INT32, number=17, ) - diarization_config = proto.Field( + diarization_config: "SpeakerDiarizationConfig" = proto.Field( proto.MESSAGE, number=19, message="SpeakerDiarizationConfig", ) - metadata = proto.Field( + metadata: "RecognitionMetadata" = proto.Field( proto.MESSAGE, number=9, message="RecognitionMetadata", ) - model = proto.Field( + model: str = proto.Field( proto.STRING, number=13, ) - use_enhanced = proto.Field( + use_enhanced: bool = proto.Field( proto.BOOL, number=14, ) @@ -615,19 +617,19 @@ class SpeakerDiarizationConfig(proto.Message): Output only. Unused. """ - enable_speaker_diarization = proto.Field( + enable_speaker_diarization: bool = proto.Field( proto.BOOL, number=1, ) - min_speaker_count = proto.Field( + min_speaker_count: int = proto.Field( proto.INT32, number=2, ) - max_speaker_count = proto.Field( + max_speaker_count: int = proto.Field( proto.INT32, number=3, ) - speaker_tag = proto.Field( + speaker_tag: int = proto.Field( proto.INT32, number=5, ) @@ -715,43 +717,43 @@ class RecordingDeviceType(proto.Enum): OTHER_OUTDOOR_DEVICE = 5 OTHER_INDOOR_DEVICE = 6 - interaction_type = proto.Field( + interaction_type: InteractionType = proto.Field( proto.ENUM, number=1, enum=InteractionType, ) - industry_naics_code_of_audio = proto.Field( + industry_naics_code_of_audio: int = proto.Field( proto.UINT32, number=3, ) - microphone_distance = proto.Field( + microphone_distance: MicrophoneDistance = proto.Field( proto.ENUM, number=4, enum=MicrophoneDistance, ) - original_media_type = proto.Field( + original_media_type: OriginalMediaType = proto.Field( proto.ENUM, number=5, enum=OriginalMediaType, ) - recording_device_type = proto.Field( + recording_device_type: RecordingDeviceType = proto.Field( proto.ENUM, number=6, enum=RecordingDeviceType, ) - recording_device_name = proto.Field( + recording_device_name: str = proto.Field( proto.STRING, number=7, ) - original_mime_type = proto.Field( + original_mime_type: str = proto.Field( proto.STRING, number=8, ) - obfuscated_id = proto.Field( + obfuscated_id: int = proto.Field( proto.INT64, number=9, ) - audio_topic = proto.Field( + audio_topic: str = proto.Field( proto.STRING, number=10, ) @@ -762,7 +764,7 @@ class SpeechContext(proto.Message): words and phrases in the results. Attributes: - phrases (Sequence[str]): + phrases (MutableSequence[str]): A list of strings containing words and phrases "hints" so that the speech recognition is more likely to recognize them. This can be used to improve the accuracy for specific @@ -791,11 +793,11 @@ class SpeechContext(proto.Message): optimal value for your use case. """ - phrases = proto.RepeatedField( + phrases: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=1, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=4, ) @@ -838,12 +840,12 @@ class RecognitionAudio(proto.Message): This field is a member of `oneof`_ ``audio_source``. """ - content = proto.Field( + content: bytes = proto.Field( proto.BYTES, number=1, oneof="audio_source", ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=2, oneof="audio_source", @@ -856,24 +858,39 @@ class RecognizeResponse(proto.Message): ``SpeechRecognitionResult`` messages. Attributes: - results (Sequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionResult]): Sequential list of transcription results corresponding to sequential portions of audio. total_billed_time (google.protobuf.duration_pb2.Duration): When available, billed audio seconds for the corresponding request. + speech_adaptation_info (google.cloud.speech_v1p1beta1.types.SpeechAdaptationInfo): + Provides information on adaptation behavior + in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ - results = proto.RepeatedField( + results: MutableSequence["SpeechRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="SpeechRecognitionResult", ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=3, message=duration_pb2.Duration, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=7, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=8, + ) class LongRunningRecognizeResponse(proto.Message): @@ -885,7 +902,7 @@ class LongRunningRecognizeResponse(proto.Message): service. Attributes: - results (Sequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionResult]): Sequential list of transcription results corresponding to sequential portions of audio. total_billed_time (google.protobuf.duration_pb2.Duration): @@ -897,28 +914,43 @@ class LongRunningRecognizeResponse(proto.Message): output_error (google.rpc.status_pb2.Status): If the transcript output fails this field contains the relevant error. + speech_adaptation_info (google.cloud.speech_v1p1beta1.types.SpeechAdaptationInfo): + Provides information on speech adaptation + behavior in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ - results = proto.RepeatedField( + results: MutableSequence["SpeechRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="SpeechRecognitionResult", ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=3, message=duration_pb2.Duration, ) - output_config = proto.Field( + output_config: "TranscriptOutputConfig" = proto.Field( proto.MESSAGE, number=6, message="TranscriptOutputConfig", ) - output_error = proto.Field( + output_error: status_pb2.Status = proto.Field( proto.MESSAGE, number=7, message=status_pb2.Status, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=8, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=9, + ) class LongRunningRecognizeMetadata(proto.Message): @@ -946,25 +978,25 @@ class LongRunningRecognizeMetadata(proto.Message): request. """ - progress_percent = proto.Field( + progress_percent: int = proto.Field( proto.INT32, number=1, ) - start_time = proto.Field( + start_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) - last_update_time = proto.Field( + last_update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=4, ) - output_config = proto.Field( + output_config: "TranscriptOutputConfig" = proto.Field( proto.MESSAGE, number=5, message="TranscriptOutputConfig", @@ -1029,7 +1061,7 @@ class StreamingRecognizeResponse(proto.Message): error (google.rpc.status_pb2.Status): If set, returns a [google.rpc.Status][google.rpc.Status] message that specifies the error for the operation. - results (Sequence[google.cloud.speech_v1p1beta1.types.StreamingRecognitionResult]): + results (MutableSequence[google.cloud.speech_v1p1beta1.types.StreamingRecognitionResult]): This repeated list contains zero or more results that correspond to consecutive portions of the audio currently being processed. It contains zero or one ``is_final=true`` @@ -1041,6 +1073,12 @@ class StreamingRecognizeResponse(proto.Message): When available, billed audio seconds for the stream. Set only if this is the last response in the stream. + speech_adaptation_info (google.cloud.speech_v1p1beta1.types.SpeechAdaptationInfo): + Provides information on adaptation behavior + in response + request_id (int): + The ID associated with the request. This is a + unique ID specific only to the given request. """ class SpeechEventType(proto.Enum): @@ -1048,26 +1086,35 @@ class SpeechEventType(proto.Enum): SPEECH_EVENT_UNSPECIFIED = 0 END_OF_SINGLE_UTTERANCE = 1 - error = proto.Field( + error: status_pb2.Status = proto.Field( proto.MESSAGE, number=1, message=status_pb2.Status, ) - results = proto.RepeatedField( + results: MutableSequence["StreamingRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=2, message="StreamingRecognitionResult", ) - speech_event_type = proto.Field( + speech_event_type: SpeechEventType = proto.Field( proto.ENUM, number=4, enum=SpeechEventType, ) - total_billed_time = proto.Field( + total_billed_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=5, message=duration_pb2.Duration, ) + speech_adaptation_info: "SpeechAdaptationInfo" = proto.Field( + proto.MESSAGE, + number=9, + message="SpeechAdaptationInfo", + ) + request_id: int = proto.Field( + proto.INT64, + number=10, + ) class StreamingRecognitionResult(proto.Message): @@ -1075,7 +1122,7 @@ class StreamingRecognitionResult(proto.Message): portion of the audio that is currently being processed. Attributes: - alternatives (Sequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses (up to the maximum specified in ``max_alternatives``). These alternatives are ordered in terms of accuracy, with the top @@ -1111,29 +1158,29 @@ class StreamingRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - is_final = proto.Field( + is_final: bool = proto.Field( proto.BOOL, number=2, ) - stability = proto.Field( + stability: float = proto.Field( proto.FLOAT, number=3, ) - result_end_time = proto.Field( + result_end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=5, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=6, ) @@ -1144,7 +1191,7 @@ class SpeechRecognitionResult(proto.Message): audio. Attributes: - alternatives (Sequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v1p1beta1.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses (up to the maximum specified in ``max_alternatives``). These alternatives are ordered in terms of accuracy, with the top @@ -1166,21 +1213,21 @@ class SpeechRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=2, ) - result_end_time = proto.Field( + result_end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=5, ) @@ -1206,21 +1253,21 @@ class SpeechRecognitionAlternative(proto.Message): 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. - words (Sequence[google.cloud.speech_v1p1beta1.types.WordInfo]): + words (MutableSequence[google.cloud.speech_v1p1beta1.types.WordInfo]): A list of word-specific information for each recognized word. Note: When ``enable_speaker_diarization`` is true, you will see all the words from the beginning of the audio. """ - transcript = proto.Field( + transcript: str = proto.Field( proto.STRING, number=1, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=2, ) - words = proto.RepeatedField( + words: MutableSequence["WordInfo"] = proto.RepeatedField( proto.MESSAGE, number=3, message="WordInfo", @@ -1264,28 +1311,51 @@ class WordInfo(proto.Message): top alternative. """ - start_time = proto.Field( + start_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=1, message=duration_pb2.Duration, ) - end_time = proto.Field( + end_time: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=2, message=duration_pb2.Duration, ) - word = proto.Field( + word: str = proto.Field( proto.STRING, number=3, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=4, ) - speaker_tag = proto.Field( + speaker_tag: int = proto.Field( proto.INT32, number=5, ) +class SpeechAdaptationInfo(proto.Message): + r"""Information on speech adaptation use in results + + Attributes: + adaptation_timeout (bool): + Whether there was a timeout when applying + speech adaptation. If true, adaptation had no + effect in the response transcript. + timeout_message (str): + If set, returns a message specifying which + part of the speech adaptation request timed out. + """ + + adaptation_timeout: bool = proto.Field( + proto.BOOL, + number=1, + ) + timeout_message: str = proto.Field( + proto.STRING, + number=4, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech_adaptation.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech_adaptation.py index a773705e9b0d..5931a9b97843 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech_adaptation.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/cloud_speech_adaptation.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore from google.cloud.speech_v1p1beta1.types import resource @@ -66,15 +68,15 @@ class CreatePhraseSetRequest(proto.Message): Required. The phrase set to create. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - phrase_set_id = proto.Field( + phrase_set_id: str = proto.Field( proto.STRING, number=2, ) - phrase_set = proto.Field( + phrase_set: resource.PhraseSet = proto.Field( proto.MESSAGE, number=3, message=resource.PhraseSet, @@ -103,12 +105,12 @@ class UpdatePhraseSetRequest(proto.Message): The list of fields to be updated. """ - phrase_set = proto.Field( + phrase_set: resource.PhraseSet = proto.Field( proto.MESSAGE, number=1, message=resource.PhraseSet, ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, @@ -132,7 +134,7 @@ class GetPhraseSetRequest(proto.Message): with matching ``us`` or ``eu`` location value. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -169,15 +171,15 @@ class ListPhraseSetRequest(proto.Message): token. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -187,7 +189,7 @@ class ListPhraseSetResponse(proto.Message): r"""Message returned to the client by the ``ListPhraseSet`` method. Attributes: - phrase_sets (Sequence[google.cloud.speech_v1p1beta1.types.PhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v1p1beta1.types.PhraseSet]): The phrase set. next_page_token (str): A token, which can be sent as ``page_token`` to retrieve the @@ -199,12 +201,12 @@ class ListPhraseSetResponse(proto.Message): def raw_page(self): return self - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence[resource.PhraseSet] = proto.RepeatedField( proto.MESSAGE, number=1, message=resource.PhraseSet, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -220,7 +222,7 @@ class DeletePhraseSetRequest(proto.Message): ``projects/{project}/locations/{location}/phraseSets/{phrase_set}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -254,15 +256,15 @@ class CreateCustomClassRequest(proto.Message): Required. The custom class to create. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - custom_class_id = proto.Field( + custom_class_id: str = proto.Field( proto.STRING, number=2, ) - custom_class = proto.Field( + custom_class: resource.CustomClass = proto.Field( proto.MESSAGE, number=3, message=resource.CustomClass, @@ -291,12 +293,12 @@ class UpdateCustomClassRequest(proto.Message): The list of fields to be updated. """ - custom_class = proto.Field( + custom_class: resource.CustomClass = proto.Field( proto.MESSAGE, number=1, message=resource.CustomClass, ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, @@ -313,7 +315,7 @@ class GetCustomClassRequest(proto.Message): ``projects/{project}/locations/{location}/customClasses/{custom_class}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -350,15 +352,15 @@ class ListCustomClassesRequest(proto.Message): page token. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -368,7 +370,7 @@ class ListCustomClassesResponse(proto.Message): r"""Message returned to the client by the ``ListCustomClasses`` method. Attributes: - custom_classes (Sequence[google.cloud.speech_v1p1beta1.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v1p1beta1.types.CustomClass]): The custom classes. next_page_token (str): A token, which can be sent as ``page_token`` to retrieve the @@ -380,12 +382,12 @@ class ListCustomClassesResponse(proto.Message): def raw_page(self): return self - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence[resource.CustomClass] = proto.RepeatedField( proto.MESSAGE, number=1, message=resource.CustomClass, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -408,7 +410,7 @@ class DeleteCustomClassRequest(proto.Message): with matching ``us`` or ``eu`` location value. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/resource.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/resource.py index 8f4a4e983a09..01572abfc6cc 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/resource.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/types/resource.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore @@ -39,7 +41,7 @@ class CustomClass(proto.Message): custom_class_id (str): If this custom class is a resource, the custom_class_id is the resource id of the CustomClass. Case sensitive. - items (Sequence[google.cloud.speech_v1p1beta1.types.CustomClass.ClassItem]): + items (MutableSequence[google.cloud.speech_v1p1beta1.types.CustomClass.ClassItem]): A collection of class items. """ @@ -51,20 +53,20 @@ class ClassItem(proto.Message): The class item's value. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - custom_class_id = proto.Field( + custom_class_id: str = proto.Field( proto.STRING, number=2, ) - items = proto.RepeatedField( + items: MutableSequence[ClassItem] = proto.RepeatedField( proto.MESSAGE, number=3, message=ClassItem, @@ -78,7 +80,7 @@ class PhraseSet(proto.Message): Attributes: name (str): The resource name of the phrase set. - phrases (Sequence[google.cloud.speech_v1p1beta1.types.PhraseSet.Phrase]): + phrases (MutableSequence[google.cloud.speech_v1p1beta1.types.PhraseSet.Phrase]): A list of word and phrases. boost (float): Hint Boost. Positive value will increase the probability @@ -142,25 +144,25 @@ class Phrase(proto.Message): of 0. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=2, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - phrases = proto.RepeatedField( + phrases: MutableSequence[Phrase] = proto.RepeatedField( proto.MESSAGE, number=2, message=Phrase, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=4, ) @@ -170,14 +172,14 @@ class SpeechAdaptation(proto.Message): r"""Speech adaptation configuration. Attributes: - phrase_sets (Sequence[google.cloud.speech_v1p1beta1.types.PhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v1p1beta1.types.PhraseSet]): A collection of phrase sets. To specify the hints inline, leave the phrase set's ``name`` blank and fill in the rest of its fields. Any phrase set can use any custom class. - phrase_set_references (Sequence[str]): + phrase_set_references (MutableSequence[str]): A collection of phrase set resource names to use. - custom_classes (Sequence[google.cloud.speech_v1p1beta1.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v1p1beta1.types.CustomClass]): A collection of custom classes. To specify the classes inline, leave the class' ``name`` blank and fill in the rest of its fields, giving it a unique ``custom_class_id``. Refer @@ -185,16 +187,16 @@ class SpeechAdaptation(proto.Message): ``custom_class_id``. """ - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence["PhraseSet"] = proto.RepeatedField( proto.MESSAGE, number=1, message="PhraseSet", ) - phrase_set_references = proto.RepeatedField( + phrase_set_references: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=2, ) - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence["CustomClass"] = proto.RepeatedField( proto.MESSAGE, number=3, message="CustomClass", @@ -209,7 +211,7 @@ class TranscriptNormalization(proto.Message): (stability > 0.8) and final transcripts. Attributes: - entries (Sequence[google.cloud.speech_v1p1beta1.types.TranscriptNormalization.Entry]): + entries (MutableSequence[google.cloud.speech_v1p1beta1.types.TranscriptNormalization.Entry]): A list of replacement entries. We will perform replacement with one entry at a time. For example, the second entry in ["cat" => "dog", "mountain cat" => "mountain dog"] will @@ -231,20 +233,20 @@ class Entry(proto.Message): Whether the search is case sensitive. """ - search = proto.Field( + search: str = proto.Field( proto.STRING, number=1, ) - replace = proto.Field( + replace: str = proto.Field( proto.STRING, number=2, ) - case_sensitive = proto.Field( + case_sensitive: bool = proto.Field( proto.BOOL, number=3, ) - entries = proto.RepeatedField( + entries: MutableSequence[Entry] = proto.RepeatedField( proto.MESSAGE, number=1, message=Entry, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/__init__.py index 9cca12001e3c..904e392b4cc4 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/__init__.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.speech_v2 import gapic_version as package_version + +__version__ = package_version.__version__ + from .services.speech import SpeechClient from .services.speech import SpeechAsyncClient diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/gapic_version.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/gapic_version.py new file mode 100644 index 000000000000..e1ac79787eb8 --- /dev/null +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +__version__ = "2.16.2" # {x-release-please-version} diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/async_client.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/async_client.py index f44234e11a3c..63a4cff68143 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/async_client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/async_client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, AsyncIterable, Awaitable, @@ -28,7 +30,8 @@ Type, Union, ) -import pkg_resources + +from google.cloud.speech_v2 import gapic_version as package_version from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions @@ -177,9 +180,9 @@ def transport(self) -> SpeechTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, SpeechTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -223,13 +226,13 @@ def __init__( async def create_recognizer( self, - request: Union[cloud_speech.CreateRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.CreateRecognizerRequest, dict]] = None, *, - parent: str = None, - recognizer: cloud_speech.Recognizer = None, - recognizer_id: str = None, + parent: Optional[str] = None, + recognizer: Optional[cloud_speech.Recognizer] = None, + recognizer_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -264,13 +267,13 @@ async def sample_create_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.CreateRecognizerRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.CreateRecognizerRequest, dict]]): The request object. Request message for the [CreateRecognizer][google.cloud.speech.v2.Speech.CreateRecognizer] method. @@ -369,11 +372,11 @@ async def sample_create_recognizer(): async def list_recognizers( self, - request: Union[cloud_speech.ListRecognizersRequest, dict] = None, + request: Optional[Union[cloud_speech.ListRecognizersRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListRecognizersAsyncPager: r"""Lists Recognizers. @@ -406,7 +409,7 @@ async def sample_list_recognizers(): print(response) Args: - request (Union[google.cloud.speech_v2.types.ListRecognizersRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.ListRecognizersRequest, dict]]): The request object. Request message for the [ListRecognizers][google.cloud.speech.v2.Speech.ListRecognizers] method. @@ -487,11 +490,11 @@ async def sample_list_recognizers(): async def get_recognizer( self, - request: Union[cloud_speech.GetRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.GetRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Recognizer: r"""Returns the requested @@ -526,7 +529,7 @@ async def sample_get_recognizer(): print(response) Args: - request (Union[google.cloud.speech_v2.types.GetRecognizerRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.GetRecognizerRequest, dict]]): The request object. Request message for the [GetRecognizer][google.cloud.speech.v2.Speech.GetRecognizer] method. @@ -594,12 +597,12 @@ async def sample_get_recognizer(): async def update_recognizer( self, - request: Union[cloud_speech.UpdateRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateRecognizerRequest, dict]] = None, *, - recognizer: cloud_speech.Recognizer = None, - update_mask: field_mask_pb2.FieldMask = None, + recognizer: Optional[cloud_speech.Recognizer] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -633,13 +636,13 @@ async def sample_update_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UpdateRecognizerRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UpdateRecognizerRequest, dict]]): The request object. Request message for the [UpdateRecognizer][google.cloud.speech.v2.Speech.UpdateRecognizer] method. @@ -733,11 +736,11 @@ async def sample_update_recognizer(): async def delete_recognizer( self, - request: Union[cloud_speech.DeleteRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.DeleteRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -767,13 +770,13 @@ async def sample_delete_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.DeleteRecognizerRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.DeleteRecognizerRequest, dict]]): The request object. Request message for the [DeleteRecognizer][google.cloud.speech.v2.Speech.DeleteRecognizer] method. @@ -852,11 +855,11 @@ async def sample_delete_recognizer(): async def undelete_recognizer( self, - request: Union[cloud_speech.UndeleteRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeleteRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Undeletes the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -886,13 +889,13 @@ async def sample_undelete_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UndeleteRecognizerRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UndeleteRecognizerRequest, dict]]): The request object. Request message for the [UndeleteRecognizer][google.cloud.speech.v2.Speech.UndeleteRecognizer] method. @@ -972,15 +975,15 @@ async def sample_undelete_recognizer(): async def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - recognizer: str = None, - config: cloud_speech.RecognitionConfig = None, - config_mask: field_mask_pb2.FieldMask = None, - content: bytes = None, - uri: str = None, + recognizer: Optional[str] = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + config_mask: Optional[field_mask_pb2.FieldMask] = None, + content: Optional[bytes] = None, + uri: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous Speech recognition: receive @@ -1014,7 +1017,7 @@ async def sample_recognize(): print(response) Args: - request (Union[google.cloud.speech_v2.types.RecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.RecognizeRequest, dict]]): The request object. Request message for the [Recognize][google.cloud.speech.v2.Speech.Recognize] method. Either `content` or `uri` must be supplied. @@ -1154,10 +1157,12 @@ async def sample_recognize(): def streaming_recognize( self, - requests: AsyncIterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[ + AsyncIterator[cloud_speech.StreamingRecognizeRequest] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]: r"""Performs bidirectional streaming speech recognition: @@ -1308,14 +1313,16 @@ def request_generator(): async def batch_recognize( self, - request: Union[cloud_speech.BatchRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.BatchRecognizeRequest, dict]] = None, *, - recognizer: str = None, - config: cloud_speech.RecognitionConfig = None, - config_mask: field_mask_pb2.FieldMask = None, - files: Sequence[cloud_speech.BatchRecognizeFileMetadata] = None, + recognizer: Optional[str] = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + config_mask: Optional[field_mask_pb2.FieldMask] = None, + files: Optional[ + MutableSequence[cloud_speech.BatchRecognizeFileMetadata] + ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Performs batch asynchronous speech recognition: send @@ -1348,13 +1355,13 @@ async def sample_batch_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.BatchRecognizeRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.BatchRecognizeRequest, dict]]): The request object. Request message for the [BatchRecognize][google.cloud.speech.v2.Speech.BatchRecognize] method. @@ -1396,7 +1403,7 @@ async def sample_batch_recognize(): This corresponds to the ``config_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - files (:class:`Sequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]`): + files (:class:`MutableSequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]`): Audio files with file metadata for ASR. @@ -1479,11 +1486,11 @@ async def sample_batch_recognize(): async def get_config( self, - request: Union[cloud_speech.GetConfigRequest, dict] = None, + request: Optional[Union[cloud_speech.GetConfigRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Config: r"""Returns the requested [Config][google.cloud.speech.v2.Config]. @@ -1515,7 +1522,7 @@ async def sample_get_config(): print(response) Args: - request (Union[google.cloud.speech_v2.types.GetConfigRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.GetConfigRequest, dict]]): The request object. Request message for the [GetConfig][google.cloud.speech.v2.Speech.GetConfig] method. @@ -1586,12 +1593,12 @@ async def sample_get_config(): async def update_config( self, - request: Union[cloud_speech.UpdateConfigRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateConfigRequest, dict]] = None, *, - config: cloud_speech.Config = None, - update_mask: field_mask_pb2.FieldMask = None, + config: Optional[cloud_speech.Config] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Config: r"""Updates the [Config][google.cloud.speech.v2.Config]. @@ -1622,7 +1629,7 @@ async def sample_update_config(): print(response) Args: - request (Union[google.cloud.speech_v2.types.UpdateConfigRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UpdateConfigRequest, dict]]): The request object. Request message for the [UpdateConfig][google.cloud.speech.v2.Speech.UpdateConfig] method. @@ -1703,13 +1710,13 @@ async def sample_update_config(): async def create_custom_class( self, - request: Union[cloud_speech.CreateCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.CreateCustomClassRequest, dict]] = None, *, - parent: str = None, - custom_class: cloud_speech.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[cloud_speech.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -1739,13 +1746,13 @@ async def sample_create_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.CreateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.CreateCustomClassRequest, dict]]): The request object. Request message for the [CreateCustomClass][google.cloud.speech.v2.Speech.CreateCustomClass] method. @@ -1844,11 +1851,11 @@ async def sample_create_custom_class(): async def list_custom_classes( self, - request: Union[cloud_speech.ListCustomClassesRequest, dict] = None, + request: Optional[Union[cloud_speech.ListCustomClassesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesAsyncPager: r"""Lists CustomClasses. @@ -1881,7 +1888,7 @@ async def sample_list_custom_classes(): print(response) Args: - request (Union[google.cloud.speech_v2.types.ListCustomClassesRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.ListCustomClassesRequest, dict]]): The request object. Request message for the [ListCustomClasses][google.cloud.speech.v2.Speech.ListCustomClasses] method. @@ -1962,11 +1969,11 @@ async def sample_list_custom_classes(): async def get_custom_class( self, - request: Union[cloud_speech.GetCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.GetCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.CustomClass: r"""Returns the requested @@ -1999,7 +2006,7 @@ async def sample_get_custom_class(): print(response) Args: - request (Union[google.cloud.speech_v2.types.GetCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.GetCustomClassRequest, dict]]): The request object. Request message for the [GetCustomClass][google.cloud.speech.v2.Speech.GetCustomClass] method. @@ -2071,12 +2078,12 @@ async def sample_get_custom_class(): async def update_custom_class( self, - request: Union[cloud_speech.UpdateCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateCustomClassRequest, dict]] = None, *, - custom_class: cloud_speech.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[cloud_speech.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2105,13 +2112,13 @@ async def sample_update_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UpdateCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UpdateCustomClassRequest, dict]]): The request object. Request message for the [UpdateCustomClass][google.cloud.speech.v2.Speech.UpdateCustomClass] method. @@ -2205,11 +2212,11 @@ async def sample_update_custom_class(): async def delete_custom_class( self, - request: Union[cloud_speech.DeleteCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.DeleteCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2239,13 +2246,13 @@ async def sample_delete_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.DeleteCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.DeleteCustomClassRequest, dict]]): The request object. Request message for the [DeleteCustomClass][google.cloud.speech.v2.Speech.DeleteCustomClass] method. @@ -2324,11 +2331,11 @@ async def sample_delete_custom_class(): async def undelete_custom_class( self, - request: Union[cloud_speech.UndeleteCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeleteCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Undeletes the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2358,13 +2365,13 @@ async def sample_undelete_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UndeleteCustomClassRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UndeleteCustomClassRequest, dict]]): The request object. Request message for the [UndeleteCustomClass][google.cloud.speech.v2.Speech.UndeleteCustomClass] method. @@ -2444,13 +2451,13 @@ async def sample_undelete_custom_class(): async def create_phrase_set( self, - request: Union[cloud_speech.CreatePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.CreatePhraseSetRequest, dict]] = None, *, - parent: str = None, - phrase_set: cloud_speech.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[cloud_speech.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -2480,13 +2487,13 @@ async def sample_create_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.CreatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.CreatePhraseSetRequest, dict]]): The request object. Request message for the [CreatePhraseSet][google.cloud.speech.v2.Speech.CreatePhraseSet] method. @@ -2584,11 +2591,11 @@ async def sample_create_phrase_set(): async def list_phrase_sets( self, - request: Union[cloud_speech.ListPhraseSetsRequest, dict] = None, + request: Optional[Union[cloud_speech.ListPhraseSetsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetsAsyncPager: r"""Lists PhraseSets. @@ -2621,7 +2628,7 @@ async def sample_list_phrase_sets(): print(response) Args: - request (Union[google.cloud.speech_v2.types.ListPhraseSetsRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.ListPhraseSetsRequest, dict]]): The request object. Request message for the [ListPhraseSets][google.cloud.speech.v2.Speech.ListPhraseSets] method. @@ -2702,11 +2709,11 @@ async def sample_list_phrase_sets(): async def get_phrase_set( self, - request: Union[cloud_speech.GetPhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.GetPhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.PhraseSet: r"""Returns the requested @@ -2739,7 +2746,7 @@ async def sample_get_phrase_set(): print(response) Args: - request (Union[google.cloud.speech_v2.types.GetPhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.GetPhraseSetRequest, dict]]): The request object. Request message for the [GetPhraseSet][google.cloud.speech.v2.Speech.GetPhraseSet] method. @@ -2810,12 +2817,12 @@ async def sample_get_phrase_set(): async def update_phrase_set( self, - request: Union[cloud_speech.UpdatePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdatePhraseSetRequest, dict]] = None, *, - phrase_set: cloud_speech.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[cloud_speech.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -2844,13 +2851,13 @@ async def sample_update_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UpdatePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UpdatePhraseSetRequest, dict]]): The request object. Request message for the [UpdatePhraseSet][google.cloud.speech.v2.Speech.UpdatePhraseSet] method. @@ -2943,11 +2950,11 @@ async def sample_update_phrase_set(): async def delete_phrase_set( self, - request: Union[cloud_speech.DeletePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.DeletePhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -2977,13 +2984,13 @@ async def sample_delete_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.DeletePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.DeletePhraseSetRequest, dict]]): The request object. Request message for the [DeletePhraseSet][google.cloud.speech.v2.Speech.DeletePhraseSet] method. @@ -3061,11 +3068,11 @@ async def sample_delete_phrase_set(): async def undelete_phrase_set( self, - request: Union[cloud_speech.UndeletePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeletePhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Undeletes the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -3095,13 +3102,13 @@ async def sample_undelete_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.speech_v2.types.UndeletePhraseSetRequest, dict]): + request (Optional[Union[google.cloud.speech_v2.types.UndeletePhraseSetRequest, dict]]): The request object. Request message for the [UndeletePhraseSet][google.cloud.speech.v2.Speech.UndeletePhraseSet] method. @@ -3179,10 +3186,10 @@ async def sample_undelete_phrase_set(): async def list_operations( self, - request: operations_pb2.ListOperationsRequest = None, + request: Optional[operations_pb2.ListOperationsRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -3233,10 +3240,10 @@ async def list_operations( async def get_operation( self, - request: operations_pb2.GetOperationRequest = None, + request: Optional[operations_pb2.GetOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -3287,10 +3294,10 @@ async def get_operation( async def delete_operation( self, - request: operations_pb2.DeleteOperationRequest = None, + request: Optional[operations_pb2.DeleteOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a long-running operation. @@ -3342,10 +3349,10 @@ async def delete_operation( async def cancel_operation( self, - request: operations_pb2.CancelOperationRequest = None, + request: Optional[operations_pb2.CancelOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -3401,14 +3408,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechAsyncClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/client.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/client.py index e35c88d08ff3..f37e4c14c3b4 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/client.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/client.py @@ -19,6 +19,8 @@ from typing import ( Dict, Mapping, + MutableMapping, + MutableSequence, Optional, Iterable, Iterator, @@ -26,8 +28,10 @@ Tuple, Type, Union, + cast, ) -import pkg_resources + +from google.cloud.speech_v2 import gapic_version as package_version from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -71,7 +75,7 @@ class SpeechClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[SpeechTransport]: """Returns an appropriate transport class. @@ -461,8 +465,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, SpeechTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, SpeechTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the speech client. @@ -476,7 +480,7 @@ def __init__( transport (Union[str, SpeechTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -506,6 +510,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -558,13 +563,13 @@ def __init__( def create_recognizer( self, - request: Union[cloud_speech.CreateRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.CreateRecognizerRequest, dict]] = None, *, - parent: str = None, - recognizer: cloud_speech.Recognizer = None, - recognizer_id: str = None, + parent: Optional[str] = None, + recognizer: Optional[cloud_speech.Recognizer] = None, + recognizer_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -704,11 +709,11 @@ def sample_create_recognizer(): def list_recognizers( self, - request: Union[cloud_speech.ListRecognizersRequest, dict] = None, + request: Optional[Union[cloud_speech.ListRecognizersRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListRecognizersPager: r"""Lists Recognizers. @@ -822,11 +827,11 @@ def sample_list_recognizers(): def get_recognizer( self, - request: Union[cloud_speech.GetRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.GetRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Recognizer: r"""Returns the requested @@ -929,12 +934,12 @@ def sample_get_recognizer(): def update_recognizer( self, - request: Union[cloud_speech.UpdateRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateRecognizerRequest, dict]] = None, *, - recognizer: cloud_speech.Recognizer = None, - update_mask: field_mask_pb2.FieldMask = None, + recognizer: Optional[cloud_speech.Recognizer] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -1068,11 +1073,11 @@ def sample_update_recognizer(): def delete_recognizer( self, - request: Union[cloud_speech.DeleteRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.DeleteRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -1187,11 +1192,11 @@ def sample_delete_recognizer(): def undelete_recognizer( self, - request: Union[cloud_speech.UndeleteRecognizerRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeleteRecognizerRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Undeletes the [Recognizer][google.cloud.speech.v2.Recognizer]. @@ -1307,15 +1312,15 @@ def sample_undelete_recognizer(): def recognize( self, - request: Union[cloud_speech.RecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.RecognizeRequest, dict]] = None, *, - recognizer: str = None, - config: cloud_speech.RecognitionConfig = None, - config_mask: field_mask_pb2.FieldMask = None, - content: bytes = None, - uri: str = None, + recognizer: Optional[str] = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + config_mask: Optional[field_mask_pb2.FieldMask] = None, + content: Optional[bytes] = None, + uri: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: r"""Performs synchronous Speech recognition: receive @@ -1489,10 +1494,10 @@ def sample_recognize(): def streaming_recognize( self, - requests: Iterator[cloud_speech.StreamingRecognizeRequest] = None, + requests: Optional[Iterator[cloud_speech.StreamingRecognizeRequest]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[cloud_speech.StreamingRecognizeResponse]: r"""Performs bidirectional streaming speech recognition: @@ -1639,14 +1644,16 @@ def request_generator(): def batch_recognize( self, - request: Union[cloud_speech.BatchRecognizeRequest, dict] = None, + request: Optional[Union[cloud_speech.BatchRecognizeRequest, dict]] = None, *, - recognizer: str = None, - config: cloud_speech.RecognitionConfig = None, - config_mask: field_mask_pb2.FieldMask = None, - files: Sequence[cloud_speech.BatchRecognizeFileMetadata] = None, + recognizer: Optional[str] = None, + config: Optional[cloud_speech.RecognitionConfig] = None, + config_mask: Optional[field_mask_pb2.FieldMask] = None, + files: Optional[ + MutableSequence[cloud_speech.BatchRecognizeFileMetadata] + ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Performs batch asynchronous speech recognition: send @@ -1727,7 +1734,7 @@ def sample_batch_recognize(): This corresponds to the ``config_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - files (Sequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]): + files (MutableSequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]): Audio files with file metadata for ASR. @@ -1810,11 +1817,11 @@ def sample_batch_recognize(): def get_config( self, - request: Union[cloud_speech.GetConfigRequest, dict] = None, + request: Optional[Union[cloud_speech.GetConfigRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Config: r"""Returns the requested [Config][google.cloud.speech.v2.Config]. @@ -1917,12 +1924,12 @@ def sample_get_config(): def update_config( self, - request: Union[cloud_speech.UpdateConfigRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateConfigRequest, dict]] = None, *, - config: cloud_speech.Config = None, - update_mask: field_mask_pb2.FieldMask = None, + config: Optional[cloud_speech.Config] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.Config: r"""Updates the [Config][google.cloud.speech.v2.Config]. @@ -2034,13 +2041,13 @@ def sample_update_config(): def create_custom_class( self, - request: Union[cloud_speech.CreateCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.CreateCustomClassRequest, dict]] = None, *, - parent: str = None, - custom_class: cloud_speech.CustomClass = None, - custom_class_id: str = None, + parent: Optional[str] = None, + custom_class: Optional[cloud_speech.CustomClass] = None, + custom_class_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2175,11 +2182,11 @@ def sample_create_custom_class(): def list_custom_classes( self, - request: Union[cloud_speech.ListCustomClassesRequest, dict] = None, + request: Optional[Union[cloud_speech.ListCustomClassesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesPager: r"""Lists CustomClasses. @@ -2293,11 +2300,11 @@ def sample_list_custom_classes(): def get_custom_class( self, - request: Union[cloud_speech.GetCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.GetCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.CustomClass: r"""Returns the requested @@ -2402,12 +2409,12 @@ def sample_get_custom_class(): def update_custom_class( self, - request: Union[cloud_speech.UpdateCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdateCustomClassRequest, dict]] = None, *, - custom_class: cloud_speech.CustomClass = None, - update_mask: field_mask_pb2.FieldMask = None, + custom_class: Optional[cloud_speech.CustomClass] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2536,11 +2543,11 @@ def sample_update_custom_class(): def delete_custom_class( self, - request: Union[cloud_speech.DeleteCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.DeleteCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2655,11 +2662,11 @@ def sample_delete_custom_class(): def undelete_custom_class( self, - request: Union[cloud_speech.UndeleteCustomClassRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeleteCustomClassRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Undeletes the [CustomClass][google.cloud.speech.v2.CustomClass]. @@ -2775,13 +2782,13 @@ def sample_undelete_custom_class(): def create_phrase_set( self, - request: Union[cloud_speech.CreatePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.CreatePhraseSetRequest, dict]] = None, *, - parent: str = None, - phrase_set: cloud_speech.PhraseSet = None, - phrase_set_id: str = None, + parent: Optional[str] = None, + phrase_set: Optional[cloud_speech.PhraseSet] = None, + phrase_set_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -2915,11 +2922,11 @@ def sample_create_phrase_set(): def list_phrase_sets( self, - request: Union[cloud_speech.ListPhraseSetsRequest, dict] = None, + request: Optional[Union[cloud_speech.ListPhraseSetsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetsPager: r"""Lists PhraseSets. @@ -3033,11 +3040,11 @@ def sample_list_phrase_sets(): def get_phrase_set( self, - request: Union[cloud_speech.GetPhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.GetPhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.PhraseSet: r"""Returns the requested @@ -3141,12 +3148,12 @@ def sample_get_phrase_set(): def update_phrase_set( self, - request: Union[cloud_speech.UpdatePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.UpdatePhraseSetRequest, dict]] = None, *, - phrase_set: cloud_speech.PhraseSet = None, - update_mask: field_mask_pb2.FieldMask = None, + phrase_set: Optional[cloud_speech.PhraseSet] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -3274,11 +3281,11 @@ def sample_update_phrase_set(): def delete_phrase_set( self, - request: Union[cloud_speech.DeletePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.DeletePhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -3392,11 +3399,11 @@ def sample_delete_phrase_set(): def undelete_phrase_set( self, - request: Union[cloud_speech.UndeletePhraseSetRequest, dict] = None, + request: Optional[Union[cloud_speech.UndeletePhraseSetRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Undeletes the [PhraseSet][google.cloud.speech.v2.PhraseSet]. @@ -3523,10 +3530,10 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: operations_pb2.ListOperationsRequest = None, + request: Optional[operations_pb2.ListOperationsRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -3577,10 +3584,10 @@ def list_operations( def get_operation( self, - request: operations_pb2.GetOperationRequest = None, + request: Optional[operations_pb2.GetOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -3631,10 +3638,10 @@ def get_operation( def delete_operation( self, - request: operations_pb2.DeleteOperationRequest = None, + request: Optional[operations_pb2.DeleteOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a long-running operation. @@ -3686,10 +3693,10 @@ def delete_operation( def cancel_operation( self, - request: operations_pb2.CancelOperationRequest = None, + request: Optional[operations_pb2.CancelOperationRequest] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -3739,14 +3746,9 @@ def cancel_operation( ) -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("SpeechClient",) diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/base.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/base.py index b2823d5ff1a7..a2799bed602d 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/base.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/base.py @@ -15,7 +15,8 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import pkg_resources + +from google.cloud.speech_v2 import gapic_version as package_version import google.auth # type: ignore import google.api_core @@ -30,14 +31,9 @@ from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-speech", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class SpeechTransport(abc.ABC): @@ -51,7 +47,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc.py index dec4648e8054..06de3d56f7aa 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc.py @@ -50,14 +50,14 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -185,8 +185,8 @@ def __init__( def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc_asyncio.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc_asyncio.py index 99b5c99ebbfc..d0c5f8bb959d 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc_asyncio.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/services/speech/transports/grpc_asyncio.py @@ -52,7 +52,7 @@ class SpeechGrpcAsyncIOTransport(SpeechTransport): def create_channel( cls, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -95,15 +95,15 @@ def __init__( self, *, host: str = "speech.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v2/types/cloud_speech.py b/packages/google-cloud-python-speech/google/cloud/speech_v2/types/cloud_speech.py index 3f6ac7969191..f3f2a1764366 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v2/types/cloud_speech.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v2/types/cloud_speech.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -102,20 +104,20 @@ class CreateRecognizerRequest(proto.Message): ``projects/{project}/locations/{location}``. """ - recognizer = proto.Field( + recognizer: "Recognizer" = proto.Field( proto.MESSAGE, number=1, message="Recognizer", ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - recognizer_id = proto.Field( + recognizer_id: str = proto.Field( proto.STRING, number=3, ) - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=4, ) @@ -234,121 +236,121 @@ class OperationMetadata(proto.Message): This field is a member of `oneof`_ ``metadata``. """ - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) - resource = proto.Field( + resource: str = proto.Field( proto.STRING, number=3, ) - method = proto.Field( + method: str = proto.Field( proto.STRING, number=4, ) - kms_key_name = proto.Field( + kms_key_name: str = proto.Field( proto.STRING, number=6, ) - kms_key_version_name = proto.Field( + kms_key_version_name: str = proto.Field( proto.STRING, number=7, ) - batch_recognize_request = proto.Field( + batch_recognize_request: "BatchRecognizeRequest" = proto.Field( proto.MESSAGE, number=8, oneof="request", message="BatchRecognizeRequest", ) - create_recognizer_request = proto.Field( + create_recognizer_request: "CreateRecognizerRequest" = proto.Field( proto.MESSAGE, number=9, oneof="request", message="CreateRecognizerRequest", ) - update_recognizer_request = proto.Field( + update_recognizer_request: "UpdateRecognizerRequest" = proto.Field( proto.MESSAGE, number=10, oneof="request", message="UpdateRecognizerRequest", ) - delete_recognizer_request = proto.Field( + delete_recognizer_request: "DeleteRecognizerRequest" = proto.Field( proto.MESSAGE, number=11, oneof="request", message="DeleteRecognizerRequest", ) - undelete_recognizer_request = proto.Field( + undelete_recognizer_request: "UndeleteRecognizerRequest" = proto.Field( proto.MESSAGE, number=12, oneof="request", message="UndeleteRecognizerRequest", ) - create_custom_class_request = proto.Field( + create_custom_class_request: "CreateCustomClassRequest" = proto.Field( proto.MESSAGE, number=13, oneof="request", message="CreateCustomClassRequest", ) - update_custom_class_request = proto.Field( + update_custom_class_request: "UpdateCustomClassRequest" = proto.Field( proto.MESSAGE, number=14, oneof="request", message="UpdateCustomClassRequest", ) - delete_custom_class_request = proto.Field( + delete_custom_class_request: "DeleteCustomClassRequest" = proto.Field( proto.MESSAGE, number=15, oneof="request", message="DeleteCustomClassRequest", ) - undelete_custom_class_request = proto.Field( + undelete_custom_class_request: "UndeleteCustomClassRequest" = proto.Field( proto.MESSAGE, number=16, oneof="request", message="UndeleteCustomClassRequest", ) - create_phrase_set_request = proto.Field( + create_phrase_set_request: "CreatePhraseSetRequest" = proto.Field( proto.MESSAGE, number=17, oneof="request", message="CreatePhraseSetRequest", ) - update_phrase_set_request = proto.Field( + update_phrase_set_request: "UpdatePhraseSetRequest" = proto.Field( proto.MESSAGE, number=18, oneof="request", message="UpdatePhraseSetRequest", ) - delete_phrase_set_request = proto.Field( + delete_phrase_set_request: "DeletePhraseSetRequest" = proto.Field( proto.MESSAGE, number=19, oneof="request", message="DeletePhraseSetRequest", ) - undelete_phrase_set_request = proto.Field( + undelete_phrase_set_request: "UndeletePhraseSetRequest" = proto.Field( proto.MESSAGE, number=20, oneof="request", message="UndeletePhraseSetRequest", ) - update_config_request = proto.Field( + update_config_request: "UpdateConfigRequest" = proto.Field( proto.MESSAGE, number=21, oneof="request", message="UpdateConfigRequest", ) - progress_percent = proto.Field( + progress_percent: int = proto.Field( proto.INT32, number=22, ) - batch_recognize_metadata = proto.Field( + batch_recognize_metadata: "BatchRecognizeMetadata" = proto.Field( proto.MESSAGE, number=23, oneof="metadata", @@ -385,19 +387,19 @@ class ListRecognizersRequest(proto.Message): been deleted. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) - show_deleted = proto.Field( + show_deleted: bool = proto.Field( proto.BOOL, number=4, ) @@ -409,7 +411,7 @@ class ListRecognizersResponse(proto.Message): method. Attributes: - recognizers (Sequence[google.cloud.speech_v2.types.Recognizer]): + recognizers (MutableSequence[google.cloud.speech_v2.types.Recognizer]): The list of requested Recognizers. next_page_token (str): A token, which can be sent as @@ -422,12 +424,12 @@ class ListRecognizersResponse(proto.Message): def raw_page(self): return self - recognizers = proto.RepeatedField( + recognizers: MutableSequence["Recognizer"] = proto.RepeatedField( proto.MESSAGE, number=1, message="Recognizer", ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -444,7 +446,7 @@ class GetRecognizerRequest(proto.Message): ``projects/{project}/locations/{location}/recognizers/{recognizer}``. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -472,17 +474,17 @@ class UpdateRecognizerRequest(proto.Message): it. """ - recognizer = proto.Field( + recognizer: "Recognizer" = proto.Field( proto.MESSAGE, number=1, message="Recognizer", ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=4, ) @@ -513,19 +515,19 @@ class DeleteRecognizerRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - allow_missing = proto.Field( + allow_missing: bool = proto.Field( proto.BOOL, number=4, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=3, ) @@ -552,15 +554,15 @@ class UndeleteRecognizerRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=3, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=4, ) @@ -602,7 +604,7 @@ class Recognizer(proto.Message): [SEPARATE_RECOGNITION_PER_CHANNEL][google.cloud.speech.v2.RecognitionFeatures.MultiChannelMode.SEPARATE_RECOGNITION_PER_CHANNEL] is not supported; multi-channel audio is accepted, but only the first channel will be processed and transcribed. - language_codes (Sequence[str]): + language_codes (MutableSequence[str]): Required. The language of the supplied audio as a `BCP-47 `__ language tag. @@ -628,7 +630,7 @@ class Recognizer(proto.Message): in the [RecognizeRequest.config][google.cloud.speech.v2.RecognizeRequest.config] field. - annotations (Mapping[str, str]): + annotations (MutableMapping[str, str]): Allows users to store small amounts of arbitrary data. Both the key and the value must be 63 characters or less each. At most 100 @@ -675,74 +677,74 @@ class State(proto.Enum): ACTIVE = 2 DELETED = 4 - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - uid = proto.Field( + uid: str = proto.Field( proto.STRING, number=2, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=3, ) - model = proto.Field( + model: str = proto.Field( proto.STRING, number=4, ) - language_codes = proto.RepeatedField( + language_codes: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=17, ) - default_recognition_config = proto.Field( + default_recognition_config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=6, message="RecognitionConfig", ) - annotations = proto.MapField( + annotations: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=7, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=8, enum=State, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, ) - delete_time = proto.Field( + delete_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, ) - expire_time = proto.Field( + expire_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=12, ) - reconciling = proto.Field( + reconciling: bool = proto.Field( proto.BOOL, number=13, ) - kms_key_name = proto.Field( + kms_key_name: str = proto.Field( proto.STRING, number=15, ) - kms_key_version_name = proto.Field( + kms_key_version_name: str = proto.Field( proto.STRING, number=16, ) @@ -802,16 +804,16 @@ class AudioEncoding(proto.Enum): MULAW = 2 ALAW = 3 - encoding = proto.Field( + encoding: AudioEncoding = proto.Field( proto.ENUM, number=1, enum=AudioEncoding, ) - sample_rate_hertz = proto.Field( + sample_rate_hertz: int = proto.Field( proto.INT32, number=2, ) - audio_channel_count = proto.Field( + audio_channel_count: int = proto.Field( proto.INT32, number=3, ) @@ -836,11 +838,11 @@ class SpeakerDiarizationConfig(proto.Message): to automatically determine the correct number of speakers. """ - min_speaker_count = proto.Field( + min_speaker_count: int = proto.Field( proto.INT32, number=2, ) - max_speaker_count = proto.Field( + max_speaker_count: int = proto.Field( proto.INT32, number=3, ) @@ -912,41 +914,41 @@ class MultiChannelMode(proto.Enum): MULTI_CHANNEL_MODE_UNSPECIFIED = 0 SEPARATE_RECOGNITION_PER_CHANNEL = 1 - profanity_filter = proto.Field( + profanity_filter: bool = proto.Field( proto.BOOL, number=1, ) - enable_word_time_offsets = proto.Field( + enable_word_time_offsets: bool = proto.Field( proto.BOOL, number=2, ) - enable_word_confidence = proto.Field( + enable_word_confidence: bool = proto.Field( proto.BOOL, number=3, ) - enable_automatic_punctuation = proto.Field( + enable_automatic_punctuation: bool = proto.Field( proto.BOOL, number=4, ) - enable_spoken_punctuation = proto.Field( + enable_spoken_punctuation: bool = proto.Field( proto.BOOL, number=14, ) - enable_spoken_emojis = proto.Field( + enable_spoken_emojis: bool = proto.Field( proto.BOOL, number=15, ) - multi_channel_mode = proto.Field( + multi_channel_mode: MultiChannelMode = proto.Field( proto.ENUM, number=17, enum=MultiChannelMode, ) - diarization_config = proto.Field( + diarization_config: "SpeakerDiarizationConfig" = proto.Field( proto.MESSAGE, number=9, message="SpeakerDiarizationConfig", ) - max_alternatives = proto.Field( + max_alternatives: int = proto.Field( proto.INT32, number=16, ) @@ -959,9 +961,9 @@ class SpeechAdaptation(proto.Message): resource. Attributes: - phrase_sets (Sequence[google.cloud.speech_v2.types.SpeechAdaptation.AdaptationPhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v2.types.SpeechAdaptation.AdaptationPhraseSet]): A list of inline or referenced phrase sets. - custom_classes (Sequence[google.cloud.speech_v2.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v2.types.CustomClass]): A list of inline custom classes. Existing custom class resources can be referenced directly in a phrase set. @@ -992,24 +994,24 @@ class AdaptationPhraseSet(proto.Message): This field is a member of `oneof`_ ``value``. """ - phrase_set = proto.Field( + phrase_set: str = proto.Field( proto.STRING, number=1, oneof="value", ) - inline_phrase_set = proto.Field( + inline_phrase_set: "PhraseSet" = proto.Field( proto.MESSAGE, number=2, oneof="value", message="PhraseSet", ) - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence[AdaptationPhraseSet] = proto.RepeatedField( proto.MESSAGE, number=1, message=AdaptationPhraseSet, ) - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence["CustomClass"] = proto.RepeatedField( proto.MESSAGE, number=2, message="CustomClass", @@ -1047,24 +1049,24 @@ class RecognitionConfig(proto.Message): phrases. """ - auto_decoding_config = proto.Field( + auto_decoding_config: "AutoDetectDecodingConfig" = proto.Field( proto.MESSAGE, number=7, oneof="decoding_config", message="AutoDetectDecodingConfig", ) - explicit_decoding_config = proto.Field( + explicit_decoding_config: "ExplicitDecodingConfig" = proto.Field( proto.MESSAGE, number=8, oneof="decoding_config", message="ExplicitDecodingConfig", ) - features = proto.Field( + features: "RecognitionFeatures" = proto.Field( proto.MESSAGE, number=2, message="RecognitionFeatures", ) - adaptation = proto.Field( + adaptation: "SpeechAdaptation" = proto.Field( proto.MESSAGE, number=6, message="SpeechAdaptation", @@ -1135,26 +1137,26 @@ class RecognizeRequest(proto.Message): This field is a member of `oneof`_ ``audio_source``. """ - recognizer = proto.Field( + recognizer: str = proto.Field( proto.STRING, number=3, ) - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - config_mask = proto.Field( + config_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=8, message=field_mask_pb2.FieldMask, ) - content = proto.Field( + content: bytes = proto.Field( proto.BYTES, number=5, oneof="audio_source", ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=6, oneof="audio_source", @@ -1170,7 +1172,7 @@ class RecognitionResponseMetadata(proto.Message): corresponding request. """ - total_billed_duration = proto.Field( + total_billed_duration: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=6, message=duration_pb2.Duration, @@ -1195,7 +1197,7 @@ class SpeechRecognitionAlternative(proto.Message): 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. - words (Sequence[google.cloud.speech_v2.types.WordInfo]): + words (MutableSequence[google.cloud.speech_v2.types.WordInfo]): A list of word-specific information for each recognized word. When [enable_speaker_diarization][google.cloud.speech.v2.SpeakerDiarizationConfig.enable_speaker_diarization] @@ -1203,15 +1205,15 @@ class SpeechRecognitionAlternative(proto.Message): the audio. """ - transcript = proto.Field( + transcript: str = proto.Field( proto.STRING, number=1, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=2, ) - words = proto.RepeatedField( + words: MutableSequence["WordInfo"] = proto.RepeatedField( proto.MESSAGE, number=3, message="WordInfo", @@ -1261,25 +1263,25 @@ class WordInfo(proto.Message): is ``true`` and only in the top alternative. """ - start_offset = proto.Field( + start_offset: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=1, message=duration_pb2.Duration, ) - end_offset = proto.Field( + end_offset: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=2, message=duration_pb2.Duration, ) - word = proto.Field( + word: str = proto.Field( proto.STRING, number=3, ) - confidence = proto.Field( + confidence: float = proto.Field( proto.FLOAT, number=4, ) - speaker_label = proto.Field( + speaker_label: str = proto.Field( proto.STRING, number=6, ) @@ -1290,7 +1292,7 @@ class SpeechRecognitionResult(proto.Message): audio. Attributes: - alternatives (Sequence[google.cloud.speech_v2.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v2.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses. These alternatives are ordered in terms of accuracy, with the top (first) @@ -1312,21 +1314,21 @@ class SpeechRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=2, ) - result_end_offset = proto.Field( + result_end_offset: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=5, ) @@ -1337,19 +1339,19 @@ class RecognizeResponse(proto.Message): [Recognize][google.cloud.speech.v2.Speech.Recognize] method. Attributes: - results (Sequence[google.cloud.speech_v2.types.SpeechRecognitionResult]): + results (MutableSequence[google.cloud.speech_v2.types.SpeechRecognitionResult]): Sequential list of transcription results corresponding to sequential portions of audio. metadata (google.cloud.speech_v2.types.RecognitionResponseMetadata): Metadata about the recognition. """ - results = proto.RepeatedField( + results: MutableSequence["SpeechRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=3, message="SpeechRecognitionResult", ) - metadata = proto.Field( + metadata: "RecognitionResponseMetadata" = proto.Field( proto.MESSAGE, number=2, message="RecognitionResponseMetadata", @@ -1392,26 +1394,26 @@ class VoiceActivityTimeout(proto.Message): server will close the stream. """ - speech_start_timeout = proto.Field( + speech_start_timeout: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=1, message=duration_pb2.Duration, ) - speech_end_timeout = proto.Field( + speech_end_timeout: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=2, message=duration_pb2.Duration, ) - enable_voice_activity_events = proto.Field( + enable_voice_activity_events: bool = proto.Field( proto.BOOL, number=1, ) - interim_results = proto.Field( + interim_results: bool = proto.Field( proto.BOOL, number=2, ) - voice_activity_timeout = proto.Field( + voice_activity_timeout: VoiceActivityTimeout = proto.Field( proto.MESSAGE, number=3, message=VoiceActivityTimeout, @@ -1452,17 +1454,17 @@ class StreamingRecognitionConfig(proto.Message): requests. """ - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=1, message="RecognitionConfig", ) - config_mask = proto.Field( + config_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=3, message=field_mask_pb2.FieldMask, ) - streaming_features = proto.Field( + streaming_features: "StreamingRecognitionFeatures" = proto.Field( proto.MESSAGE, number=2, message="StreamingRecognitionFeatures", @@ -1515,17 +1517,17 @@ class StreamingRecognizeRequest(proto.Message): This field is a member of `oneof`_ ``streaming_request``. """ - recognizer = proto.Field( + recognizer: str = proto.Field( proto.STRING, number=3, ) - streaming_config = proto.Field( + streaming_config: "StreamingRecognitionConfig" = proto.Field( proto.MESSAGE, number=6, oneof="streaming_request", message="StreamingRecognitionConfig", ) - audio = proto.Field( + audio: bytes = proto.Field( proto.BYTES, number=5, oneof="streaming_request", @@ -1563,25 +1565,25 @@ class BatchRecognizeRequest(proto.Message): [config][google.cloud.speech.v2.BatchRecognizeRequest.config] completely overrides and replaces the config in the recognizer for this recognition request. - files (Sequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]): + files (MutableSequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]): Audio files with file metadata for ASR. """ - recognizer = proto.Field( + recognizer: str = proto.Field( proto.STRING, number=1, ) - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=4, message="RecognitionConfig", ) - config_mask = proto.Field( + config_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask, ) - files = proto.RepeatedField( + files: MutableSequence["BatchRecognizeFileMetadata"] = proto.RepeatedField( proto.MESSAGE, number=3, message="BatchRecognizeFileMetadata", @@ -1595,12 +1597,12 @@ class BatchRecognizeResponse(proto.Message): [Operation][google.longrunning.Operation]. Attributes: - results (Mapping[str, google.cloud.speech_v2.types.BatchRecognizeFileResult]): + results (MutableMapping[str, google.cloud.speech_v2.types.BatchRecognizeFileResult]): Map from filename to the final result for that file. """ - results = proto.MapField( + results: MutableMapping[str, "BatchRecognizeFileResult"] = proto.MapField( proto.STRING, proto.MESSAGE, number=1, @@ -1619,11 +1621,11 @@ class BatchRecognizeFileResult(proto.Message): Error if one was encountered. """ - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=1, ) - error = proto.Field( + error: status_pb2.Status = proto.Field( proto.MESSAGE, number=2, message=status_pb2.Status, @@ -1645,16 +1647,16 @@ class BatchRecognizeTranscriptionMetadata(proto.Message): be written. """ - progress_percent = proto.Field( + progress_percent: int = proto.Field( proto.INT32, number=1, ) - error = proto.Field( + error: status_pb2.Status = proto.Field( proto.MESSAGE, number=2, message=status_pb2.Status, ) - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=3, ) @@ -1665,12 +1667,14 @@ class BatchRecognizeMetadata(proto.Message): [BatchRecognize][google.cloud.speech.v2.Speech.BatchRecognize]. Attributes: - transcription_metadata (Mapping[str, google.cloud.speech_v2.types.BatchRecognizeTranscriptionMetadata]): + transcription_metadata (MutableMapping[str, google.cloud.speech_v2.types.BatchRecognizeTranscriptionMetadata]): Map from provided filename to the transcription metadata for that file. """ - transcription_metadata = proto.MapField( + transcription_metadata: MutableMapping[ + str, "BatchRecognizeTranscriptionMetadata" + ] = proto.MapField( proto.STRING, proto.MESSAGE, number=1, @@ -1714,17 +1718,17 @@ class BatchRecognizeFileMetadata(proto.Message): recognizer for this recognition request. """ - uri = proto.Field( + uri: str = proto.Field( proto.STRING, number=1, oneof="audio_source", ) - config = proto.Field( + config: "RecognitionConfig" = proto.Field( proto.MESSAGE, number=4, message="RecognitionConfig", ) - config_mask = proto.Field( + config_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask, @@ -1736,7 +1740,7 @@ class StreamingRecognitionResult(proto.Message): portion of the audio that is currently being processed. Attributes: - alternatives (Sequence[google.cloud.speech_v2.types.SpeechRecognitionAlternative]): + alternatives (MutableSequence[google.cloud.speech_v2.types.SpeechRecognitionAlternative]): May contain one or more recognition hypotheses. These alternatives are ordered in terms of accuracy, with the top (first) @@ -1775,29 +1779,29 @@ class StreamingRecognitionResult(proto.Message): spoken in the audio. """ - alternatives = proto.RepeatedField( + alternatives: MutableSequence["SpeechRecognitionAlternative"] = proto.RepeatedField( proto.MESSAGE, number=1, message="SpeechRecognitionAlternative", ) - is_final = proto.Field( + is_final: bool = proto.Field( proto.BOOL, number=2, ) - stability = proto.Field( + stability: float = proto.Field( proto.FLOAT, number=3, ) - result_end_offset = proto.Field( + result_end_offset: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=4, message=duration_pb2.Duration, ) - channel_tag = proto.Field( + channel_tag: int = proto.Field( proto.INT32, number=5, ) - language_code = proto.Field( + language_code: str = proto.Field( proto.STRING, number=6, ) @@ -1858,7 +1862,7 @@ class StreamingRecognizeResponse(proto.Message): ``results``. Attributes: - results (Sequence[google.cloud.speech_v2.types.StreamingRecognitionResult]): + results (MutableSequence[google.cloud.speech_v2.types.StreamingRecognitionResult]): This repeated list contains zero or more results that correspond to consecutive portions of the audio currently being processed. It contains zero or one @@ -1882,22 +1886,22 @@ class SpeechEventType(proto.Enum): SPEECH_ACTIVITY_BEGIN = 2 SPEECH_ACTIVITY_END = 3 - results = proto.RepeatedField( + results: MutableSequence["StreamingRecognitionResult"] = proto.RepeatedField( proto.MESSAGE, number=6, message="StreamingRecognitionResult", ) - speech_event_type = proto.Field( + speech_event_type: SpeechEventType = proto.Field( proto.ENUM, number=3, enum=SpeechEventType, ) - speech_event_offset = proto.Field( + speech_event_offset: duration_pb2.Duration = proto.Field( proto.MESSAGE, number=7, message=duration_pb2.Duration, ) - metadata = proto.Field( + metadata: "RecognitionResponseMetadata" = proto.Field( proto.MESSAGE, number=5, message="RecognitionResponseMetadata", @@ -1929,15 +1933,15 @@ class Config(proto.Message): resource was modified. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - kms_key_name = proto.Field( + kms_key_name: str = proto.Field( proto.STRING, number=2, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, @@ -1956,7 +1960,7 @@ class GetConfigRequest(proto.Message): ``projects/{project}/locations/{location}/config``. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -1977,12 +1981,12 @@ class UpdateConfigRequest(proto.Message): The list of fields to be updated. """ - config = proto.Field( + config: "Config" = proto.Field( proto.MESSAGE, number=1, message="Config", ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, @@ -2005,7 +2009,7 @@ class CustomClass(proto.Message): display_name (str): User-settable, human-readable name for the CustomClass. Must be 63 characters or less. - items (Sequence[google.cloud.speech_v2.types.CustomClass.ClassItem]): + items (MutableSequence[google.cloud.speech_v2.types.CustomClass.ClassItem]): A collection of class items. state (google.cloud.speech_v2.types.CustomClass.State): Output only. The CustomClass lifecycle state. @@ -2020,7 +2024,7 @@ class CustomClass(proto.Message): expire_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time at which this resource will be purged. - annotations (Mapping[str, str]): + annotations (MutableMapping[str, str]): Allows users to store small amounts of arbitrary data. Both the key and the value must be 63 characters or less each. At most 100 @@ -2062,71 +2066,71 @@ class ClassItem(proto.Message): The class item's value. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - uid = proto.Field( + uid: str = proto.Field( proto.STRING, number=2, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=4, ) - items = proto.RepeatedField( + items: MutableSequence[ClassItem] = proto.RepeatedField( proto.MESSAGE, number=5, message=ClassItem, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=15, enum=State, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - delete_time = proto.Field( + delete_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp, ) - expire_time = proto.Field( + expire_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, ) - annotations = proto.MapField( + annotations: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=10, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=11, ) - reconciling = proto.Field( + reconciling: bool = proto.Field( proto.BOOL, number=12, ) - kms_key_name = proto.Field( + kms_key_name: str = proto.Field( proto.STRING, number=13, ) - kms_key_version_name = proto.Field( + kms_key_version_name: str = proto.Field( proto.STRING, number=14, ) @@ -2144,7 +2148,7 @@ class PhraseSet(proto.Message): uid (str): Output only. System-assigned unique identifier for the PhraseSet. - phrases (Sequence[google.cloud.speech_v2.types.PhraseSet.Phrase]): + phrases (MutableSequence[google.cloud.speech_v2.types.PhraseSet.Phrase]): A list of word and phrases. boost (float): Hint Boost. Positive value will increase the probability @@ -2170,7 +2174,7 @@ class PhraseSet(proto.Message): expire_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time at which this resource will be purged. - annotations (Mapping[str, str]): + annotations (MutableMapping[str, str]): Allows users to store small amounts of arbitrary data. Both the key and the value must be 63 characters or less each. At most 100 @@ -2234,79 +2238,79 @@ class Phrase(proto.Message): skip PhraseSets with a boost value of 0. """ - value = proto.Field( + value: str = proto.Field( proto.STRING, number=1, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=2, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - uid = proto.Field( + uid: str = proto.Field( proto.STRING, number=2, ) - phrases = proto.RepeatedField( + phrases: MutableSequence[Phrase] = proto.RepeatedField( proto.MESSAGE, number=3, message=Phrase, ) - boost = proto.Field( + boost: float = proto.Field( proto.FLOAT, number=4, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=5, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=15, enum=State, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - delete_time = proto.Field( + delete_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp, ) - expire_time = proto.Field( + expire_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, ) - annotations = proto.MapField( + annotations: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=10, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=11, ) - reconciling = proto.Field( + reconciling: bool = proto.Field( proto.BOOL, number=12, ) - kms_key_name = proto.Field( + kms_key_name: str = proto.Field( proto.STRING, number=13, ) - kms_key_version_name = proto.Field( + kms_key_version_name: str = proto.Field( proto.STRING, number=14, ) @@ -2335,20 +2339,20 @@ class CreateCustomClassRequest(proto.Message): ``projects/{project}/locations/{location}``. """ - custom_class = proto.Field( + custom_class: "CustomClass" = proto.Field( proto.MESSAGE, number=1, message="CustomClass", ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - custom_class_id = proto.Field( + custom_class_id: str = proto.Field( proto.STRING, number=3, ) - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=4, ) @@ -2384,19 +2388,19 @@ class ListCustomClassesRequest(proto.Message): been deleted. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) - show_deleted = proto.Field( + show_deleted: bool = proto.Field( proto.BOOL, number=4, ) @@ -2408,7 +2412,7 @@ class ListCustomClassesResponse(proto.Message): method. Attributes: - custom_classes (Sequence[google.cloud.speech_v2.types.CustomClass]): + custom_classes (MutableSequence[google.cloud.speech_v2.types.CustomClass]): The list of requested CustomClasses. next_page_token (str): A token, which can be sent as @@ -2421,12 +2425,12 @@ class ListCustomClassesResponse(proto.Message): def raw_page(self): return self - custom_classes = proto.RepeatedField( + custom_classes: MutableSequence["CustomClass"] = proto.RepeatedField( proto.MESSAGE, number=1, message="CustomClass", ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -2444,7 +2448,7 @@ class GetCustomClassRequest(proto.Message): ``projects/{project}/locations/{location}/customClasses/{custom_class}``. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -2471,17 +2475,17 @@ class UpdateCustomClassRequest(proto.Message): it. """ - custom_class = proto.Field( + custom_class: "CustomClass" = proto.Field( proto.MESSAGE, number=1, message="CustomClass", ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=4, ) @@ -2512,19 +2516,19 @@ class DeleteCustomClassRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - allow_missing = proto.Field( + allow_missing: bool = proto.Field( proto.BOOL, number=4, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=3, ) @@ -2551,15 +2555,15 @@ class UndeleteCustomClassRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=3, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=4, ) @@ -2588,20 +2592,20 @@ class CreatePhraseSetRequest(proto.Message): ``projects/{project}/locations/{location}``. """ - phrase_set = proto.Field( + phrase_set: "PhraseSet" = proto.Field( proto.MESSAGE, number=1, message="PhraseSet", ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - phrase_set_id = proto.Field( + phrase_set_id: str = proto.Field( proto.STRING, number=3, ) - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=4, ) @@ -2636,19 +2640,19 @@ class ListPhraseSetsRequest(proto.Message): been deleted. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) - show_deleted = proto.Field( + show_deleted: bool = proto.Field( proto.BOOL, number=4, ) @@ -2660,7 +2664,7 @@ class ListPhraseSetsResponse(proto.Message): method. Attributes: - phrase_sets (Sequence[google.cloud.speech_v2.types.PhraseSet]): + phrase_sets (MutableSequence[google.cloud.speech_v2.types.PhraseSet]): The list of requested PhraseSets. next_page_token (str): A token, which can be sent as @@ -2673,12 +2677,12 @@ class ListPhraseSetsResponse(proto.Message): def raw_page(self): return self - phrase_sets = proto.RepeatedField( + phrase_sets: MutableSequence["PhraseSet"] = proto.RepeatedField( proto.MESSAGE, number=1, message="PhraseSet", ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) @@ -2695,7 +2699,7 @@ class GetPhraseSetRequest(proto.Message): ``projects/{project}/locations/{location}/phraseSets/{phrase_set}``. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -2723,17 +2727,17 @@ class UpdatePhraseSetRequest(proto.Message): it. """ - phrase_set = proto.Field( + phrase_set: "PhraseSet" = proto.Field( proto.MESSAGE, number=1, message="PhraseSet", ) - update_mask = proto.Field( + update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=4, ) @@ -2764,19 +2768,19 @@ class DeletePhraseSetRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=2, ) - allow_missing = proto.Field( + allow_missing: bool = proto.Field( proto.BOOL, number=4, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=3, ) @@ -2803,15 +2807,15 @@ class UndeletePhraseSetRequest(proto.Message): proceeding. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - validate_only = proto.Field( + validate_only: bool = proto.Field( proto.BOOL, number=3, ) - etag = proto.Field( + etag: str = proto.Field( proto.STRING, number=4, ) diff --git a/packages/google-cloud-python-speech/owlbot.py b/packages/google-cloud-python-speech/owlbot.py index cda41e362651..4bf4e673d8bc 100644 --- a/packages/google-cloud-python-speech/owlbot.py +++ b/packages/google-cloud-python-speech/owlbot.py @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,17 +12,30 @@ # 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 json +from pathlib import Path +import shutil import synthtool as s -from synthtool import gcp +import synthtool.gcp as gcp from synthtool.languages import python -common = gcp.CommonTemplates() +# ---------------------------------------------------------------------------- +# Copy the generated client from the owl-bot staging directory +# ---------------------------------------------------------------------------- + +clean_up_generated_samples = True -default_version = "v1" +# Load the default version defined in .repo-metadata.json. +default_version = json.load(open(".repo-metadata.json", "rt")).get( + "default_version" +) for library in s.get_staging_dirs(default_version): + if clean_up_generated_samples: + shutil.rmtree("samples/generated_samples", ignore_errors=True) + clean_up_generated_samples = False + if "v1" in library.name: # Add the manually written SpeechHelpers to v1 and v1p1beta1 # See google/cloud/speech_v1/helpers.py for details @@ -46,27 +59,27 @@ class SpeechClient(SpeechHelpers, SpeechClient): ) assert count == 1 - s.move(library, excludes=["setup.py"]) - + s.replace( + library / "google/cloud/speech_v*/__init__.py", + "from google.cloud.speech import gapic_version as package_version", + f"from google.cloud.speech_{library.name} import gapic_version as package_version", + ) + s.move([library], excludes=["**/gapic_version.py"]) s.remove_staging_dirs() # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- -templated_files = common.py_library( + +templated_files = gcp.CommonTemplates().py_library( + cov_level=100, microgenerator=True, versions=gcp.common.detect_versions(path="./google", default_first=True), ) -s.move( - templated_files, excludes=[".coveragerc"] -) # microgenerator has a good .coveragerc file - -python.configure_previous_major_version_branches() - -# ---------------------------------------------------------------------------- -# Samples templates -# ---------------------------------------------------------------------------- +s.move(templated_files, excludes=[".coveragerc", ".github/release-please.yml"]) python.py_samples(skip_readmes=True) -s.shell.run(["nox", "-s", "blacken"], hide_output=False) +# run format session for all directories which have a noxfile +for noxfile in Path(".").glob("**/noxfile.py"): + s.shell.run(["nox", "-s", "blacken"], cwd=noxfile.parent, hide_output=False) diff --git a/packages/google-cloud-python-speech/release-please-config.json b/packages/google-cloud-python-speech/release-please-config.json new file mode 100644 index 000000000000..25ee9d596768 --- /dev/null +++ b/packages/google-cloud-python-speech/release-please-config.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "packages": { + ".": { + "release-type": "python", + "extra-files": [ + "google/cloud/speech_v2/gapic_version.py", + "google/cloud/speech_v1/gapic_version.py", + "google/cloud/speech_v1p1beta1/gapic_version.py", + "google/cloud/speech/gapic_version.py", + { + "type": "json", + "path": "samples/generated_samples/snippet_metadata_google.cloud.speech.v1p1beta1.json", + "jsonpath": "$.clientLibrary.version" + }, + { + "type": "json", + "path": "samples/generated_samples/snippet_metadata_google.cloud.speech.v2.json", + "jsonpath": "$.clientLibrary.version" + }, + { + "type": "json", + "path": "samples/generated_samples/snippet_metadata_google.cloud.speech.v1.json", + "jsonpath": "$.clientLibrary.version" + } + ] + } + }, + "release-type": "python", + "plugins": [ + { + "type": "sentence-case" + } + ], + "initial-version": "0.1.0" +} + \ No newline at end of file diff --git a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1.json b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1.json similarity index 99% rename from packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1.json rename to packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1.json index fef347d79dea..c793efe0e3c8 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1.json +++ b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1.json @@ -7,7 +7,8 @@ } ], "language": "PYTHON", - "name": "google-cloud-speech" + "name": "google-cloud-speech", + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1p1beta1.json b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1p1beta1.json similarity index 99% rename from packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1p1beta1.json rename to packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1p1beta1.json index 4d8a8b90c001..b51d437c94b0 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v1p1beta1.json +++ b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v1p1beta1.json @@ -7,7 +7,8 @@ } ], "language": "PYTHON", - "name": "google-cloud-speech" + "name": "google-cloud-speech", + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v2.json b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v2.json similarity index 99% rename from packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v2.json rename to packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v2.json index cd0f56ae8397..cdf74909cdd7 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_speech_v2.json +++ b/packages/google-cloud-python-speech/samples/generated_samples/snippet_metadata_google.cloud.speech.v2.json @@ -7,7 +7,8 @@ } ], "language": "PYTHON", - "name": "google-cloud-speech" + "name": "google-cloud-speech", + "version": "0.1.0" }, "snippets": [ { @@ -46,7 +47,7 @@ }, { "name": "files", - "type": "Sequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]" + "type": "MutableSequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]" }, { "name": "retry", @@ -138,7 +139,7 @@ }, { "name": "files", - "type": "Sequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]" + "type": "MutableSequence[google.cloud.speech_v2.types.BatchRecognizeFileMetadata]" }, { "name": "retry", diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v1_generated_speech_long_running_recognize_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v1_generated_speech_long_running_recognize_async.py index 98af31d837b9..c216ad43c2a5 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v1_generated_speech_long_running_recognize_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v1_generated_speech_long_running_recognize_async.py @@ -55,7 +55,7 @@ async def sample_long_running_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v1p1beta1_generated_speech_long_running_recognize_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v1p1beta1_generated_speech_long_running_recognize_async.py index cd291d9eff05..2ccda75e3391 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v1p1beta1_generated_speech_long_running_recognize_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v1p1beta1_generated_speech_long_running_recognize_async.py @@ -55,7 +55,7 @@ async def sample_long_running_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_batch_recognize_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_batch_recognize_async.py index 64de219fe419..7421e58eb6fb 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_batch_recognize_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_batch_recognize_async.py @@ -48,7 +48,7 @@ async def sample_batch_recognize(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_custom_class_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_custom_class_async.py index cad6b2f12694..ac34d16b2dae 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_custom_class_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_custom_class_async.py @@ -48,7 +48,7 @@ async def sample_create_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_phrase_set_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_phrase_set_async.py index d2932bee3778..90721b21c251 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_phrase_set_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_phrase_set_async.py @@ -48,7 +48,7 @@ async def sample_create_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_recognizer_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_recognizer_async.py index eb62638eb3a9..03dbbce76642 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_recognizer_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_create_recognizer_async.py @@ -53,7 +53,7 @@ async def sample_create_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_custom_class_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_custom_class_async.py index 64dce73c81da..e166f4ca6efe 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_custom_class_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_custom_class_async.py @@ -48,7 +48,7 @@ async def sample_delete_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_phrase_set_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_phrase_set_async.py index d5f1c64bfd9a..14fd5d671893 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_phrase_set_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_phrase_set_async.py @@ -48,7 +48,7 @@ async def sample_delete_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_recognizer_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_recognizer_async.py index 8de3bedd71bb..1ef850a84285 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_recognizer_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_delete_recognizer_async.py @@ -48,7 +48,7 @@ async def sample_delete_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_custom_class_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_custom_class_async.py index 2ae43d7f72d3..3ae9ff321b90 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_custom_class_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_custom_class_async.py @@ -48,7 +48,7 @@ async def sample_undelete_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_phrase_set_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_phrase_set_async.py index 77808995b1c8..5b06559b2330 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_phrase_set_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_phrase_set_async.py @@ -48,7 +48,7 @@ async def sample_undelete_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_recognizer_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_recognizer_async.py index eb58be11bd8f..2754c91b4639 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_recognizer_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_undelete_recognizer_async.py @@ -48,7 +48,7 @@ async def sample_undelete_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_custom_class_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_custom_class_async.py index 959038979403..ec13c2f1ee32 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_custom_class_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_custom_class_async.py @@ -47,7 +47,7 @@ async def sample_update_custom_class(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_phrase_set_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_phrase_set_async.py index 02ee5d96efc0..0f14f7088b26 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_phrase_set_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_phrase_set_async.py @@ -47,7 +47,7 @@ async def sample_update_phrase_set(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_recognizer_async.py b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_recognizer_async.py index d29f724c271f..cc2f894c61aa 100644 --- a/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_recognizer_async.py +++ b/packages/google-cloud-python-speech/samples/generated_samples/speech_v2_generated_speech_update_recognizer_async.py @@ -52,7 +52,7 @@ async def sample_update_recognizer(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/packages/google-cloud-python-speech/samples/microphone/noxfile.py b/packages/google-cloud-python-speech/samples/microphone/noxfile.py index f5c32b22789b..e8283c38d4a0 100644 --- a/packages/google-cloud-python-speech/samples/microphone/noxfile.py +++ b/packages/google-cloud-python-speech/samples/microphone/noxfile.py @@ -160,6 +160,7 @@ def blacken(session: nox.sessions.Session) -> None: # format = isort + black # + @nox.session def format(session: nox.sessions.Session) -> None: """ @@ -187,7 +188,9 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( + "**/test_*.py", recursive=True + ) test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: @@ -209,9 +212,7 @@ def _session_tests( if os.path.exists("requirements-test.txt"): if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") else: session.install("-r", "requirements-test.txt") with open("requirements-test.txt") as rtfile: @@ -224,9 +225,9 @@ def _session_tests( post_install(session) if "pytest-parallel" in packages: - concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) elif "pytest-xdist" in packages: - concurrent_args.extend(['-n', 'auto']) + concurrent_args.extend(["-n", "auto"]) session.run( "pytest", @@ -256,7 +257,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference.py b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference.py index 7cae68c071f2..6185818d7dbe 100644 --- a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference.py +++ b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference.py @@ -20,7 +20,9 @@ from google.cloud.speech_v2.types import cloud_speech -def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_id, custom_class_id, audio_file): +def adaptation_v2_custom_class_reference( + project_id, recognizer_id, phrase_set_id, custom_class_id, audio_file +): # Instantiates a client client = SpeechClient() @@ -44,7 +46,8 @@ def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_i request = cloud_speech.CreateCustomClassRequest( parent=f"projects/{project_id}/locations/global", custom_class_id=custom_class_id, - custom_class=cloud_speech.CustomClass(items=[{"value": "fare"}])) + custom_class=cloud_speech.CustomClass(items=[{"value": "fare"}]), + ) operation = client.create_custom_class(request=request) custom_class = operation.result() @@ -53,7 +56,10 @@ def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_i request = cloud_speech.CreatePhraseSetRequest( parent=f"projects/{project_id}/locations/global", phrase_set_id=phrase_set_id, - phrase_set=cloud_speech.PhraseSet(phrases=[{"value": f"${{{custom_class.name}}}", "boost": 20}])) + phrase_set=cloud_speech.PhraseSet( + phrases=[{"value": f"${{{custom_class.name}}}", "boost": 20}] + ), + ) operation = client.create_phrase_set(request=request) phrase_set = operation.result() @@ -81,6 +87,8 @@ def adaptation_v2_custom_class_reference(project_id, recognizer_id, phrase_set_i print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_adaptation_v2_custom_class_reference] diff --git a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference_test.py b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference_test.py index b869f4405519..618424fa4c96 100644 --- a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference_test.py +++ b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_custom_class_reference_test.py @@ -47,8 +47,14 @@ def test_adaptation_v2_custom_class_reference(capsys): recognizer_id = "recognizer-" + str(uuid4()) phrase_set_id = "phrase-set-" + str(uuid4()) custom_class_id = "custom-class-" + str(uuid4()) - response = adaptation_v2_custom_class_reference.adaptation_v2_custom_class_reference( - project_id, recognizer_id, phrase_set_id, custom_class_id, os.path.join(RESOURCES, "fair.wav") + response = ( + adaptation_v2_custom_class_reference.adaptation_v2_custom_class_reference( + project_id, + recognizer_id, + phrase_set_id, + custom_class_id, + os.path.join(RESOURCES, "fair.wav"), + ) ) assert re.search( diff --git a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_custom_class.py b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_custom_class.py index 3c362fc35c39..77991fd9d571 100644 --- a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_custom_class.py +++ b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_custom_class.py @@ -49,7 +49,7 @@ def adaptation_v2_inline_custom_class(project_id, recognizer_id, audio_file): inline_phrase_set=phrase_set ) ], - custom_classes=[custom_class] + custom_classes=[custom_class], ) config = cloud_speech.RecognitionConfig( auto_decoding_config={}, adaptation=adaptation @@ -66,6 +66,8 @@ def adaptation_v2_inline_custom_class(project_id, recognizer_id, audio_file): print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_adaptation_v2_inline_custom_class] diff --git a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_phrase_set.py b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_phrase_set.py index e6bd581e1317..a51e468f3141 100644 --- a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_phrase_set.py +++ b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_inline_phrase_set.py @@ -64,6 +64,8 @@ def adaptation_v2_inline_phrase_set(project_id, recognizer_id, audio_file): print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_adaptation_v2_inline_phrase_set] diff --git a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_phrase_set_reference.py b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_phrase_set_reference.py index ceb728557a1c..ae479db0ac83 100644 --- a/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_phrase_set_reference.py +++ b/packages/google-cloud-python-speech/samples/snippets/adaptation_v2_phrase_set_reference.py @@ -20,7 +20,9 @@ from google.cloud.speech_v2.types import cloud_speech -def adaptation_v2_phrase_set_reference(project_id, recognizer_id, phrase_set_id, audio_file): +def adaptation_v2_phrase_set_reference( + project_id, recognizer_id, phrase_set_id, audio_file +): # Instantiates a client client = SpeechClient() @@ -44,7 +46,8 @@ def adaptation_v2_phrase_set_reference(project_id, recognizer_id, phrase_set_id, request = cloud_speech.CreatePhraseSetRequest( parent=f"projects/{project_id}/locations/global", phrase_set_id=phrase_set_id, - phrase_set=cloud_speech.PhraseSet(phrases=[{"value": "fare", "boost": 10}])) + phrase_set=cloud_speech.PhraseSet(phrases=[{"value": "fare", "boost": 10}]), + ) operation = client.create_phrase_set(request=request) phrase_set = operation.result() @@ -72,6 +75,8 @@ def adaptation_v2_phrase_set_reference(project_id, recognizer_id, phrase_set_id, print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_adaptation_v2_phrase_set_reference] diff --git a/packages/google-cloud-python-speech/samples/snippets/beta_snippets.py b/packages/google-cloud-python-speech/samples/snippets/beta_snippets.py index 51702e2bf8dc..1360dabeed55 100644 --- a/packages/google-cloud-python-speech/samples/snippets/beta_snippets.py +++ b/packages/google-cloud-python-speech/samples/snippets/beta_snippets.py @@ -59,8 +59,8 @@ def transcribe_file_with_enhanced_model(): for i, result in enumerate(response.results): alternative = result.alternatives[0] print("-" * 20) - print(u"First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("First alternative of result {}".format(i)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_enhanced_model_beta] @@ -108,8 +108,8 @@ def transcribe_file_with_metadata(): for i, result in enumerate(response.results): alternative = result.alternatives[0] print("-" * 20) - print(u"First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("First alternative of result {}".format(i)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_recognition_metadata_beta] @@ -139,8 +139,8 @@ def transcribe_file_with_auto_punctuation(): for i, result in enumerate(response.results): alternative = result.alternatives[0] print("-" * 20) - print(u"First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("First alternative of result {}".format(i)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_auto_punctuation_beta] @@ -159,9 +159,9 @@ def transcribe_file_with_diarization(): audio = speech.RecognitionAudio(content=content) diarization_config = speech.SpeakerDiarizationConfig( - enable_speaker_diarization=True, - min_speaker_count=2, - max_speaker_count=10, + enable_speaker_diarization=True, + min_speaker_count=2, + max_speaker_count=10, ) config = speech.RecognitionConfig( @@ -185,7 +185,7 @@ def transcribe_file_with_diarization(): # Printing out the output: for word_info in words_info: print( - u"word: '{}', speaker_tag: {}".format(word_info.word, word_info.speaker_tag) + "word: '{}', speaker_tag: {}".format(word_info.word, word_info.speaker_tag) ) # [END speech_transcribe_diarization_beta] @@ -219,8 +219,8 @@ def transcribe_file_with_multichannel(): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) - print(u"Channel Tag: {}".format(result.channel_tag)) + print("Transcript: {}".format(alternative.transcript)) + print("Channel Tag: {}".format(result.channel_tag)) # [END speech_transcribe_multichannel_beta] @@ -255,8 +255,8 @@ def transcribe_file_with_multilanguage(): for i, result in enumerate(response.results): alternative = result.alternatives[0] print("-" * 20) - print(u"First alternative of result {}: {}".format(i, alternative)) - print(u"Transcript: {}".format(alternative.transcript)) + print("First alternative of result {}: {}".format(i, alternative)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_multilanguage_beta] @@ -288,9 +288,9 @@ def transcribe_file_with_word_level_confidence(): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) print( - u"First Word and Confidence: ({}, {})".format( + "First Word and Confidence: ({}, {})".format( alternative.words[0].word, alternative.words[0].confidence ) ) @@ -326,8 +326,8 @@ def transcribe_file_with_spoken_punctuation_end_emojis(): for i, result in enumerate(response.results): alternative = result.alternatives[0] print("-" * 20) - print(u"First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("First alternative of result {}".format(i)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_spoken_punctuation_emojis_beta] diff --git a/packages/google-cloud-python-speech/samples/snippets/create_recognizer.py b/packages/google-cloud-python-speech/samples/snippets/create_recognizer.py index 986e7c5cd0ca..43a3efcbe14d 100644 --- a/packages/google-cloud-python-speech/samples/snippets/create_recognizer.py +++ b/packages/google-cloud-python-speech/samples/snippets/create_recognizer.py @@ -35,6 +35,8 @@ def create_recognizer(project_id, recognizer_id): print("Created Recognizer:", recognizer.name) return recognizer + + # [END speech_create_recognizer] diff --git a/packages/google-cloud-python-speech/samples/snippets/noxfile.py b/packages/google-cloud-python-speech/samples/snippets/noxfile.py index f5c32b22789b..e8283c38d4a0 100644 --- a/packages/google-cloud-python-speech/samples/snippets/noxfile.py +++ b/packages/google-cloud-python-speech/samples/snippets/noxfile.py @@ -160,6 +160,7 @@ def blacken(session: nox.sessions.Session) -> None: # format = isort + black # + @nox.session def format(session: nox.sessions.Session) -> None: """ @@ -187,7 +188,9 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( + "**/test_*.py", recursive=True + ) test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: @@ -209,9 +212,7 @@ def _session_tests( if os.path.exists("requirements-test.txt"): if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") else: session.install("-r", "requirements-test.txt") with open("requirements-test.txt") as rtfile: @@ -224,9 +225,9 @@ def _session_tests( post_install(session) if "pytest-parallel" in packages: - concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) elif "pytest-xdist" in packages: - concurrent_args.extend(['-n', 'auto']) + concurrent_args.extend(["-n", "auto"]) session.run( "pytest", @@ -256,7 +257,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/packages/google-cloud-python-speech/samples/snippets/profanity_filter.py b/packages/google-cloud-python-speech/samples/snippets/profanity_filter.py index c588691776b2..0cf2b5e960c7 100644 --- a/packages/google-cloud-python-speech/samples/snippets/profanity_filter.py +++ b/packages/google-cloud-python-speech/samples/snippets/profanity_filter.py @@ -39,7 +39,7 @@ def sync_recognize_with_profanity_filter_gcs(gcs_uri): for i, result in enumerate(response.results): alternative = result.alternatives[0] - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_recognize_with_profanity_filter_gcs] diff --git a/packages/google-cloud-python-speech/samples/snippets/quickstart_v2.py b/packages/google-cloud-python-speech/samples/snippets/quickstart_v2.py index d045c42c4655..6ba58ef7ec8d 100644 --- a/packages/google-cloud-python-speech/samples/snippets/quickstart_v2.py +++ b/packages/google-cloud-python-speech/samples/snippets/quickstart_v2.py @@ -53,6 +53,8 @@ def quickstart_v2(project_id, recognizer_id, audio_file): print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_quickstart_v2] diff --git a/packages/google-cloud-python-speech/samples/snippets/speech_adaptation_beta.py b/packages/google-cloud-python-speech/samples/snippets/speech_adaptation_beta.py index 8543519a9fd4..bf254b27e13e 100644 --- a/packages/google-cloud-python-speech/samples/snippets/speech_adaptation_beta.py +++ b/packages/google-cloud-python-speech/samples/snippets/speech_adaptation_beta.py @@ -76,7 +76,7 @@ def sample_recognize(storage_uri, phrase): for result in response.results: # First alternative is the most probable result alternative = result.alternatives[0] - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_adaptation_beta] return response diff --git a/packages/google-cloud-python-speech/samples/snippets/speech_quickstart_beta.py b/packages/google-cloud-python-speech/samples/snippets/speech_quickstart_beta.py index d40e6d32f1c8..b507ac633a32 100644 --- a/packages/google-cloud-python-speech/samples/snippets/speech_quickstart_beta.py +++ b/packages/google-cloud-python-speech/samples/snippets/speech_quickstart_beta.py @@ -61,7 +61,7 @@ def sample_recognize(storage_uri): for result in response.results: # First alternative is the most probable result alternative = result.alternatives[0] - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_quickstart_beta] return response diff --git a/packages/google-cloud-python-speech/samples/snippets/speech_to_storage_beta.py b/packages/google-cloud-python-speech/samples/snippets/speech_to_storage_beta.py index 549388285f6e..5b0e4a102d4b 100644 --- a/packages/google-cloud-python-speech/samples/snippets/speech_to_storage_beta.py +++ b/packages/google-cloud-python-speech/samples/snippets/speech_to_storage_beta.py @@ -81,5 +81,5 @@ def export_transcript_to_storage_beta( print(f"Transcript: {result.alternatives[0].transcript}") print(f"Confidence: {result.alternatives[0].confidence}") -# [END speech_transcribe_with_speech_to_storage_beta] + # [END speech_transcribe_with_speech_to_storage_beta] return storage_transcript.results diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe.py b/packages/google-cloud-python-speech/samples/snippets/transcribe.py index 9243c7963978..3d45a82841a2 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe.py @@ -54,7 +54,7 @@ def transcribe_file(speech_file): # them to get the transcripts for the entire audio file. for result in response.results: # The first alternative is the most likely one for this portion. - print(u"Transcript: {}".format(result.alternatives[0].transcript)) + print("Transcript: {}".format(result.alternatives[0].transcript)) # [END speech_python_migration_sync_response] @@ -83,7 +83,7 @@ def transcribe_gcs(gcs_uri): # them to get the transcripts for the entire audio file. for result in response.results: # The first alternative is the most likely one for this portion. - print(u"Transcript: {}".format(result.alternatives[0].transcript)) + print("Transcript: {}".format(result.alternatives[0].transcript)) # [END speech_transcribe_sync_gcs] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_async_file.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_async_file.py index db5ed5c37b73..e35073121229 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_async_file.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_async_file.py @@ -52,7 +52,7 @@ def transcribe_file(speech_file): # them to get the transcripts for the entire audio file. for result in response.results: # The first alternative is the most likely one for this portion. - print(u"Transcript: {}".format(result.alternatives[0].transcript)) + print("Transcript: {}".format(result.alternatives[0].transcript)) print("Confidence: {}".format(result.alternatives[0].confidence)) # [END speech_python_migration_async_response] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_async_gcs.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_async_gcs.py index 727b91512d2e..cb8207bacbbc 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_async_gcs.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_async_gcs.py @@ -40,6 +40,8 @@ def transcribe_gcs(gcs_uri): # them to get the transcripts for the entire audio file. for result in response.results: # The first alternative is the most likely one for this portion. - print(u"Transcript: {}".format(result.alternatives[0].transcript)) + print("Transcript: {}".format(result.alternatives[0].transcript)) print("Confidence: {}".format(result.alternatives[0].confidence)) + + # [END speech_transcribe_async_gcs] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_file_v2.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_file_v2.py index ef923051e2be..92bdf53cc478 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_file_v2.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_file_v2.py @@ -53,6 +53,8 @@ def transcribe_file_v2(project_id, recognizer_id, audio_file): print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_transcribe_file_v2] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_gcs_v2.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_gcs_v2.py index 0d9bdefe668a..592822fb9af6 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_gcs_v2.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_gcs_v2.py @@ -47,6 +47,8 @@ def transcribe_gcs_v2(project_id, recognizer_id, gcs_uri): print("Transcript: {}".format(result.alternatives[0].transcript)) return response + + # [END speech_transcribe_gcs_v2] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_model_selection.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_model_selection.py index 76db3c9cd731..6749853570af 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_model_selection.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_model_selection.py @@ -53,7 +53,7 @@ def transcribe_model_selection(speech_file, model): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_model_selection] @@ -85,7 +85,7 @@ def transcribe_model_selection_gcs(gcs_uri, model): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_transcribe_model_selection_gcs] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_multichannel.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_multichannel.py index 245738553111..34f498219fe4 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_multichannel.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_multichannel.py @@ -52,8 +52,8 @@ def transcribe_file_with_multichannel(speech_file): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) - print(u"Channel Tag: {}".format(result.channel_tag)) + print("Transcript: {}".format(alternative.transcript)) + print("Channel Tag: {}".format(result.channel_tag)) # [END speech_transcribe_multichannel] @@ -81,8 +81,8 @@ def transcribe_gcs_with_multichannel(gcs_uri): alternative = result.alternatives[0] print("-" * 20) print("First alternative of result {}".format(i)) - print(u"Transcript: {}".format(alternative.transcript)) - print(u"Channel Tag: {}".format(result.channel_tag)) + print("Transcript: {}".format(alternative.transcript)) + print("Channel Tag: {}".format(result.channel_tag)) # [END speech_transcribe_multichannel_gcs] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming.py index 979478a6aae5..5b9abedc77b3 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming.py @@ -69,7 +69,7 @@ def transcribe_streaming(stream_file): # The alternatives are ordered from most likely to least. for alternative in alternatives: print("Confidence: {}".format(alternative.confidence)) - print(u"Transcript: {}".format(alternative.transcript)) + print("Transcript: {}".format(alternative.transcript)) # [END speech_python_migration_streaming_response] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_v2.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_v2.py index d6f3fa57d991..1cba1206de12 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_v2.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_v2.py @@ -74,6 +74,8 @@ def requests(config, audio): print("Transcript: {}".format(result.alternatives[0].transcript)) return responses + + # [END speech_transcribe_streaming_v2] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_events.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_events.py index 50689433669a..65d6976eb0c0 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_events.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_events.py @@ -92,6 +92,8 @@ def requests(config, audio): print("Transcript: {}".format(result.alternatives[0].transcript)) return responses + + # [END speech_transcribe_streaming_voice_activity_events] diff --git a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_timeouts.py b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_timeouts.py index 6b6bdfef03b0..3c68ef987c3a 100644 --- a/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_timeouts.py +++ b/packages/google-cloud-python-speech/samples/snippets/transcribe_streaming_voice_activity_timeouts.py @@ -107,6 +107,8 @@ def requests(config, audio): print("Transcript: {}".format(result.alternatives[0].transcript)) return responses + + # [END speech_transcribe_streaming_voice_activity_timeouts] diff --git a/packages/google-cloud-python-speech/setup.py b/packages/google-cloud-python-speech/setup.py index c84cde4b9586..e110ab2b50a4 100644 --- a/packages/google-cloud-python-speech/setup.py +++ b/packages/google-cloud-python-speech/setup.py @@ -1,4 +1,5 @@ -# Copyright 2018 Google LLC +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,32 +12,35 @@ # 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 io import os -import setuptools +import setuptools # type: ignore - -# Package metadata. +package_root = os.path.abspath(os.path.dirname(__file__)) name = "google-cloud-speech" + + description = "Google Cloud Speech API client library" -version = "2.16.2" -# Should be one of: -# 'Development Status :: 3 - Alpha' -# 'Development Status :: 4 - Beta' -# 'Development Status :: 5 - Production/Stable' -release_status = "Development Status :: 5 - Production/Stable" + +version = {} +with open(os.path.join(package_root, "google/cloud/speech/gapic_version.py")) as fp: + exec(fp.read(), version) +version = version["__version__"] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + dependencies = [ - "google-api-core[grpc] >= 1.32.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*", + "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", "proto-plus >= 1.22.0, <2.0.0dev", "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", ] -extras = {"libcst": "libcst >= 0.2.5"} - - -# Setup boilerplate below this line. +url = "https://github.com/googleapis/python-speech" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -44,20 +48,16 @@ with io.open(readme_filename, encoding="utf-8") as readme_file: readme = readme_file.read() -# Only include packages under the 'google' namespace. Do not include tests, -# benchmarks, etc. packages = [ package for package in setuptools.PEP420PackageFinder.find() if package.startswith("google") ] -# Determine which namespaces are needed. namespaces = ["google"] if "google.cloud" in packages: namespaces.append("google.cloud") - setuptools.setup( name=name, version=version, @@ -66,7 +66,7 @@ author="Google LLC", author_email="googleapis-packages@google.com", license="Apache 2.0", - url="https://github.com/googleapis/python-speech", + url=url, classifiers=[ release_status, "Intended Audience :: Developers", @@ -82,14 +82,9 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, + python_requires=">=3.7", namespace_packages=namespaces, install_requires=dependencies, - extras_require=extras, - python_requires=">=3.7", - scripts=[ - "scripts/fixup_speech_v1_keywords.py", - "scripts/fixup_speech_v1p1beta1_keywords.py", - ], include_package_data=True, zip_safe=False, ) diff --git a/packages/google-cloud-python-speech/testing/constraints-3.10.txt b/packages/google-cloud-python-speech/testing/constraints-3.10.txt index e69de29bb2d1..ed7f9aed2559 100644 --- a/packages/google-cloud-python-speech/testing/constraints-3.10.txt +++ b/packages/google-cloud-python-speech/testing/constraints-3.10.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/packages/google-cloud-python-speech/testing/constraints-3.11.txt b/packages/google-cloud-python-speech/testing/constraints-3.11.txt index e69de29bb2d1..ed7f9aed2559 100644 --- a/packages/google-cloud-python-speech/testing/constraints-3.11.txt +++ b/packages/google-cloud-python-speech/testing/constraints-3.11.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/packages/google-cloud-python-speech/testing/constraints-3.7.txt b/packages/google-cloud-python-speech/testing/constraints-3.7.txt index 12b4d1428b2b..6c44adfea7ee 100644 --- a/packages/google-cloud-python-speech/testing/constraints-3.7.txt +++ b/packages/google-cloud-python-speech/testing/constraints-3.7.txt @@ -1,11 +1,9 @@ # This constraints file is used to check that lower bounds # are correct in setup.py -# List *all* library dependencies and extras in this file. +# List all library dependencies and extras in this file. # Pin the version to the lower bound. -# -# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", -# Then this file should have foo==1.14.0 -google-api-core==1.32.0 -libcst==0.2.5 +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.0 proto-plus==1.22.0 protobuf==3.19.5 diff --git a/packages/google-cloud-python-speech/testing/constraints-3.8.txt b/packages/google-cloud-python-speech/testing/constraints-3.8.txt index e69de29bb2d1..ed7f9aed2559 100644 --- a/packages/google-cloud-python-speech/testing/constraints-3.8.txt +++ b/packages/google-cloud-python-speech/testing/constraints-3.8.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/packages/google-cloud-python-speech/testing/constraints-3.9.txt b/packages/google-cloud-python-speech/testing/constraints-3.9.txt index e69de29bb2d1..ed7f9aed2559 100644 --- a/packages/google-cloud-python-speech/testing/constraints-3.9.txt +++ b/packages/google-cloud-python-speech/testing/constraints-3.9.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_adaptation.py b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_adaptation.py index 0d4310b8c5ea..2c662dec25e4 100644 --- a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_adaptation.py +++ b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_adaptation.py @@ -43,6 +43,7 @@ from google.cloud.speech_v1.services.adaptation import transports from google.cloud.speech_v1.types import cloud_speech_adaptation from google.cloud.speech_v1.types import resource +from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore import google.auth @@ -3666,6 +3667,8 @@ def test_adaptation_base_transport(): "list_custom_classes", "update_custom_class", "delete_custom_class", + "get_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): @@ -4194,6 +4197,296 @@ async def test_transport_close_async(): close.assert_called_once() +def test_get_operation(transport: str = "grpc"): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = AdaptationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = AdaptationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel", diff --git a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_speech.py b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_speech.py index 55447ae5d56a..2f5bdf0960a5 100644 --- a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_speech.py +++ b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1/test_speech.py @@ -664,7 +664,9 @@ def test_recognize(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.recognize), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_speech.RecognizeResponse() + call.return_value = cloud_speech.RecognizeResponse( + request_id=1077, + ) response = client.recognize(request) # Establish that the underlying gRPC stub method was called. @@ -674,6 +676,7 @@ def test_recognize(request_type, transport: str = "grpc"): # Establish that the response is the type that we expect. assert isinstance(response, cloud_speech.RecognizeResponse) + assert response.request_id == 1077 def test_recognize_empty_call(): @@ -709,7 +712,9 @@ async def test_recognize_async( with mock.patch.object(type(client.transport.recognize), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_speech.RecognizeResponse() + cloud_speech.RecognizeResponse( + request_id=1077, + ) ) response = await client.recognize(request) @@ -720,6 +725,7 @@ async def test_recognize_async( # Establish that the response is the type that we expect. assert isinstance(response, cloud_speech.RecognizeResponse) + assert response.request_id == 1077 @pytest.mark.asyncio @@ -1245,6 +1251,8 @@ def test_speech_base_transport(): "recognize", "long_running_recognize", "streaming_recognize", + "get_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): @@ -1812,6 +1820,296 @@ async def test_transport_close_async(): close.assert_called_once() +def test_get_operation(transport: str = "grpc"): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = SpeechClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = SpeechAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel", diff --git a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py index 49769576cacc..f52e27817a10 100644 --- a/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py +++ b/packages/google-cloud-python-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py @@ -664,7 +664,9 @@ def test_recognize(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.recognize), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_speech.RecognizeResponse() + call.return_value = cloud_speech.RecognizeResponse( + request_id=1077, + ) response = client.recognize(request) # Establish that the underlying gRPC stub method was called. @@ -674,6 +676,7 @@ def test_recognize(request_type, transport: str = "grpc"): # Establish that the response is the type that we expect. assert isinstance(response, cloud_speech.RecognizeResponse) + assert response.request_id == 1077 def test_recognize_empty_call(): @@ -709,7 +712,9 @@ async def test_recognize_async( with mock.patch.object(type(client.transport.recognize), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_speech.RecognizeResponse() + cloud_speech.RecognizeResponse( + request_id=1077, + ) ) response = await client.recognize(request) @@ -720,6 +725,7 @@ async def test_recognize_async( # Establish that the response is the type that we expect. assert isinstance(response, cloud_speech.RecognizeResponse) + assert response.request_id == 1077 @pytest.mark.asyncio