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

Commit f484e7f

Browse files
feat: promote CustomVoiceParams to v1 (#266)
* feat: promote CustomVoiceParams to v1 PiperOrigin-RevId: 433829087 Source-Link: googleapis/googleapis@9916192 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 <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 0a2f294 commit f484e7f

File tree

7 files changed

+91
-12
lines changed

7 files changed

+91
-12
lines changed

google/cloud/texttospeech/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323

2424
from google.cloud.texttospeech_v1.types.cloud_tts import AudioConfig
25+
from google.cloud.texttospeech_v1.types.cloud_tts import CustomVoiceParams
2526
from google.cloud.texttospeech_v1.types.cloud_tts import ListVoicesRequest
2627
from google.cloud.texttospeech_v1.types.cloud_tts import ListVoicesResponse
2728
from google.cloud.texttospeech_v1.types.cloud_tts import SynthesisInput
@@ -36,6 +37,7 @@
3637
"TextToSpeechClient",
3738
"TextToSpeechAsyncClient",
3839
"AudioConfig",
40+
"CustomVoiceParams",
3941
"ListVoicesRequest",
4042
"ListVoicesResponse",
4143
"SynthesisInput",

google/cloud/texttospeech_v1/__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
@@ -32,6 +33,7 @@
3233
"TextToSpeechAsyncClient",
3334
"AudioConfig",
3435
"AudioEncoding",
36+
"CustomVoiceParams",
3537
"ListVoicesRequest",
3638
"ListVoicesResponse",
3739
"SsmlVoiceGender",

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

Lines changed: 2 additions & 0 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
)

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

Lines changed: 16 additions & 0 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."""

google/cloud/texttospeech_v1/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,
@@ -28,6 +29,7 @@
2829

2930
__all__ = (
3031
"AudioConfig",
32+
"CustomVoiceParams",
3133
"ListVoicesRequest",
3234
"ListVoicesResponse",
3335
"SynthesisInput",

google/cloud/texttospeech_v1/types/cloud_tts.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"SynthesisInput",
2929
"VoiceSelectionParams",
3030
"AudioConfig",
31+
"CustomVoiceParams",
3132
"SynthesizeSpeechResponse",
3233
},
3334
)
@@ -193,11 +194,16 @@ class VoiceSelectionParams(proto.Message):
193194
not requirement; if a voice of the appropriate gender is not
194195
available, the synthesizer should substitute a voice with a
195196
different gender rather than failing the request.
197+
custom_voice (google.cloud.texttospeech_v1.types.CustomVoiceParams):
198+
The configuration for a custom voice. If
199+
[CustomVoiceParams.model] is set, the service will choose
200+
the custom voice matching the specified configuration.
196201
"""
197202

198203
language_code = proto.Field(proto.STRING, number=1,)
199204
name = proto.Field(proto.STRING, number=2,)
200205
ssml_gender = proto.Field(proto.ENUM, number=3, enum="SsmlVoiceGender",)
206+
custom_voice = proto.Field(proto.MESSAGE, number=4, message="CustomVoiceParams",)
201207

202208

203209
class AudioConfig(proto.Message):
@@ -255,6 +261,31 @@ class AudioConfig(proto.Message):
255261
effects_profile_id = proto.RepeatedField(proto.STRING, number=6,)
256262

257263

264+
class CustomVoiceParams(proto.Message):
265+
r"""Description of the custom voice to be synthesized.
266+
267+
Attributes:
268+
model (str):
269+
Required. The name of the AutoML model that
270+
synthesizes the custom voice.
271+
reported_usage (google.cloud.texttospeech_v1.types.CustomVoiceParams.ReportedUsage):
272+
Optional. The usage of the synthesized audio
273+
to be reported.
274+
"""
275+
276+
class ReportedUsage(proto.Enum):
277+
r"""The usage of the synthesized audio. You must report your
278+
honest and correct usage of the service as it's regulated by
279+
contract and will cause significant difference in billing.
280+
"""
281+
REPORTED_USAGE_UNSPECIFIED = 0
282+
REALTIME = 1
283+
OFFLINE = 2
284+
285+
model = proto.Field(proto.STRING, number=1,)
286+
reported_usage = proto.Field(proto.ENUM, number=3, enum=ReportedUsage,)
287+
288+
258289
class SynthesizeSpeechResponse(proto.Message):
259290
r"""The message returned to the client by the ``SynthesizeSpeech``
260291
method.

tests/unit/gapic/texttospeech_v1/test_text_to_speech.py

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

13521352

1353+
def test_model_path():
1354+
project = "squid"
1355+
location = "clam"
1356+
model = "whelk"
1357+
expected = "projects/{project}/locations/{location}/models/{model}".format(
1358+
project=project, location=location, model=model,
1359+
)
1360+
actual = TextToSpeechClient.model_path(project, location, model)
1361+
assert expected == actual
1362+
1363+
1364+
def test_parse_model_path():
1365+
expected = {
1366+
"project": "octopus",
1367+
"location": "oyster",
1368+
"model": "nudibranch",
1369+
}
1370+
path = TextToSpeechClient.model_path(**expected)
1371+
1372+
# Check that the path construction is reversible.
1373+
actual = TextToSpeechClient.parse_model_path(path)
1374+
assert expected == actual
1375+
1376+
13531377
def test_common_billing_account_path():
1354-
billing_account = "squid"
1378+
billing_account = "cuttlefish"
13551379
expected = "billingAccounts/{billing_account}".format(
13561380
billing_account=billing_account,
13571381
)
@@ -1361,7 +1385,7 @@ def test_common_billing_account_path():
13611385

13621386
def test_parse_common_billing_account_path():
13631387
expected = {
1364-
"billing_account": "clam",
1388+
"billing_account": "mussel",
13651389
}
13661390
path = TextToSpeechClient.common_billing_account_path(**expected)
13671391

@@ -1371,15 +1395,15 @@ def test_parse_common_billing_account_path():
13711395

13721396

13731397
def test_common_folder_path():
1374-
folder = "whelk"
1398+
folder = "winkle"
13751399
expected = "folders/{folder}".format(folder=folder,)
13761400
actual = TextToSpeechClient.common_folder_path(folder)
13771401
assert expected == actual
13781402

13791403

13801404
def test_parse_common_folder_path():
13811405
expected = {
1382-
"folder": "octopus",
1406+
"folder": "nautilus",
13831407
}
13841408
path = TextToSpeechClient.common_folder_path(**expected)
13851409

@@ -1389,15 +1413,15 @@ def test_parse_common_folder_path():
13891413

13901414

13911415
def test_common_organization_path():
1392-
organization = "oyster"
1416+
organization = "scallop"
13931417
expected = "organizations/{organization}".format(organization=organization,)
13941418
actual = TextToSpeechClient.common_organization_path(organization)
13951419
assert expected == actual
13961420

13971421

13981422
def test_parse_common_organization_path():
13991423
expected = {
1400-
"organization": "nudibranch",
1424+
"organization": "abalone",
14011425
}
14021426
path = TextToSpeechClient.common_organization_path(**expected)
14031427

@@ -1407,15 +1431,15 @@ def test_parse_common_organization_path():
14071431

14081432

14091433
def test_common_project_path():
1410-
project = "cuttlefish"
1434+
project = "squid"
14111435
expected = "projects/{project}".format(project=project,)
14121436
actual = TextToSpeechClient.common_project_path(project)
14131437
assert expected == actual
14141438

14151439

14161440
def test_parse_common_project_path():
14171441
expected = {
1418-
"project": "mussel",
1442+
"project": "clam",
14191443
}
14201444
path = TextToSpeechClient.common_project_path(**expected)
14211445

@@ -1425,8 +1449,8 @@ def test_parse_common_project_path():
14251449

14261450

14271451
def test_common_location_path():
1428-
project = "winkle"
1429-
location = "nautilus"
1452+
project = "whelk"
1453+
location = "octopus"
14301454
expected = "projects/{project}/locations/{location}".format(
14311455
project=project, location=location,
14321456
)
@@ -1436,8 +1460,8 @@ def test_common_location_path():
14361460

14371461
def test_parse_common_location_path():
14381462
expected = {
1439-
"project": "scallop",
1440-
"location": "abalone",
1463+
"project": "oyster",
1464+
"location": "nudibranch",
14411465
}
14421466
path = TextToSpeechClient.common_location_path(**expected)
14431467

0 commit comments

Comments
 (0)