google-cloud-text_to_speech-v1beta1 0.9.1 → 0.10.0

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,52 @@
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 "gapic/rest"
20
+ require "gapic/config"
21
+ require "gapic/config/method"
22
+
23
+ require "google/cloud/text_to_speech/v1beta1/version"
24
+
25
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech/credentials"
26
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech/paths"
27
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech/rest/client"
28
+
29
+ module Google
30
+ module Cloud
31
+ module TextToSpeech
32
+ module V1beta1
33
+ ##
34
+ # Service that implements Google Cloud Text-to-Speech API.
35
+ #
36
+ # To load this service and instantiate a REST client:
37
+ #
38
+ # require "google/cloud/text_to_speech/v1beta1/text_to_speech/rest"
39
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeech::Rest::Client.new
40
+ #
41
+ module TextToSpeech
42
+ # Client for the REST transport
43
+ module Rest
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ helper_path = ::File.join __dir__, "rest", "helpers.rb"
52
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech/rest/helpers" if ::File.file? helper_path
@@ -25,6 +25,7 @@ require "google/cloud/text_to_speech/v1beta1/version"
25
25
  require "google/cloud/text_to_speech/v1beta1/text_to_speech/credentials"
26
26
  require "google/cloud/text_to_speech/v1beta1/text_to_speech/paths"
27
27
  require "google/cloud/text_to_speech/v1beta1/text_to_speech/client"
28
+ require "google/cloud/text_to_speech/v1beta1/text_to_speech/rest"
28
29
 
29
30
  module Google
30
31
  module Cloud
@@ -33,11 +34,16 @@ module Google
33
34
  ##
34
35
  # Service that implements Google Cloud Text-to-Speech API.
35
36
  #
36
- # To load this service and instantiate a client:
37
+ # @example Load this service and instantiate a gRPC client
37
38
  #
38
39
  # require "google/cloud/text_to_speech/v1beta1/text_to_speech"
39
40
  # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeech::Client.new
40
41
  #
42
+ # @example Load this service and instantiate a REST client
43
+ #
44
+ # require "google/cloud/text_to_speech/v1beta1/text_to_speech/rest"
45
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeech::Rest::Client.new
46
+ #
41
47
  module TextToSpeech
42
48
  end
43
49
  end
@@ -211,14 +211,14 @@ module Google
211
211
  # # Call the synthesize_long_audio method.
212
212
  # result = client.synthesize_long_audio request
213
213
  #
214
- # # The returned object is of type Gapic::Operation. You can use this
215
- # # object to check the status of an operation, cancel it, or wait
216
- # # for results. Here is how to block until completion:
214
+ # # The returned object is of type Gapic::Operation. You can use it to
215
+ # # check the status of an operation, cancel it, or wait for results.
216
+ # # Here is how to wait for a response.
217
217
  # result.wait_until_done! timeout: 60
218
218
  # if result.response?
219
219
  # p result.response
220
220
  # else
221
- # puts "Error!"
221
+ # puts "No response received."
222
222
  # end
223
223
  #
224
224
  def synthesize_long_audio request, options = nil
@@ -158,13 +158,11 @@ module Google
158
158
  # # Call the list_operations method.
159
159
  # result = client.list_operations request
160
160
  #
161
- # # The returned object is of type Gapic::PagedEnumerable. You can
162
- # # iterate over all elements by calling #each, and the enumerable
163
- # # will lazily make API calls to fetch subsequent pages. Other
164
- # # methods are also available for managing paging directly.
165
- # result.each do |response|
161
+ # # The returned object is of type Gapic::PagedEnumerable. You can iterate
162
+ # # over elements, and API calls will be issued to fetch pages as needed.
163
+ # result.each do |item|
166
164
  # # Each element is of type ::Google::Longrunning::Operation.
167
- # p response
165
+ # p item
168
166
  # end
169
167
  #
170
168
  def list_operations request, options = nil
@@ -253,14 +251,14 @@ module Google
253
251
  # # Call the get_operation method.
254
252
  # result = client.get_operation request
255
253
  #
256
- # # The returned object is of type Gapic::Operation. You can use this
257
- # # object to check the status of an operation, cancel it, or wait
258
- # # for results. Here is how to block until completion:
254
+ # # The returned object is of type Gapic::Operation. You can use it to
255
+ # # check the status of an operation, cancel it, or wait for results.
256
+ # # Here is how to wait for a response.
259
257
  # result.wait_until_done! timeout: 60
260
258
  # if result.response?
261
259
  # p result.response
262
260
  # else
263
- # puts "Error!"
261
+ # puts "No response received."
264
262
  # end
265
263
  #
266
264
  def get_operation request, options = nil
@@ -540,14 +538,14 @@ module Google
540
538
  # # Call the wait_operation method.
541
539
  # result = client.wait_operation request
542
540
  #
543
- # # The returned object is of type Gapic::Operation. You can use this
544
- # # object to check the status of an operation, cancel it, or wait
545
- # # for results. Here is how to block until completion:
541
+ # # The returned object is of type Gapic::Operation. You can use it to
542
+ # # check the status of an operation, cancel it, or wait for results.
543
+ # # Here is how to wait for a response.
546
544
  # result.wait_until_done! timeout: 60
547
545
  # if result.response?
548
546
  # p result.response
549
547
  # else
550
- # puts "Error!"
548
+ # puts "No response received."
551
549
  # end
552
550
  #
553
551
  def wait_operation request, options = nil
@@ -0,0 +1,371 @@
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/*/voices/*`.
174
+ # @param input [::Google::Cloud::TextToSpeech::V1beta1::SynthesisInput, ::Hash]
175
+ # Required. The Synthesizer requires either plain text or SSML as input.
176
+ # @param audio_config [::Google::Cloud::TextToSpeech::V1beta1::AudioConfig, ::Hash]
177
+ # Required. The configuration of the synthesized audio.
178
+ # @param output_gcs_uri [::String]
179
+ # Specifies a Cloud Storage URI for the synthesis results. Must be
180
+ # specified in the format: `gs://bucket_name/object_name`, and the bucket
181
+ # must already exist.
182
+ # @param voice [::Google::Cloud::TextToSpeech::V1beta1::VoiceSelectionParams, ::Hash]
183
+ # The desired voice of the synthesized audio.
184
+ # @yield [result, operation] Access the result along with the TransportOperation object
185
+ # @yieldparam result [::Gapic::Operation]
186
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
187
+ #
188
+ # @return [::Gapic::Operation]
189
+ #
190
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
191
+ def synthesize_long_audio request, options = nil
192
+ raise ::ArgumentError, "request must be provided" if request.nil?
193
+
194
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::TextToSpeech::V1beta1::SynthesizeLongAudioRequest
195
+
196
+ # Converts hash and nil to an options object
197
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
198
+
199
+ # Customize the options with defaults
200
+ call_metadata = @config.rpcs.synthesize_long_audio.metadata.to_h
201
+
202
+ # Set x-goog-api-client and x-goog-user-project headers
203
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
204
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
205
+ gapic_version: ::Google::Cloud::TextToSpeech::V1beta1::VERSION,
206
+ transports_version_send: [:rest]
207
+
208
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
209
+
210
+ options.apply_defaults timeout: @config.rpcs.synthesize_long_audio.timeout,
211
+ metadata: call_metadata,
212
+ retry_policy: @config.rpcs.synthesize_long_audio.retry_policy
213
+
214
+ options.apply_defaults timeout: @config.timeout,
215
+ metadata: @config.metadata,
216
+ retry_policy: @config.retry_policy
217
+
218
+ @text_to_speech_long_audio_synthesize_stub.synthesize_long_audio request, options do |result, operation|
219
+ result = ::Gapic::Operation.new result, @operations_client, options: options
220
+ yield result, operation if block_given?
221
+ return result
222
+ end
223
+ rescue ::Gapic::Rest::Error => e
224
+ raise ::Google::Cloud::Error.from_error(e)
225
+ end
226
+
227
+ ##
228
+ # Configuration class for the TextToSpeechLongAudioSynthesize REST API.
229
+ #
230
+ # This class represents the configuration for TextToSpeechLongAudioSynthesize REST,
231
+ # providing control over timeouts, retry behavior, logging, transport
232
+ # parameters, and other low-level controls. Certain parameters can also be
233
+ # applied individually to specific RPCs. See
234
+ # {::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client::Configuration::Rpcs}
235
+ # for a list of RPCs that can be configured independently.
236
+ #
237
+ # Configuration can be applied globally to all clients, or to a single client
238
+ # on construction.
239
+ #
240
+ # @example
241
+ #
242
+ # # Modify the global config, setting the timeout for
243
+ # # synthesize_long_audio to 20 seconds,
244
+ # # and all remaining timeouts to 10 seconds.
245
+ # ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.configure do |config|
246
+ # config.timeout = 10.0
247
+ # config.rpcs.synthesize_long_audio.timeout = 20.0
248
+ # end
249
+ #
250
+ # # Apply the above configuration only to a new client.
251
+ # client = ::Google::Cloud::TextToSpeech::V1beta1::TextToSpeechLongAudioSynthesize::Rest::Client.new do |config|
252
+ # config.timeout = 10.0
253
+ # config.rpcs.synthesize_long_audio.timeout = 20.0
254
+ # end
255
+ #
256
+ # @!attribute [rw] endpoint
257
+ # The hostname or hostname:port of the service endpoint.
258
+ # Defaults to `"texttospeech.googleapis.com"`.
259
+ # @return [::String]
260
+ # @!attribute [rw] credentials
261
+ # Credentials to send with calls. You may provide any of the following types:
262
+ # * (`String`) The path to a service account key file in JSON format
263
+ # * (`Hash`) A service account key as a Hash
264
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
265
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
266
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
267
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
268
+ # * (`nil`) indicating no credentials
269
+ # @return [::Object]
270
+ # @!attribute [rw] scope
271
+ # The OAuth scopes
272
+ # @return [::Array<::String>]
273
+ # @!attribute [rw] lib_name
274
+ # The library name as recorded in instrumentation and logging
275
+ # @return [::String]
276
+ # @!attribute [rw] lib_version
277
+ # The library version as recorded in instrumentation and logging
278
+ # @return [::String]
279
+ # @!attribute [rw] timeout
280
+ # The call timeout in seconds.
281
+ # @return [::Numeric]
282
+ # @!attribute [rw] metadata
283
+ # Additional headers to be sent with the call.
284
+ # @return [::Hash{::Symbol=>::String}]
285
+ # @!attribute [rw] retry_policy
286
+ # The retry policy. The value is a hash with the following keys:
287
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
288
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
289
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
290
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
291
+ # trigger a retry.
292
+ # @return [::Hash]
293
+ # @!attribute [rw] quota_project
294
+ # A separate project against which to charge quota.
295
+ # @return [::String]
296
+ #
297
+ class Configuration
298
+ extend ::Gapic::Config
299
+
300
+ config_attr :endpoint, "texttospeech.googleapis.com", ::String
301
+ config_attr :credentials, nil do |value|
302
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
303
+ allowed.any? { |klass| klass === value }
304
+ end
305
+ config_attr :scope, nil, ::String, ::Array, nil
306
+ config_attr :lib_name, nil, ::String, nil
307
+ config_attr :lib_version, nil, ::String, nil
308
+ config_attr :timeout, nil, ::Numeric, nil
309
+ config_attr :metadata, nil, ::Hash, nil
310
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
311
+ config_attr :quota_project, nil, ::String, nil
312
+
313
+ # @private
314
+ def initialize parent_config = nil
315
+ @parent_config = parent_config unless parent_config.nil?
316
+
317
+ yield self if block_given?
318
+ end
319
+
320
+ ##
321
+ # Configurations for individual RPCs
322
+ # @return [Rpcs]
323
+ #
324
+ def rpcs
325
+ @rpcs ||= begin
326
+ parent_rpcs = nil
327
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
328
+ Rpcs.new parent_rpcs
329
+ end
330
+ end
331
+
332
+ ##
333
+ # Configuration RPC class for the TextToSpeechLongAudioSynthesize API.
334
+ #
335
+ # Includes fields providing the configuration for each RPC in this service.
336
+ # Each configuration object is of type `Gapic::Config::Method` and includes
337
+ # the following configuration fields:
338
+ #
339
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
340
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
341
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
342
+ # include the following keys:
343
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
344
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
345
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
346
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
347
+ # trigger a retry.
348
+ #
349
+ class Rpcs
350
+ ##
351
+ # RPC-specific configuration for `synthesize_long_audio`
352
+ # @return [::Gapic::Config::Method]
353
+ #
354
+ attr_reader :synthesize_long_audio
355
+
356
+ # @private
357
+ def initialize parent_rpcs = nil
358
+ synthesize_long_audio_config = parent_rpcs.synthesize_long_audio if parent_rpcs.respond_to? :synthesize_long_audio
359
+ @synthesize_long_audio = ::Gapic::Config::Method.new synthesize_long_audio_config
360
+
361
+ yield self if block_given?
362
+ end
363
+ end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+ end