From f484e7fe036fe57a4f432bf30c6421a6541ea486 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 10 Mar 2022 17:43:03 -0500 Subject: [PATCH] feat: promote CustomVoiceParams to v1 (#266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: promote CustomVoiceParams to v1 PiperOrigin-RevId: 433829087 Source-Link: https://github.com/googleapis/googleapis/commit/9916192ab15e3507e41ba2c5165182fec06120d0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/86d3ab8eb66634eafe0608372030d94b21361dae Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODZkM2FiOGViNjY2MzRlYWZlMDYwODM3MjAzMGQ5NGIyMTM2MWRhZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- google/cloud/texttospeech/__init__.py | 2 + google/cloud/texttospeech_v1/__init__.py | 2 + .../services/text_to_speech/async_client.py | 2 + .../services/text_to_speech/client.py | 16 +++++++ .../cloud/texttospeech_v1/types/__init__.py | 2 + .../cloud/texttospeech_v1/types/cloud_tts.py | 31 ++++++++++++ .../texttospeech_v1/test_text_to_speech.py | 48 ++++++++++++++----- 7 files changed, 91 insertions(+), 12 deletions(-) diff --git a/google/cloud/texttospeech/__init__.py b/google/cloud/texttospeech/__init__.py index 0aac0870..f3c3fd33 100644 --- a/google/cloud/texttospeech/__init__.py +++ b/google/cloud/texttospeech/__init__.py @@ -22,6 +22,7 @@ ) from google.cloud.texttospeech_v1.types.cloud_tts import AudioConfig +from google.cloud.texttospeech_v1.types.cloud_tts import CustomVoiceParams from google.cloud.texttospeech_v1.types.cloud_tts import ListVoicesRequest from google.cloud.texttospeech_v1.types.cloud_tts import ListVoicesResponse from google.cloud.texttospeech_v1.types.cloud_tts import SynthesisInput @@ -36,6 +37,7 @@ "TextToSpeechClient", "TextToSpeechAsyncClient", "AudioConfig", + "CustomVoiceParams", "ListVoicesRequest", "ListVoicesResponse", "SynthesisInput", diff --git a/google/cloud/texttospeech_v1/__init__.py b/google/cloud/texttospeech_v1/__init__.py index e0804882..9a00f7af 100644 --- a/google/cloud/texttospeech_v1/__init__.py +++ b/google/cloud/texttospeech_v1/__init__.py @@ -18,6 +18,7 @@ from .services.text_to_speech import TextToSpeechAsyncClient from .types.cloud_tts import AudioConfig +from .types.cloud_tts import CustomVoiceParams from .types.cloud_tts import ListVoicesRequest from .types.cloud_tts import ListVoicesResponse from .types.cloud_tts import SynthesisInput @@ -32,6 +33,7 @@ "TextToSpeechAsyncClient", "AudioConfig", "AudioEncoding", + "CustomVoiceParams", "ListVoicesRequest", "ListVoicesResponse", "SsmlVoiceGender", diff --git a/google/cloud/texttospeech_v1/services/text_to_speech/async_client.py b/google/cloud/texttospeech_v1/services/text_to_speech/async_client.py index a2d87ac7..b8c0a062 100644 --- a/google/cloud/texttospeech_v1/services/text_to_speech/async_client.py +++ b/google/cloud/texttospeech_v1/services/text_to_speech/async_client.py @@ -45,6 +45,8 @@ class TextToSpeechAsyncClient: DEFAULT_ENDPOINT = TextToSpeechClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = TextToSpeechClient.DEFAULT_MTLS_ENDPOINT + model_path = staticmethod(TextToSpeechClient.model_path) + parse_model_path = staticmethod(TextToSpeechClient.parse_model_path) common_billing_account_path = staticmethod( TextToSpeechClient.common_billing_account_path ) diff --git a/google/cloud/texttospeech_v1/services/text_to_speech/client.py b/google/cloud/texttospeech_v1/services/text_to_speech/client.py index 6ee34d2c..6df2c8fa 100644 --- a/google/cloud/texttospeech_v1/services/text_to_speech/client.py +++ b/google/cloud/texttospeech_v1/services/text_to_speech/client.py @@ -156,6 +156,22 @@ def transport(self) -> TextToSpeechTransport: """ return self._transport + @staticmethod + def model_path(project: str, location: str, model: str,) -> str: + """Returns a fully-qualified model string.""" + return "projects/{project}/locations/{location}/models/{model}".format( + project=project, location=location, model=model, + ) + + @staticmethod + def parse_model_path(path: str) -> Dict[str, str]: + """Parses a model path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def common_billing_account_path(billing_account: str,) -> str: """Returns a fully-qualified billing_account string.""" diff --git a/google/cloud/texttospeech_v1/types/__init__.py b/google/cloud/texttospeech_v1/types/__init__.py index 2c552c36..15a07e1d 100644 --- a/google/cloud/texttospeech_v1/types/__init__.py +++ b/google/cloud/texttospeech_v1/types/__init__.py @@ -15,6 +15,7 @@ # from .cloud_tts import ( AudioConfig, + CustomVoiceParams, ListVoicesRequest, ListVoicesResponse, SynthesisInput, @@ -28,6 +29,7 @@ __all__ = ( "AudioConfig", + "CustomVoiceParams", "ListVoicesRequest", "ListVoicesResponse", "SynthesisInput", diff --git a/google/cloud/texttospeech_v1/types/cloud_tts.py b/google/cloud/texttospeech_v1/types/cloud_tts.py index 1e91e5c0..e7d84604 100644 --- a/google/cloud/texttospeech_v1/types/cloud_tts.py +++ b/google/cloud/texttospeech_v1/types/cloud_tts.py @@ -28,6 +28,7 @@ "SynthesisInput", "VoiceSelectionParams", "AudioConfig", + "CustomVoiceParams", "SynthesizeSpeechResponse", }, ) @@ -193,11 +194,16 @@ class VoiceSelectionParams(proto.Message): not requirement; if a voice of the appropriate gender is not available, the synthesizer should substitute a voice with a different gender rather than failing the request. + custom_voice (google.cloud.texttospeech_v1.types.CustomVoiceParams): + The configuration for a custom voice. If + [CustomVoiceParams.model] is set, the service will choose + the custom voice matching the specified configuration. """ language_code = proto.Field(proto.STRING, number=1,) name = proto.Field(proto.STRING, number=2,) ssml_gender = proto.Field(proto.ENUM, number=3, enum="SsmlVoiceGender",) + custom_voice = proto.Field(proto.MESSAGE, number=4, message="CustomVoiceParams",) class AudioConfig(proto.Message): @@ -255,6 +261,31 @@ class AudioConfig(proto.Message): effects_profile_id = proto.RepeatedField(proto.STRING, number=6,) +class CustomVoiceParams(proto.Message): + r"""Description of the custom voice to be synthesized. + + Attributes: + model (str): + Required. The name of the AutoML model that + synthesizes the custom voice. + reported_usage (google.cloud.texttospeech_v1.types.CustomVoiceParams.ReportedUsage): + Optional. The usage of the synthesized audio + to be reported. + """ + + class ReportedUsage(proto.Enum): + r"""The usage of the synthesized audio. You must report your + honest and correct usage of the service as it's regulated by + contract and will cause significant difference in billing. + """ + REPORTED_USAGE_UNSPECIFIED = 0 + REALTIME = 1 + OFFLINE = 2 + + model = proto.Field(proto.STRING, number=1,) + reported_usage = proto.Field(proto.ENUM, number=3, enum=ReportedUsage,) + + class SynthesizeSpeechResponse(proto.Message): r"""The message returned to the client by the ``SynthesizeSpeech`` method. diff --git a/tests/unit/gapic/texttospeech_v1/test_text_to_speech.py b/tests/unit/gapic/texttospeech_v1/test_text_to_speech.py index 67a41f55..cd7c1d0c 100644 --- a/tests/unit/gapic/texttospeech_v1/test_text_to_speech.py +++ b/tests/unit/gapic/texttospeech_v1/test_text_to_speech.py @@ -1350,8 +1350,32 @@ def test_text_to_speech_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel +def test_model_path(): + project = "squid" + location = "clam" + model = "whelk" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, location=location, model=model, + ) + actual = TextToSpeechClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "octopus", + "location": "oyster", + "model": "nudibranch", + } + path = TextToSpeechClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = TextToSpeechClient.parse_model_path(path) + assert expected == actual + + def test_common_billing_account_path(): - billing_account = "squid" + billing_account = "cuttlefish" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1361,7 +1385,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "clam", + "billing_account": "mussel", } path = TextToSpeechClient.common_billing_account_path(**expected) @@ -1371,7 +1395,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "whelk" + folder = "winkle" expected = "folders/{folder}".format(folder=folder,) actual = TextToSpeechClient.common_folder_path(folder) assert expected == actual @@ -1379,7 +1403,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "octopus", + "folder": "nautilus", } path = TextToSpeechClient.common_folder_path(**expected) @@ -1389,7 +1413,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "oyster" + organization = "scallop" expected = "organizations/{organization}".format(organization=organization,) actual = TextToSpeechClient.common_organization_path(organization) assert expected == actual @@ -1397,7 +1421,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "abalone", } path = TextToSpeechClient.common_organization_path(**expected) @@ -1407,7 +1431,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" + project = "squid" expected = "projects/{project}".format(project=project,) actual = TextToSpeechClient.common_project_path(project) assert expected == actual @@ -1415,7 +1439,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "clam", } path = TextToSpeechClient.common_project_path(**expected) @@ -1425,8 +1449,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "whelk" + location = "octopus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -1436,8 +1460,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "oyster", + "location": "nudibranch", } path = TextToSpeechClient.common_location_path(**expected)