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

Commit 6a18d0f

Browse files
feat(v1beta1): add CustomVoiceParams (#215)
* feat: update v1beta1 proto PiperOrigin-RevId: 409139454 Source-Link: googleapis/googleapis@7c10623 Source-Link: https://github.com/googleapis/googleapis-gen/commit/48051ebabf991abcddcb2685cefc331aea7f5208 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>
1 parent 8200ec0 commit 6a18d0f

File tree

6 files changed

+109
-30
lines changed

6 files changed

+109
-30
lines changed

google/cloud/texttospeech_v1beta1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .services.text_to_speech import TextToSpeechAsyncClient
1919

2020
from .types.cloud_tts import AudioConfig
21+
from .types.cloud_tts import CustomVoiceParams
2122
from .types.cloud_tts import ListVoicesRequest
2223
from .types.cloud_tts import ListVoicesResponse
2324
from .types.cloud_tts import SynthesisInput
@@ -33,6 +34,7 @@
3334
"TextToSpeechAsyncClient",
3435
"AudioConfig",
3536
"AudioEncoding",
37+
"CustomVoiceParams",
3638
"ListVoicesRequest",
3739
"ListVoicesResponse",
3840
"SsmlVoiceGender",

google/cloud/texttospeech_v1beta1/services/text_to_speech/async_client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class TextToSpeechAsyncClient:
4545
DEFAULT_ENDPOINT = TextToSpeechClient.DEFAULT_ENDPOINT
4646
DEFAULT_MTLS_ENDPOINT = TextToSpeechClient.DEFAULT_MTLS_ENDPOINT
4747

48+
model_path = staticmethod(TextToSpeechClient.model_path)
49+
parse_model_path = staticmethod(TextToSpeechClient.parse_model_path)
4850
common_billing_account_path = staticmethod(
4951
TextToSpeechClient.common_billing_account_path
5052
)
@@ -180,12 +182,13 @@ async def list_voices(
180182
language tag. If not specified, the API will return all
181183
supported voices. If specified, the ListVoices call will
182184
only return voices that can be used to synthesize this
183-
language_code. E.g. when specifying "en-NZ", you will
184-
get supported "en-NZ" voices; when specifying "no", you
185-
will get supported "no-\*" (Norwegian) and "nb-\*"
186-
(Norwegian Bokmal) voices; specifying "zh" will also get
187-
supported "cmn-\*" voices; specifying "zh-hk" will also
188-
get supported "yue-hk" voices.
185+
language_code. E.g. when specifying ``"en-NZ"``, you
186+
will get supported ``"en-NZ"`` voices; when specifying
187+
``"no"``, you will get supported ``"no-\*"`` (Norwegian)
188+
and ``"nb-\*"`` (Norwegian Bokmal) voices; specifying
189+
``"zh"`` will also get supported ``"cmn-\*"`` voices;
190+
specifying ``"zh-hk"`` will also get supported
191+
``"yue-hk"`` voices.
189192
190193
This corresponds to the ``language_code`` field
191194
on the ``request`` instance; if ``request`` is provided, this

google/cloud/texttospeech_v1beta1/services/text_to_speech/client.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ def transport(self) -> TextToSpeechTransport:
156156
"""
157157
return self._transport
158158

159+
@staticmethod
160+
def model_path(project: str, location: str, model: str,) -> str:
161+
"""Returns a fully-qualified model string."""
162+
return "projects/{project}/locations/{location}/models/{model}".format(
163+
project=project, location=location, model=model,
164+
)
165+
166+
@staticmethod
167+
def parse_model_path(path: str) -> Dict[str, str]:
168+
"""Parses a model path into its component segments."""
169+
m = re.match(
170+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/models/(?P<model>.+?)$",
171+
path,
172+
)
173+
return m.groupdict() if m else {}
174+
159175
@staticmethod
160176
def common_billing_account_path(billing_account: str,) -> str:
161177
"""Returns a fully-qualified billing_account string."""
@@ -360,12 +376,13 @@ def list_voices(
360376
language tag. If not specified, the API will return all
361377
supported voices. If specified, the ListVoices call will
362378
only return voices that can be used to synthesize this
363-
language_code. E.g. when specifying "en-NZ", you will
364-
get supported "en-NZ" voices; when specifying "no", you
365-
will get supported "no-\*" (Norwegian) and "nb-\*"
366-
(Norwegian Bokmal) voices; specifying "zh" will also get
367-
supported "cmn-\*" voices; specifying "zh-hk" will also
368-
get supported "yue-hk" voices.
379+
language_code. E.g. when specifying ``"en-NZ"``, you
380+
will get supported ``"en-NZ"`` voices; when specifying
381+
``"no"``, you will get supported ``"no-\*"`` (Norwegian)
382+
and ``"nb-\*"`` (Norwegian Bokmal) voices; specifying
383+
``"zh"`` will also get supported ``"cmn-\*"`` voices;
384+
specifying ``"zh-hk"`` will also get supported
385+
``"yue-hk"`` voices.
369386
370387
This corresponds to the ``language_code`` field
371388
on the ``request`` instance; if ``request`` is provided, this

google/cloud/texttospeech_v1beta1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
from .cloud_tts import (
1717
AudioConfig,
18+
CustomVoiceParams,
1819
ListVoicesRequest,
1920
ListVoicesResponse,
2021
SynthesisInput,
@@ -29,6 +30,7 @@
2930

3031
__all__ = (
3132
"AudioConfig",
33+
"CustomVoiceParams",
3234
"ListVoicesRequest",
3335
"ListVoicesResponse",
3436
"SynthesisInput",

google/cloud/texttospeech_v1beta1/types/cloud_tts.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"SynthesisInput",
2929
"VoiceSelectionParams",
3030
"AudioConfig",
31+
"CustomVoiceParams",
3132
"SynthesizeSpeechResponse",
3233
"Timepoint",
3334
},
@@ -68,12 +69,12 @@ class ListVoicesRequest(proto.Message):
6869
language tag. If not specified, the API will return all
6970
supported voices. If specified, the ListVoices call will
7071
only return voices that can be used to synthesize this
71-
language_code. E.g. when specifying "en-NZ", you will get
72-
supported "en-NZ" voices; when specifying "no", you will get
73-
supported "no-\*" (Norwegian) and "nb-\*" (Norwegian Bokmal)
74-
voices; specifying "zh" will also get supported "cmn-\*"
75-
voices; specifying "zh-hk" will also get supported "yue-hk"
76-
voices.
72+
language_code. E.g. when specifying ``"en-NZ"``, you will
73+
get supported ``"en-NZ"`` voices; when specifying ``"no"``,
74+
you will get supported ``"no-\*"`` (Norwegian) and
75+
``"nb-\*"`` (Norwegian Bokmal) voices; specifying ``"zh"``
76+
will also get supported ``"cmn-\*"`` voices; specifying
77+
``"zh-hk"`` will also get supported ``"yue-hk"`` voices.
7778
"""
7879

7980
language_code = proto.Field(proto.STRING, number=1,)
@@ -210,11 +211,16 @@ class VoiceSelectionParams(proto.Message):
210211
not requirement; if a voice of the appropriate gender is not
211212
available, the synthesizer should substitute a voice with a
212213
different gender rather than failing the request.
214+
custom_voice (google.cloud.texttospeech_v1beta1.types.CustomVoiceParams):
215+
The configuration for a custom voice. If
216+
[CustomVoiceParams.model] is set, the service will choose
217+
the custom voice matching the specified configuration.
213218
"""
214219

215220
language_code = proto.Field(proto.STRING, number=1,)
216221
name = proto.Field(proto.STRING, number=2,)
217222
ssml_gender = proto.Field(proto.ENUM, number=3, enum="SsmlVoiceGender",)
223+
custom_voice = proto.Field(proto.MESSAGE, number=4, message="CustomVoiceParams",)
218224

219225

220226
class AudioConfig(proto.Message):
@@ -272,6 +278,31 @@ class AudioConfig(proto.Message):
272278
effects_profile_id = proto.RepeatedField(proto.STRING, number=6,)
273279

274280

281+
class CustomVoiceParams(proto.Message):
282+
r"""Description of the custom voice to be synthesized.
283+
284+
Attributes:
285+
model (str):
286+
Required. The name of the AutoML model that
287+
synthesizes the custom voice.
288+
reported_usage (google.cloud.texttospeech_v1beta1.types.CustomVoiceParams.ReportedUsage):
289+
Optional. The usage of the synthesized audio
290+
to be reported.
291+
"""
292+
293+
class ReportedUsage(proto.Enum):
294+
r"""The usage of the synthesized audio. You must report your
295+
honest and correct usage of the service as it's regulated by
296+
contract and will cause significant difference in billing.
297+
"""
298+
REPORTED_USAGE_UNSPECIFIED = 0
299+
REALTIME = 1
300+
OFFLINE = 2
301+
302+
model = proto.Field(proto.STRING, number=1,)
303+
reported_usage = proto.Field(proto.ENUM, number=3, enum=ReportedUsage,)
304+
305+
275306
class SynthesizeSpeechResponse(proto.Message):
276307
r"""The message returned to the client by the ``SynthesizeSpeech``
277308
method.

tests/unit/gapic/texttospeech_v1beta1/test_text_to_speech.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,32 @@ def test_text_to_speech_transport_channel_mtls_with_adc(transport_class):
11931193
assert transport.grpc_channel == mock_grpc_channel
11941194

11951195

1196+
def test_model_path():
1197+
project = "squid"
1198+
location = "clam"
1199+
model = "whelk"
1200+
expected = "projects/{project}/locations/{location}/models/{model}".format(
1201+
project=project, location=location, model=model,
1202+
)
1203+
actual = TextToSpeechClient.model_path(project, location, model)
1204+
assert expected == actual
1205+
1206+
1207+
def test_parse_model_path():
1208+
expected = {
1209+
"project": "octopus",
1210+
"location": "oyster",
1211+
"model": "nudibranch",
1212+
}
1213+
path = TextToSpeechClient.model_path(**expected)
1214+
1215+
# Check that the path construction is reversible.
1216+
actual = TextToSpeechClient.parse_model_path(path)
1217+
assert expected == actual
1218+
1219+
11961220
def test_common_billing_account_path():
1197-
billing_account = "squid"
1221+
billing_account = "cuttlefish"
11981222
expected = "billingAccounts/{billing_account}".format(
11991223
billing_account=billing_account,
12001224
)
@@ -1204,7 +1228,7 @@ def test_common_billing_account_path():
12041228

12051229
def test_parse_common_billing_account_path():
12061230
expected = {
1207-
"billing_account": "clam",
1231+
"billing_account": "mussel",
12081232
}
12091233
path = TextToSpeechClient.common_billing_account_path(**expected)
12101234

@@ -1214,15 +1238,15 @@ def test_parse_common_billing_account_path():
12141238

12151239

12161240
def test_common_folder_path():
1217-
folder = "whelk"
1241+
folder = "winkle"
12181242
expected = "folders/{folder}".format(folder=folder,)
12191243
actual = TextToSpeechClient.common_folder_path(folder)
12201244
assert expected == actual
12211245

12221246

12231247
def test_parse_common_folder_path():
12241248
expected = {
1225-
"folder": "octopus",
1249+
"folder": "nautilus",
12261250
}
12271251
path = TextToSpeechClient.common_folder_path(**expected)
12281252

@@ -1232,15 +1256,15 @@ def test_parse_common_folder_path():
12321256

12331257

12341258
def test_common_organization_path():
1235-
organization = "oyster"
1259+
organization = "scallop"
12361260
expected = "organizations/{organization}".format(organization=organization,)
12371261
actual = TextToSpeechClient.common_organization_path(organization)
12381262
assert expected == actual
12391263

12401264

12411265
def test_parse_common_organization_path():
12421266
expected = {
1243-
"organization": "nudibranch",
1267+
"organization": "abalone",
12441268
}
12451269
path = TextToSpeechClient.common_organization_path(**expected)
12461270

@@ -1250,15 +1274,15 @@ def test_parse_common_organization_path():
12501274

12511275

12521276
def test_common_project_path():
1253-
project = "cuttlefish"
1277+
project = "squid"
12541278
expected = "projects/{project}".format(project=project,)
12551279
actual = TextToSpeechClient.common_project_path(project)
12561280
assert expected == actual
12571281

12581282

12591283
def test_parse_common_project_path():
12601284
expected = {
1261-
"project": "mussel",
1285+
"project": "clam",
12621286
}
12631287
path = TextToSpeechClient.common_project_path(**expected)
12641288

@@ -1268,8 +1292,8 @@ def test_parse_common_project_path():
12681292

12691293

12701294
def test_common_location_path():
1271-
project = "winkle"
1272-
location = "nautilus"
1295+
project = "whelk"
1296+
location = "octopus"
12731297
expected = "projects/{project}/locations/{location}".format(
12741298
project=project, location=location,
12751299
)
@@ -1279,8 +1303,8 @@ def test_common_location_path():
12791303

12801304
def test_parse_common_location_path():
12811305
expected = {
1282-
"project": "scallop",
1283-
"location": "abalone",
1306+
"project": "oyster",
1307+
"location": "nudibranch",
12841308
}
12851309
path = TextToSpeechClient.common_location_path(**expected)
12861310

0 commit comments

Comments
 (0)