@@ -49,7 +49,7 @@ class TextToSpeechClientMeta(type):
4949 _transport_registry ["grpc" ] = TextToSpeechGrpcTransport
5050 _transport_registry ["grpc_asyncio" ] = TextToSpeechGrpcAsyncIOTransport
5151
52- def get_transport_class (cls , label : str = None ) -> Type [TextToSpeechTransport ]:
52+ def get_transport_class (cls , label : str = None , ) -> Type [TextToSpeechTransport ]:
5353 """Return an appropriate transport class.
5454
5555 Args:
@@ -192,19 +192,27 @@ def __init__(
192192 # instance provides an extensibility point for unusual situations.
193193 if isinstance (transport , TextToSpeechTransport ):
194194 # transport is a TextToSpeechTransport instance.
195- if credentials :
195+ if credentials or client_options . credentials_file :
196196 raise ValueError (
197197 "When providing a transport instance, "
198198 "provide its credentials directly."
199199 )
200+ if client_options .scopes :
201+ raise ValueError (
202+ "When providing a transport instance, "
203+ "provide its scopes directly."
204+ )
200205 self ._transport = transport
201206 else :
202207 Transport = type (self ).get_transport_class (transport )
203208 self ._transport = Transport (
204209 credentials = credentials ,
210+ credentials_file = client_options .credentials_file ,
205211 host = client_options .api_endpoint ,
212+ scopes = client_options .scopes ,
206213 api_mtls_endpoint = client_options .api_endpoint ,
207214 client_cert_source = client_options .client_cert_source ,
215+ quota_project_id = client_options .quota_project_id ,
208216 )
209217
210218 def list_voices (
@@ -229,9 +237,9 @@ def list_voices(
229237 only return voices that can be used to synthesize this
230238 language_code. E.g. when specifying "en-NZ", you will
231239 get supported "en-\*" voices; when specifying "no", you
232- will get supported "no-\*" (Norwegian) and "nb-*"
240+ will get supported "no-\*" (Norwegian) and "nb-\ *"
233241 (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
235243 get supported "yue-\*" voices.
236244 This corresponds to the ``language_code`` field
237245 on the ``request`` instance; if ``request`` is provided, this
@@ -252,28 +260,32 @@ def list_voices(
252260 # Create or coerce a protobuf request object.
253261 # Sanity check: If we got a request object, we should *not* have
254262 # 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 :
256265 raise ValueError (
257266 "If the `request` argument is set, then none of "
258267 "the individual field arguments should be set."
259268 )
260269
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 )
262276
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.
265279
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
268282
269283 # Wrap the RPC method; this adds retry and timeout information,
270284 # 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 ]
274286
275287 # Send the request.
276- response = rpc (request , retry = retry , timeout = timeout , metadata = metadata )
288+ response = rpc (request , retry = retry , timeout = timeout , metadata = metadata , )
277289
278290 # Done; return the response.
279291 return response
@@ -330,34 +342,36 @@ def synthesize_speech(
330342 # Create or coerce a protobuf request object.
331343 # Sanity check: If we got a request object, we should *not* have
332344 # 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 :
334347 raise ValueError (
335348 "If the `request` argument is set, then none of "
336349 "the individual field arguments should be set."
337350 )
338351
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 )
340358
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.
343361
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
350368
351369 # Wrap the RPC method; this adds retry and timeout information,
352370 # 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 ]
358372
359373 # Send the request.
360- response = rpc (request , retry = retry , timeout = timeout , metadata = metadata )
374+ response = rpc (request , retry = retry , timeout = timeout , metadata = metadata , )
361375
362376 # Done; return the response.
363377 return response
@@ -366,8 +380,8 @@ def synthesize_speech(
366380try :
367381 _client_info = gapic_v1 .client_info .ClientInfo (
368382 gapic_version = pkg_resources .get_distribution (
369- "google-cloud-texttospeech"
370- ).version
383+ "google-cloud-texttospeech" ,
384+ ).version ,
371385 )
372386except pkg_resources .DistributionNotFound :
373387 _client_info = gapic_v1 .client_info .ClientInfo ()
0 commit comments