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

Commit

Permalink
feat(v1beta1): add CustomVoiceParams (#215)
Browse files Browse the repository at this point in the history
* feat: update v1beta1 proto

PiperOrigin-RevId: 409139454

Source-Link: googleapis/googleapis@7c10623

Source-Link: googleapis/googleapis-gen@48051eb
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDgwNTFlYmFiZjk5MWFiY2RkY2IyNjg1Y2VmYzMzMWFlYTdmNTIwOCJ9

* 🦉 Updates from OwlBot

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>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people committed Nov 11, 2021
1 parent 8200ec0 commit 6a18d0f
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 30 deletions.
2 changes: 2 additions & 0 deletions google/cloud/texttospeech_v1beta1/__init__.py
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 @@ -33,6 +34,7 @@
"TextToSpeechAsyncClient",
"AudioConfig",
"AudioEncoding",
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"SsmlVoiceGender",
Expand Down
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 Expand Up @@ -180,12 +182,13 @@ async def list_voices(
language tag. If not specified, the API will return all
supported voices. If specified, the ListVoices call will
only return voices that can be used to synthesize this
language_code. E.g. when specifying "en-NZ", you will
get supported "en-NZ" voices; when specifying "no", you
will get supported "no-\*" (Norwegian) and "nb-\*"
(Norwegian Bokmal) voices; specifying "zh" will also get
supported "cmn-\*" voices; specifying "zh-hk" will also
get supported "yue-hk" voices.
language_code. E.g. when specifying ``"en-NZ"``, you
will get supported ``"en-NZ"`` voices; when specifying
``"no"``, you will get supported ``"no-\*"`` (Norwegian)
and ``"nb-\*"`` (Norwegian Bokmal) voices; specifying
``"zh"`` will also get supported ``"cmn-\*"`` voices;
specifying ``"zh-hk"`` will also get supported
``"yue-hk"`` voices.
This corresponds to the ``language_code`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down
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 Expand Up @@ -360,12 +376,13 @@ def list_voices(
language tag. If not specified, the API will return all
supported voices. If specified, the ListVoices call will
only return voices that can be used to synthesize this
language_code. E.g. when specifying "en-NZ", you will
get supported "en-NZ" voices; when specifying "no", you
will get supported "no-\*" (Norwegian) and "nb-\*"
(Norwegian Bokmal) voices; specifying "zh" will also get
supported "cmn-\*" voices; specifying "zh-hk" will also
get supported "yue-hk" voices.
language_code. E.g. when specifying ``"en-NZ"``, you
will get supported ``"en-NZ"`` voices; when specifying
``"no"``, you will get supported ``"no-\*"`` (Norwegian)
and ``"nb-\*"`` (Norwegian Bokmal) voices; specifying
``"zh"`` will also get supported ``"cmn-\*"`` voices;
specifying ``"zh-hk"`` will also get supported
``"yue-hk"`` voices.
This corresponds to the ``language_code`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/texttospeech_v1beta1/types/__init__.py
Expand Up @@ -15,6 +15,7 @@
#
from .cloud_tts import (
AudioConfig,
CustomVoiceParams,
ListVoicesRequest,
ListVoicesResponse,
SynthesisInput,
Expand All @@ -29,6 +30,7 @@

__all__ = (
"AudioConfig",
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"SynthesisInput",
Expand Down
43 changes: 37 additions & 6 deletions google/cloud/texttospeech_v1beta1/types/cloud_tts.py
Expand Up @@ -28,6 +28,7 @@
"SynthesisInput",
"VoiceSelectionParams",
"AudioConfig",
"CustomVoiceParams",
"SynthesizeSpeechResponse",
"Timepoint",
},
Expand Down Expand Up @@ -68,12 +69,12 @@ class ListVoicesRequest(proto.Message):
language tag. If not specified, the API will return all
supported voices. If specified, the ListVoices call will
only return voices that can be used to synthesize this
language_code. E.g. when specifying "en-NZ", you will get
supported "en-NZ" voices; when specifying "no", you will get
supported "no-\*" (Norwegian) and "nb-\*" (Norwegian Bokmal)
voices; specifying "zh" will also get supported "cmn-\*"
voices; specifying "zh-hk" will also get supported "yue-hk"
voices.
language_code. E.g. when specifying ``"en-NZ"``, you will
get supported ``"en-NZ"`` voices; when specifying ``"no"``,
you will get supported ``"no-\*"`` (Norwegian) and
``"nb-\*"`` (Norwegian Bokmal) voices; specifying ``"zh"``
will also get supported ``"cmn-\*"`` voices; specifying
``"zh-hk"`` will also get supported ``"yue-hk"`` voices.
"""

language_code = proto.Field(proto.STRING, number=1,)
Expand Down Expand Up @@ -210,11 +211,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_v1beta1.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 @@ -272,6 +278,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_v1beta1.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_v1beta1/test_text_to_speech.py
Expand Up @@ -1193,8 +1193,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 @@ -1204,7 +1228,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 @@ -1214,15 +1238,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 @@ -1232,15 +1256,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 @@ -1250,15 +1274,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 @@ -1268,8 +1292,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 @@ -1279,8 +1303,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 6a18d0f

Please sign in to comment.