@@ -49,7 +49,7 @@ class TextToSpeechClientMeta(type):
49
49
_transport_registry ["grpc" ] = TextToSpeechGrpcTransport
50
50
_transport_registry ["grpc_asyncio" ] = TextToSpeechGrpcAsyncIOTransport
51
51
52
- def get_transport_class (cls , label : str = None ) -> Type [TextToSpeechTransport ]:
52
+ def get_transport_class (cls , label : str = None , ) -> Type [TextToSpeechTransport ]:
53
53
"""Return an appropriate transport class.
54
54
55
55
Args:
@@ -192,19 +192,27 @@ def __init__(
192
192
# instance provides an extensibility point for unusual situations.
193
193
if isinstance (transport , TextToSpeechTransport ):
194
194
# transport is a TextToSpeechTransport instance.
195
- if credentials :
195
+ if credentials or client_options . credentials_file :
196
196
raise ValueError (
197
197
"When providing a transport instance, "
198
198
"provide its credentials directly."
199
199
)
200
+ if client_options .scopes :
201
+ raise ValueError (
202
+ "When providing a transport instance, "
203
+ "provide its scopes directly."
204
+ )
200
205
self ._transport = transport
201
206
else :
202
207
Transport = type (self ).get_transport_class (transport )
203
208
self ._transport = Transport (
204
209
credentials = credentials ,
210
+ credentials_file = client_options .credentials_file ,
205
211
host = client_options .api_endpoint ,
212
+ scopes = client_options .scopes ,
206
213
api_mtls_endpoint = client_options .api_endpoint ,
207
214
client_cert_source = client_options .client_cert_source ,
215
+ quota_project_id = client_options .quota_project_id ,
208
216
)
209
217
210
218
def list_voices (
@@ -229,9 +237,9 @@ def list_voices(
229
237
only return voices that can be used to synthesize this
230
238
language_code. E.g. when specifying "en-NZ", you will
231
239
get supported "en-\*" voices; when specifying "no", you
232
- will get supported "no-\*" (Norwegian) and "nb-*"
240
+ will get supported "no-\*" (Norwegian) and "nb-\ *"
233
241
(Norwegian Bokmal) voices; specifying "zh" will also get
234
- supported "cmn-*" voices; specifying "zh-hk" will also
242
+ supported "cmn-\ *" voices; specifying "zh-hk" will also
235
243
get supported "yue-\*" voices.
236
244
This corresponds to the ``language_code`` field
237
245
on the ``request`` instance; if ``request`` is provided, this
@@ -252,28 +260,32 @@ def list_voices(
252
260
# Create or coerce a protobuf request object.
253
261
# Sanity check: If we got a request object, we should *not* have
254
262
# gotten any keyword arguments that map to the request.
255
- if request is not None and any ([language_code ]):
263
+ has_flattened_params = any ([language_code ])
264
+ if request is not None and has_flattened_params :
256
265
raise ValueError (
257
266
"If the `request` argument is set, then none of "
258
267
"the individual field arguments should be set."
259
268
)
260
269
261
- request = cloud_tts .ListVoicesRequest (request )
270
+ # Minor optimization to avoid making a copy if the user passes
271
+ # in a cloud_tts.ListVoicesRequest.
272
+ # There's no risk of modifying the input as we've already verified
273
+ # there are no flattened fields.
274
+ if not isinstance (request , cloud_tts .ListVoicesRequest ):
275
+ request = cloud_tts .ListVoicesRequest (request )
262
276
263
- # If we have keyword arguments corresponding to fields on the
264
- # request, apply these.
277
+ # If we have keyword arguments corresponding to fields on the
278
+ # request, apply these.
265
279
266
- if language_code is not None :
267
- request .language_code = language_code
280
+ if language_code is not None :
281
+ request .language_code = language_code
268
282
269
283
# Wrap the RPC method; this adds retry and timeout information,
270
284
# and friendly error handling.
271
- rpc = gapic_v1 .method .wrap_method (
272
- self ._transport .list_voices , default_timeout = None , client_info = _client_info
273
- )
285
+ rpc = self ._transport ._wrapped_methods [self ._transport .list_voices ]
274
286
275
287
# Send the request.
276
- response = rpc (request , retry = retry , timeout = timeout , metadata = metadata )
288
+ response = rpc (request , retry = retry , timeout = timeout , metadata = metadata , )
277
289
278
290
# Done; return the response.
279
291
return response
@@ -330,34 +342,36 @@ def synthesize_speech(
330
342
# Create or coerce a protobuf request object.
331
343
# Sanity check: If we got a request object, we should *not* have
332
344
# gotten any keyword arguments that map to the request.
333
- if request is not None and any ([input , voice , audio_config ]):
345
+ has_flattened_params = any ([input , voice , audio_config ])
346
+ if request is not None and has_flattened_params :
334
347
raise ValueError (
335
348
"If the `request` argument is set, then none of "
336
349
"the individual field arguments should be set."
337
350
)
338
351
339
- request = cloud_tts .SynthesizeSpeechRequest (request )
352
+ # Minor optimization to avoid making a copy if the user passes
353
+ # in a cloud_tts.SynthesizeSpeechRequest.
354
+ # There's no risk of modifying the input as we've already verified
355
+ # there are no flattened fields.
356
+ if not isinstance (request , cloud_tts .SynthesizeSpeechRequest ):
357
+ request = cloud_tts .SynthesizeSpeechRequest (request )
340
358
341
- # If we have keyword arguments corresponding to fields on the
342
- # request, apply these.
359
+ # If we have keyword arguments corresponding to fields on the
360
+ # request, apply these.
343
361
344
- if input is not None :
345
- request .input = input
346
- if voice is not None :
347
- request .voice = voice
348
- if audio_config is not None :
349
- request .audio_config = audio_config
362
+ if input is not None :
363
+ request .input = input
364
+ if voice is not None :
365
+ request .voice = voice
366
+ if audio_config is not None :
367
+ request .audio_config = audio_config
350
368
351
369
# Wrap the RPC method; this adds retry and timeout information,
352
370
# and friendly error handling.
353
- rpc = gapic_v1 .method .wrap_method (
354
- self ._transport .synthesize_speech ,
355
- default_timeout = None ,
356
- client_info = _client_info ,
357
- )
371
+ rpc = self ._transport ._wrapped_methods [self ._transport .synthesize_speech ]
358
372
359
373
# Send the request.
360
- response = rpc (request , retry = retry , timeout = timeout , metadata = metadata )
374
+ response = rpc (request , retry = retry , timeout = timeout , metadata = metadata , )
361
375
362
376
# Done; return the response.
363
377
return response
@@ -366,8 +380,8 @@ def synthesize_speech(
366
380
try :
367
381
_client_info = gapic_v1 .client_info .ClientInfo (
368
382
gapic_version = pkg_resources .get_distribution (
369
- "google-cloud-texttospeech"
370
- ).version
383
+ "google-cloud-texttospeech" ,
384
+ ).version ,
371
385
)
372
386
except pkg_resources .DistributionNotFound :
373
387
_client_info = gapic_v1 .client_info .ClientInfo ()
0 commit comments