google-cloud-text_to_speech 0.7.0 → 1.0.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.
@@ -1,279 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/texttospeech/v1/cloud_tts.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/cloud/texttospeech/v1/cloud_tts_pb"
29
- require "google/cloud/text_to_speech/v1/credentials"
30
- require "google/cloud/text_to_speech/version"
31
-
32
- module Google
33
- module Cloud
34
- module TextToSpeech
35
- module V1
36
- # Service that implements Google Cloud Text-to-Speech API.
37
- #
38
- # @!attribute [r] text_to_speech_stub
39
- # @return [Google::Cloud::TextToSpeech::V1::TextToSpeech::Stub]
40
- class TextToSpeechClient
41
- # @private
42
- attr_reader :text_to_speech_stub
43
-
44
- # The default address of the service.
45
- SERVICE_ADDRESS = "texttospeech.googleapis.com".freeze
46
-
47
- # The default port of the service.
48
- DEFAULT_SERVICE_PORT = 443
49
-
50
- # The default set of gRPC interceptors.
51
- GRPC_INTERCEPTORS = []
52
-
53
- DEFAULT_TIMEOUT = 30
54
-
55
- # The scopes needed to make gRPC calls to all of the methods defined in
56
- # this service.
57
- ALL_SCOPES = [
58
- "https://www.googleapis.com/auth/cloud-platform"
59
- ].freeze
60
-
61
-
62
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
63
- # Provides the means for authenticating requests made by the client. This parameter can
64
- # be many types.
65
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
66
- # authenticating requests made by this client.
67
- # A `String` will be treated as the path to the keyfile to be used for the construction of
68
- # credentials for this client.
69
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
70
- # credentials for this client.
71
- # A `GRPC::Core::Channel` will be used to make calls through.
72
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
73
- # should already be composed with a `GRPC::Core::CallCredentials` object.
74
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
75
- # metadata for requests, generally, to give OAuth credentials.
76
- # @param scopes [Array<String>]
77
- # The OAuth scopes for this service. This parameter is ignored if
78
- # an updater_proc is supplied.
79
- # @param client_config [Hash]
80
- # A Hash for call options for each method. See
81
- # Google::Gax#construct_settings for the structure of
82
- # this data. Falls back to the default config if not specified
83
- # or the specified config is missing data points.
84
- # @param timeout [Numeric]
85
- # The default timeout, in seconds, for calls made through this client.
86
- # @param metadata [Hash]
87
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
88
- # @param service_address [String]
89
- # Override for the service hostname, or `nil` to leave as the default.
90
- # @param service_port [Integer]
91
- # Override for the service port, or `nil` to leave as the default.
92
- # @param exception_transformer [Proc]
93
- # An optional proc that intercepts any exceptions raised during an API call to inject
94
- # custom error handling.
95
- def initialize \
96
- credentials: nil,
97
- scopes: ALL_SCOPES,
98
- client_config: {},
99
- timeout: DEFAULT_TIMEOUT,
100
- metadata: nil,
101
- service_address: nil,
102
- service_port: nil,
103
- exception_transformer: nil,
104
- lib_name: nil,
105
- lib_version: ""
106
- # These require statements are intentionally placed here to initialize
107
- # the gRPC module only when it's required.
108
- # See https://github.com/googleapis/toolkit/issues/446
109
- require "google/gax/grpc"
110
- require "google/cloud/texttospeech/v1/cloud_tts_services_pb"
111
-
112
- credentials ||= Google::Cloud::TextToSpeech::V1::Credentials.default
113
-
114
- if credentials.is_a?(String) || credentials.is_a?(Hash)
115
- updater_proc = Google::Cloud::TextToSpeech::V1::Credentials.new(credentials).updater_proc
116
- end
117
- if credentials.is_a?(GRPC::Core::Channel)
118
- channel = credentials
119
- end
120
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
121
- chan_creds = credentials
122
- end
123
- if credentials.is_a?(Proc)
124
- updater_proc = credentials
125
- end
126
- if credentials.is_a?(Google::Auth::Credentials)
127
- updater_proc = credentials.updater_proc
128
- end
129
-
130
- package_version = Google::Cloud::TextToSpeech::VERSION
131
-
132
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
133
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
134
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
135
- google_api_client << " grpc/#{GRPC::VERSION}"
136
- google_api_client.freeze
137
-
138
- headers = { :"x-goog-api-client" => google_api_client }
139
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
140
- headers[:"x-goog-user-project"] = credentials.quota_project_id
141
- end
142
- headers.merge!(metadata) unless metadata.nil?
143
- client_config_file = Pathname.new(__dir__).join(
144
- "text_to_speech_client_config.json"
145
- )
146
- defaults = client_config_file.open do |f|
147
- Google::Gax.construct_settings(
148
- "google.cloud.texttospeech.v1.TextToSpeech",
149
- JSON.parse(f.read),
150
- client_config,
151
- Google::Gax::Grpc::STATUS_CODE_NAMES,
152
- timeout,
153
- errors: Google::Gax::Grpc::API_ERRORS,
154
- metadata: headers
155
- )
156
- end
157
-
158
- # Allow overriding the service path/port in subclasses.
159
- service_path = service_address || self.class::SERVICE_ADDRESS
160
- port = service_port || self.class::DEFAULT_SERVICE_PORT
161
- interceptors = self.class::GRPC_INTERCEPTORS
162
- @text_to_speech_stub = Google::Gax::Grpc.create_stub(
163
- service_path,
164
- port,
165
- chan_creds: chan_creds,
166
- channel: channel,
167
- updater_proc: updater_proc,
168
- scopes: scopes,
169
- interceptors: interceptors,
170
- &Google::Cloud::TextToSpeech::V1::TextToSpeech::Stub.method(:new)
171
- )
172
-
173
- @list_voices = Google::Gax.create_api_call(
174
- @text_to_speech_stub.method(:list_voices),
175
- defaults["list_voices"],
176
- exception_transformer: exception_transformer
177
- )
178
- @synthesize_speech = Google::Gax.create_api_call(
179
- @text_to_speech_stub.method(:synthesize_speech),
180
- defaults["synthesize_speech"],
181
- exception_transformer: exception_transformer
182
- )
183
- end
184
-
185
- # Service calls
186
-
187
- # Returns a list of Voice supported for synthesis.
188
- #
189
- # @param language_code [String]
190
- # Optional. Recommended.
191
- # [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. If
192
- # specified, the ListVoices call will only return voices that can be used to
193
- # synthesize this language_code. E.g. when specifying "en-NZ", you will get
194
- # supported "en-*" voices; when specifying "no", you will get supported
195
- # "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) voices; specifying "zh"
196
- # will also get supported "cmn-*" voices; specifying "zh-hk" will also get
197
- # supported "yue-*" voices.
198
- # @param options [Google::Gax::CallOptions]
199
- # Overrides the default settings for this call, e.g, timeout,
200
- # retries, etc.
201
- # @yield [result, operation] Access the result along with the RPC operation
202
- # @yieldparam result [Google::Cloud::TextToSpeech::V1::ListVoicesResponse]
203
- # @yieldparam operation [GRPC::ActiveCall::Operation]
204
- # @return [Google::Cloud::TextToSpeech::V1::ListVoicesResponse]
205
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
206
- # @example
207
- # require "google/cloud/text_to_speech"
208
- #
209
- # text_to_speech_client = Google::Cloud::TextToSpeech.new(version: :v1)
210
- # response = text_to_speech_client.list_voices
211
-
212
- def list_voices \
213
- language_code: nil,
214
- options: nil,
215
- &block
216
- req = {
217
- language_code: language_code
218
- }.delete_if { |_, v| v.nil? }
219
- req = Google::Gax::to_proto(req, Google::Cloud::TextToSpeech::V1::ListVoicesRequest)
220
- @list_voices.call(req, options, &block)
221
- end
222
-
223
- # Synthesizes speech synchronously: receive results after all text input
224
- # has been processed.
225
- #
226
- # @param input [Google::Cloud::TextToSpeech::V1::SynthesisInput | Hash]
227
- # Required. The Synthesizer requires either plain text or SSML as input.
228
- # A hash of the same form as `Google::Cloud::TextToSpeech::V1::SynthesisInput`
229
- # can also be provided.
230
- # @param voice [Google::Cloud::TextToSpeech::V1::VoiceSelectionParams | Hash]
231
- # Required. The desired voice of the synthesized audio.
232
- # A hash of the same form as `Google::Cloud::TextToSpeech::V1::VoiceSelectionParams`
233
- # can also be provided.
234
- # @param audio_config [Google::Cloud::TextToSpeech::V1::AudioConfig | Hash]
235
- # Required. The configuration of the synthesized audio.
236
- # A hash of the same form as `Google::Cloud::TextToSpeech::V1::AudioConfig`
237
- # can also be provided.
238
- # @param options [Google::Gax::CallOptions]
239
- # Overrides the default settings for this call, e.g, timeout,
240
- # retries, etc.
241
- # @yield [result, operation] Access the result along with the RPC operation
242
- # @yieldparam result [Google::Cloud::TextToSpeech::V1::SynthesizeSpeechResponse]
243
- # @yieldparam operation [GRPC::ActiveCall::Operation]
244
- # @return [Google::Cloud::TextToSpeech::V1::SynthesizeSpeechResponse]
245
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
246
- # @example
247
- # require "google/cloud/text_to_speech"
248
- #
249
- # text_to_speech_client = Google::Cloud::TextToSpeech.new(version: :v1)
250
- #
251
- # # TODO: Initialize `input`:
252
- # input = {}
253
- #
254
- # # TODO: Initialize `voice`:
255
- # voice = {}
256
- #
257
- # # TODO: Initialize `audio_config`:
258
- # audio_config = {}
259
- # response = text_to_speech_client.synthesize_speech(input, voice, audio_config)
260
-
261
- def synthesize_speech \
262
- input,
263
- voice,
264
- audio_config,
265
- options: nil,
266
- &block
267
- req = {
268
- input: input,
269
- voice: voice,
270
- audio_config: audio_config
271
- }.delete_if { |_, v| v.nil? }
272
- req = Google::Gax::to_proto(req, Google::Cloud::TextToSpeech::V1::SynthesizeSpeechRequest)
273
- @synthesize_speech.call(req, options, &block)
274
- end
275
- end
276
- end
277
- end
278
- end
279
- end
@@ -1,36 +0,0 @@
1
- {
2
- "interfaces": {
3
- "google.cloud.texttospeech.v1.TextToSpeech": {
4
- "retry_codes": {
5
- "idempotent": [
6
- "DEADLINE_EXCEEDED",
7
- "UNAVAILABLE"
8
- ],
9
- "non_idempotent": []
10
- },
11
- "retry_params": {
12
- "default": {
13
- "initial_retry_delay_millis": 100,
14
- "retry_delay_multiplier": 1.3,
15
- "max_retry_delay_millis": 60000,
16
- "initial_rpc_timeout_millis": 20000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 20000,
19
- "total_timeout_millis": 600000
20
- }
21
- },
22
- "methods": {
23
- "ListVoices": {
24
- "timeout_millis": 60000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "SynthesizeSpeech": {
29
- "timeout_millis": 60000,
30
- "retry_codes_name": "non_idempotent",
31
- "retry_params_name": "default"
32
- }
33
- }
34
- }
35
- }
36
- }
@@ -1,146 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/text_to_speech/v1beta1/text_to_speech_client"
17
-
18
- module Google
19
- module Cloud
20
- module TextToSpeech
21
- # rubocop:disable LineLength
22
-
23
- ##
24
- # # Ruby Client for Cloud Text-to-Speech API
25
- #
26
- # [Cloud Text-to-Speech API][Product Documentation]:
27
- # Synthesizes natural-sounding speech by applying powerful neural network
28
- # models.
29
- # - [Product Documentation][]
30
- #
31
- # ## Quick Start
32
- # In order to use this library, you first need to go through the following
33
- # steps:
34
- #
35
- # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
36
- # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
37
- # 3. [Enable the Cloud Text-to-Speech API.](https://console.cloud.google.com/apis/library/texttospeech.googleapis.com)
38
- # 4. [Setup Authentication.](https://googleapis.dev/ruby/google-cloud-text_to_speech/latest/file.AUTHENTICATION.html)
39
- #
40
- # ### Installation
41
- # ```
42
- # $ gem install google-cloud-text_to_speech
43
- # ```
44
- #
45
- # ### Next Steps
46
- # - Read the [Cloud Text-to-Speech API Product documentation][Product Documentation]
47
- # to learn more about the product and see How-to Guides.
48
- # - View this [repository's main README](https://github.com/googleapis/google-cloud-ruby/blob/master/README.md)
49
- # to see the full list of Cloud APIs that we cover.
50
- #
51
- # [Product Documentation]: https://cloud.google.com/texttospeech
52
- #
53
- # ## Enabling Logging
54
- #
55
- # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
56
- # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
57
- # or a [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
58
- # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
59
- # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
60
- #
61
- # Configuring a Ruby stdlib logger:
62
- #
63
- # ```ruby
64
- # require "logger"
65
- #
66
- # module MyLogger
67
- # LOGGER = Logger.new $stderr, level: Logger::WARN
68
- # def logger
69
- # LOGGER
70
- # end
71
- # end
72
- #
73
- # # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
74
- # module GRPC
75
- # extend MyLogger
76
- # end
77
- # ```
78
- #
79
- module V1beta1
80
- # rubocop:enable LineLength
81
-
82
- ##
83
- # Service that implements Google Cloud Text-to-Speech API.
84
- #
85
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
86
- # Provides the means for authenticating requests made by the client. This parameter can
87
- # be many types.
88
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
89
- # authenticating requests made by this client.
90
- # A `String` will be treated as the path to the keyfile to be used for the construction of
91
- # credentials for this client.
92
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
93
- # credentials for this client.
94
- # A `GRPC::Core::Channel` will be used to make calls through.
95
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
96
- # should already be composed with a `GRPC::Core::CallCredentials` object.
97
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
98
- # metadata for requests, generally, to give OAuth credentials.
99
- # @param scopes [Array<String>]
100
- # The OAuth scopes for this service. This parameter is ignored if
101
- # an updater_proc is supplied.
102
- # @param client_config [Hash]
103
- # A Hash for call options for each method. See
104
- # Google::Gax#construct_settings for the structure of
105
- # this data. Falls back to the default config if not specified
106
- # or the specified config is missing data points.
107
- # @param timeout [Numeric]
108
- # The default timeout, in seconds, for calls made through this client.
109
- # @param metadata [Hash]
110
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
111
- # @param service_address [String]
112
- # Override for the service hostname, or `nil` to leave as the default.
113
- # @param service_port [Integer]
114
- # Override for the service port, or `nil` to leave as the default.
115
- # @param exception_transformer [Proc]
116
- # An optional proc that intercepts any exceptions raised during an API call to inject
117
- # custom error handling.
118
- def self.new \
119
- credentials: nil,
120
- scopes: nil,
121
- client_config: nil,
122
- timeout: nil,
123
- metadata: nil,
124
- service_address: nil,
125
- service_port: nil,
126
- exception_transformer: nil,
127
- lib_name: nil,
128
- lib_version: nil
129
- kwargs = {
130
- credentials: credentials,
131
- scopes: scopes,
132
- client_config: client_config,
133
- timeout: timeout,
134
- metadata: metadata,
135
- exception_transformer: exception_transformer,
136
- lib_name: lib_name,
137
- service_address: service_address,
138
- service_port: service_port,
139
- lib_version: lib_version
140
- }.select { |_, v| v != nil }
141
- Google::Cloud::TextToSpeech::V1beta1::TextToSpeechClient.new(**kwargs)
142
- end
143
- end
144
- end
145
- end
146
- end