google-cloud-text_to_speech-v1beta1 0.9.1 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,372 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/cloud/texttospeech/v1beta1/cloud_tts_lrs_pb"
21
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech_long_audio_synthesize/rest/service_stub"
22
+
23
+ module Google
24
+ module Cloud
25
+ module TextToSpeech
26
+ module V1beta1
27
+ module TextToSpeechLongAudioSynthesize
28
+ module Rest
29
+ ##
30
+ # REST client for the TextToSpeechLongAudioSynthesize service.
31
+ #
32
+ # Service that implements Google Cloud Text-to-Speech API.
33
+ #
34
+ class Client
35
+ include Paths
36
+
37
+ # @private
38
+ attr_reader :text_to_speech_long_audio_synthesize_stub
39
+
40
+ ##
41
+ # Configure the TextToSpeechLongAudioSynthesize Client class.
42
+ #
43
+ # See {::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client::Configuration}
44
+ # for a description of the configuration fields.
45
+ #
46
+ # @example
47
+ #
48
+ # # Modify the configuration for all TextToSpeechLongAudioSynthesize clients
49
+ # ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.configure do |config|
50
+ # config.timeout = 10.0
51
+ # end
52
+ #
53
+ # @yield [config] Configure the Client client.
54
+ # @yieldparam config [Client::Configuration]
55
+ #
56
+ # @return [Client::Configuration]
57
+ #
58
+ def self.configure
59
+ @configure ||= begin
60
+ namespace = ["Google", "Cloud", "TextToSpeech", "V1beta1"]
61
+ parent_config = while namespace.any?
62
+ parent_name = namespace.join "::"
63
+ parent_const = const_get parent_name
64
+ break parent_const.configure if parent_const.respond_to? :configure
65
+ namespace.pop
66
+ end
67
+ default_config = Client::Configuration.new parent_config
68
+
69
+ default_config.rpcs.synthesize_long_audio.timeout = 5000.0
70
+
71
+ default_config
72
+ end
73
+ yield @configure if block_given?
74
+ @configure
75
+ end
76
+
77
+ ##
78
+ # Configure the TextToSpeechLongAudioSynthesize Client instance.
79
+ #
80
+ # The configuration is set to the derived mode, meaning that values can be changed,
81
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
82
+ # should be made on {Client.configure}.
83
+ #
84
+ # See {::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client::Configuration}
85
+ # for a description of the configuration fields.
86
+ #
87
+ # @yield [config] Configure the Client client.
88
+ # @yieldparam config [Client::Configuration]
89
+ #
90
+ # @return [Client::Configuration]
91
+ #
92
+ def configure
93
+ yield @config if block_given?
94
+ @config
95
+ end
96
+
97
+ ##
98
+ # Create a new TextToSpeechLongAudioSynthesize REST client object.
99
+ #
100
+ # @example
101
+ #
102
+ # # Create a client using the default configuration
103
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.new
104
+ #
105
+ # # Create a client using a custom configuration
106
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.new do |config|
107
+ # config.timeout = 10.0
108
+ # end
109
+ #
110
+ # @yield [config] Configure the TextToSpeechLongAudioSynthesize client.
111
+ # @yieldparam config [Client::Configuration]
112
+ #
113
+ def initialize
114
+ # Create the configuration object
115
+ @config = Configuration.new Client.configure
116
+
117
+ # Yield the configuration if needed
118
+ yield @config if block_given?
119
+
120
+ # Create credentials
121
+ credentials = @config.credentials
122
+ # Use self-signed JWT if the endpoint is unchanged from default,
123
+ # but only if the default endpoint does not have a region prefix.
124
+ enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
125
+ !@config.endpoint.split(".").first.include?("-")
126
+ credentials ||= Credentials.default scope: @config.scope,
127
+ enable_self_signed_jwt: enable_self_signed_jwt
128
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
129
+ credentials = Credentials.new credentials, scope: @config.scope
130
+ end
131
+
132
+ @quota_project_id = @config.quota_project
133
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
134
+
135
+ @operations_client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Operations.new do |config|
136
+ config.credentials = credentials
137
+ config.quota_project = @quota_project_id
138
+ config.endpoint = @config.endpoint
139
+ end
140
+
141
+ @text_to_speech_long_audio_synthesize_stub = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials
142
+ end
143
+
144
+ ##
145
+ # Get the associated client for long-running operations.
146
+ #
147
+ # @return [::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Operations]
148
+ #
149
+ attr_reader :operations_client
150
+
151
+ # Service calls
152
+
153
+ ##
154
+ # Synthesizes long form text asynchronously.
155
+ #
156
+ # @overload synthesize_long_audio(request, options = nil)
157
+ # Pass arguments to `synthesize_long_audio` via a request object, either of type
158
+ # {::Google::Cloud::TextToSpeech::V1beta1::SynthesizeLongAudioRequest} or an equivalent Hash.
159
+ #
160
+ # @param request [::Google::Cloud::TextToSpeech::V1beta1::SynthesizeLongAudioRequest, ::Hash]
161
+ # A request object representing the call parameters. Required. To specify no
162
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
163
+ # @param options [::Gapic::CallOptions, ::Hash]
164
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
165
+ #
166
+ # @overload synthesize_long_audio(parent: nil, input: nil, audio_config: nil, output_gcs_uri: nil, voice: nil)
167
+ # Pass arguments to `synthesize_long_audio` via keyword arguments. Note that at
168
+ # least one keyword argument is required. To specify no parameters, or to keep all
169
+ # the default parameter values, pass an empty Hash as a request object (see above).
170
+ #
171
+ # @param parent [::String]
172
+ # The resource states of the request in the form of
173
+ # `projects/*/locations/*`.
174
+ # @param input [::Google::Cloud::TextToSpeech::V1beta1::SynthesisInput, ::Hash]
175
+ # Required. The Synthesizer requires either plain text or SSML as input.
176
+ # While Long Audio is in preview, SSML is temporarily unsupported.
177
+ # @param audio_config [::Google::Cloud::TextToSpeech::V1beta1::AudioConfig, ::Hash]
178
+ # Required. The configuration of the synthesized audio.
179
+ # @param output_gcs_uri [::String]
180
+ # Required. Specifies a Cloud Storage URI for the synthesis results. Must be
181
+ # specified in the format: `gs://bucket_name/object_name`, and the bucket
182
+ # must already exist.
183
+ # @param voice [::Google::Cloud::TextToSpeech::V1beta1::VoiceSelectionParams, ::Hash]
184
+ # Required. The desired voice of the synthesized audio.
185
+ # @yield [result, operation] Access the result along with the TransportOperation object
186
+ # @yieldparam result [::Gapic::Operation]
187
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
188
+ #
189
+ # @return [::Gapic::Operation]
190
+ #
191
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
192
+ def synthesize_long_audio request, options = nil
193
+ raise ::ArgumentError, "request must be provided" if request.nil?
194
+
195
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::TextToSpeech::V1beta1::SynthesizeLongAudioRequest
196
+
197
+ # Converts hash and nil to an options object
198
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
199
+
200
+ # Customize the options with defaults
201
+ call_metadata = @config.rpcs.synthesize_long_audio.metadata.to_h
202
+
203
+ # Set x-goog-api-client and x-goog-user-project headers
204
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
205
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
206
+ gapic_version: ::Google::Cloud::TextToSpeech::V1beta1::VERSION,
207
+ transports_version_send: [:rest]
208
+
209
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
210
+
211
+ options.apply_defaults timeout: @config.rpcs.synthesize_long_audio.timeout,
212
+ metadata: call_metadata,
213
+ retry_policy: @config.rpcs.synthesize_long_audio.retry_policy
214
+
215
+ options.apply_defaults timeout: @config.timeout,
216
+ metadata: @config.metadata,
217
+ retry_policy: @config.retry_policy
218
+
219
+ @text_to_speech_long_audio_synthesize_stub.synthesize_long_audio request, options do |result, operation|
220
+ result = ::Gapic::Operation.new result, @operations_client, options: options
221
+ yield result, operation if block_given?
222
+ return result
223
+ end
224
+ rescue ::Gapic::Rest::Error => e
225
+ raise ::Google::Cloud::Error.from_error(e)
226
+ end
227
+
228
+ ##
229
+ # Configuration class for the TextToSpeechLongAudioSynthesize REST API.
230
+ #
231
+ # This class represents the configuration for TextToSpeechLongAudioSynthesize REST,
232
+ # providing control over timeouts, retry behavior, logging, transport
233
+ # parameters, and other low-level controls. Certain parameters can also be
234
+ # applied individually to specific RPCs. See
235
+ # {::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client::Configuration::Rpcs}
236
+ # for a list of RPCs that can be configured independently.
237
+ #
238
+ # Configuration can be applied globally to all clients, or to a single client
239
+ # on construction.
240
+ #
241
+ # @example
242
+ #
243
+ # # Modify the global config, setting the timeout for
244
+ # # synthesize_long_audio to 20 seconds,
245
+ # # and all remaining timeouts to 10 seconds.
246
+ # ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.configure do |config|
247
+ # config.timeout = 10.0
248
+ # config.rpcs.synthesize_long_audio.timeout = 20.0
249
+ # end
250
+ #
251
+ # # Apply the above configuration only to a new client.
252
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.new do |config|
253
+ # config.timeout = 10.0
254
+ # config.rpcs.synthesize_long_audio.timeout = 20.0
255
+ # end
256
+ #
257
+ # @!attribute [rw] endpoint
258
+ # The hostname or hostname:port of the service endpoint.
259
+ # Defaults to `"texttospeech.googleapis.com"`.
260
+ # @return [::String]
261
+ # @!attribute [rw] credentials
262
+ # Credentials to send with calls. You may provide any of the following types:
263
+ # * (`String`) The path to a service account key file in JSON format
264
+ # * (`Hash`) A service account key as a Hash
265
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
266
+ # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials))
267
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
268
+ # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
269
+ # * (`nil`) indicating no credentials
270
+ # @return [::Object]
271
+ # @!attribute [rw] scope
272
+ # The OAuth scopes
273
+ # @return [::Array<::String>]
274
+ # @!attribute [rw] lib_name
275
+ # The library name as recorded in instrumentation and logging
276
+ # @return [::String]
277
+ # @!attribute [rw] lib_version
278
+ # The library version as recorded in instrumentation and logging
279
+ # @return [::String]
280
+ # @!attribute [rw] timeout
281
+ # The call timeout in seconds.
282
+ # @return [::Numeric]
283
+ # @!attribute [rw] metadata
284
+ # Additional headers to be sent with the call.
285
+ # @return [::Hash{::Symbol=>::String}]
286
+ # @!attribute [rw] retry_policy
287
+ # The retry policy. The value is a hash with the following keys:
288
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
289
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
290
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
291
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
292
+ # trigger a retry.
293
+ # @return [::Hash]
294
+ # @!attribute [rw] quota_project
295
+ # A separate project against which to charge quota.
296
+ # @return [::String]
297
+ #
298
+ class Configuration
299
+ extend ::Gapic::Config
300
+
301
+ config_attr :endpoint, "texttospeech.googleapis.com", ::String
302
+ config_attr :credentials, nil do |value|
303
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
304
+ allowed.any? { |klass| klass === value }
305
+ end
306
+ config_attr :scope, nil, ::String, ::Array, nil
307
+ config_attr :lib_name, nil, ::String, nil
308
+ config_attr :lib_version, nil, ::String, nil
309
+ config_attr :timeout, nil, ::Numeric, nil
310
+ config_attr :metadata, nil, ::Hash, nil
311
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
312
+ config_attr :quota_project, nil, ::String, nil
313
+
314
+ # @private
315
+ def initialize parent_config = nil
316
+ @parent_config = parent_config unless parent_config.nil?
317
+
318
+ yield self if block_given?
319
+ end
320
+
321
+ ##
322
+ # Configurations for individual RPCs
323
+ # @return [Rpcs]
324
+ #
325
+ def rpcs
326
+ @rpcs ||= begin
327
+ parent_rpcs = nil
328
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
329
+ Rpcs.new parent_rpcs
330
+ end
331
+ end
332
+
333
+ ##
334
+ # Configuration RPC class for the TextToSpeechLongAudioSynthesize API.
335
+ #
336
+ # Includes fields providing the configuration for each RPC in this service.
337
+ # Each configuration object is of type `Gapic::Config::Method` and includes
338
+ # the following configuration fields:
339
+ #
340
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
341
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
342
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
343
+ # include the following keys:
344
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
345
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
346
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
347
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
348
+ # trigger a retry.
349
+ #
350
+ class Rpcs
351
+ ##
352
+ # RPC-specific configuration for `synthesize_long_audio`
353
+ # @return [::Gapic::Config::Method]
354
+ #
355
+ attr_reader :synthesize_long_audio
356
+
357
+ # @private
358
+ def initialize parent_rpcs = nil
359
+ synthesize_long_audio_config = parent_rpcs.synthesize_long_audio if parent_rpcs.respond_to? :synthesize_long_audio
360
+ @synthesize_long_audio = ::Gapic::Config::Method.new synthesize_long_audio_config
361
+
362
+ yield self if block_given?
363
+ end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end