Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
feat: promote CustomVoiceParams to v1 (#266)
Browse files Browse the repository at this point in the history
* feat: promote CustomVoiceParams to v1

PiperOrigin-RevId: 433829087

Source-Link: googleapis/googleapis@9916192

Source-Link: googleapis/googleapis-gen@86d3ab8
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 <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Mar 10, 2022
1 parent 0a2f294 commit f484e7f
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 12 deletions.
2 changes: 2 additions & 0 deletions google/cloud/texttospeech/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@
"TextToSpeechClient",
"TextToSpeechAsyncClient",
"AudioConfig",
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"SynthesisInput",
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/texttospeech_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,7 @@
"TextToSpeechAsyncClient",
"AudioConfig",
"AudioEncoding",
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"SsmlVoiceGender",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
16 changes: 16 additions & 0 deletions google/cloud/texttospeech_v1/services/text_to_speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<project>.+?)/locations/(?P<location>.+?)/models/(?P<model>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Returns a fully-qualified billing_account string."""
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/texttospeech_v1/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
from .cloud_tts import (
AudioConfig,
CustomVoiceParams,
ListVoicesRequest,
ListVoicesResponse,
SynthesisInput,
Expand All @@ -28,6 +29,7 @@

__all__ = (
"AudioConfig",
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"SynthesisInput",
Expand Down
31 changes: 31 additions & 0 deletions google/cloud/texttospeech_v1/types/cloud_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"SynthesisInput",
"VoiceSelectionParams",
"AudioConfig",
"CustomVoiceParams",
"SynthesizeSpeechResponse",
},
)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
48 changes: 36 additions & 12 deletions tests/unit/gapic/texttospeech_v1/test_text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)

Expand All @@ -1371,15 +1395,15 @@ 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


def test_parse_common_folder_path():
expected = {
"folder": "octopus",
"folder": "nautilus",
}
path = TextToSpeechClient.common_folder_path(**expected)

Expand All @@ -1389,15 +1413,15 @@ 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


def test_parse_common_organization_path():
expected = {
"organization": "nudibranch",
"organization": "abalone",
}
path = TextToSpeechClient.common_organization_path(**expected)

Expand All @@ -1407,15 +1431,15 @@ 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


def test_parse_common_project_path():
expected = {
"project": "mussel",
"project": "clam",
}
path = TextToSpeechClient.common_project_path(**expected)

Expand All @@ -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,
)
Expand All @@ -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)

Expand Down

0 comments on commit f484e7f

Please sign in to comment.